diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 83620574c6..514a949753 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -3014,6 +3014,7 @@ phutil_register_library_map(array( 'PhameBlogLiveController' => 'applications/phame/controller/blog/PhameBlogLiveController.php', 'PhameBlogQuery' => 'applications/phame/query/PhameBlogQuery.php', 'PhameBlogResourceSite' => 'applications/phame/site/PhameBlogResourceSite.php', + 'PhameBlogSearchEngine' => 'applications/phame/query/PhameBlogSearchEngine.php', 'PhameBlogSite' => 'applications/phame/site/PhameBlogSite.php', 'PhameBlogSkin' => 'applications/phame/skins/PhameBlogSkin.php', 'PhameBlogTransaction' => 'applications/phame/storage/PhameBlogTransaction.php', @@ -6979,6 +6980,7 @@ phutil_register_library_map(array( 'PhameBlogLiveController' => 'PhameController', 'PhameBlogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhameBlogResourceSite' => 'PhameSite', + 'PhameBlogSearchEngine' => 'PhabricatorApplicationSearchEngine', 'PhameBlogSite' => 'PhameSite', 'PhameBlogSkin' => 'PhabricatorController', 'PhameBlogTransaction' => 'PhabricatorApplicationTransaction', diff --git a/src/applications/phame/query/PhameBlogQuery.php b/src/applications/phame/query/PhameBlogQuery.php index a3e88e5143..ef441636b3 100644 --- a/src/applications/phame/query/PhameBlogQuery.php +++ b/src/applications/phame/query/PhameBlogQuery.php @@ -22,54 +22,39 @@ final class PhameBlogQuery extends PhabricatorCursorPagedPolicyAwareQuery { return $this; } - protected function loadPage() { - $table = new PhameBlog(); - $conn_r = $table->establishConnection('r'); - - $where_clause = $this->buildWhereClause($conn_r); - $order_clause = $this->buildOrderClause($conn_r); - $limit_clause = $this->buildLimitClause($conn_r); - - $data = queryfx_all( - $conn_r, - 'SELECT * FROM %T b %Q %Q %Q', - $table->getTableName(), - $where_clause, - $order_clause, - $limit_clause); - - $blogs = $table->loadAllFromArray($data); - - return $blogs; + public function newResultObject() { + return new PhameBlog(); } - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { - $where = array(); + protected function loadPage() { + return $this->loadStandardPage($this->newResultObject()); + } - if ($this->ids) { + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { + $where = parent::buildWhereClauseParts($conn); + + if ($this->ids !== null) { $where[] = qsprintf( - $conn_r, + $conn, 'id IN (%Ls)', $this->ids); } - if ($this->phids) { + if ($this->phids !== null) { $where[] = qsprintf( - $conn_r, + $conn, 'phid IN (%Ls)', $this->phids); } - if ($this->domain) { + if ($this->domain !== null) { $where[] = qsprintf( - $conn_r, + $conn, 'domain = %s', $this->domain); } - $where[] = $this->buildPagingClause($conn_r); - - return $this->formatWhereClause($where); + return $where; } public function getQueryApplicationClass() { diff --git a/src/applications/phame/query/PhameBlogSearchEngine.php b/src/applications/phame/query/PhameBlogSearchEngine.php new file mode 100644 index 0000000000..18871ebefe --- /dev/null +++ b/src/applications/phame/query/PhameBlogSearchEngine.php @@ -0,0 +1,80 @@ +newQuery(); + return $query; + } + + protected function buildCustomSearchFields() { + return array(); + } + + protected function getURI($path) { + return '/phame/blog/'.$path; + } + + protected function getBuiltinQueryNames() { + $names = array( + 'all' => pht('All'), + ); + return $names; + } + + public function buildSavedQueryFromBuiltin($query_key) { + $query = $this->newSavedQuery(); + $query->setQueryKey($query_key); + + switch ($query_key) { + case 'all': + return $query; + } + + return parent::buildSavedQueryFromBuiltin($query_key); + } + protected function renderResultList( + array $blogs, + PhabricatorSavedQuery $query, + array $handles) { + + assert_instances_of($blogs, 'PhameBlog'); + $viewer = $this->requireViewer(); + + $list = new PHUIObjectItemListView(); + $list->setUser($viewer); + + foreach ($blogs as $blog) { + $id = $blog->getID(); + $item = id(new PHUIObjectItemView()) + ->setUser($viewer) + ->setObject($blog) + ->setHeader($blog->getName()) + ->setStatusIcon('fa-star') + ->setHref($this->getApplicationURI("/blog/view/{$id}/")) + ->addAttribute($blog->getSkin()) + ->addAttribute($blog->getDomain()); + $list->addItem($item); + } + + $result = new PhabricatorApplicationSearchResultView(); + $result->setObjectList($list); + $result->setNoDataString(pht('No blogs found.')); + + return $result; + } + +}