Page MenuHomePhabricator

D13670.diff
No OneTemporary

D13670.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -3014,6 +3014,7 @@
'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 @@
'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
--- a/src/applications/phame/query/PhameBlogQuery.php
+++ b/src/applications/phame/query/PhameBlogQuery.php
@@ -22,54 +22,39 @@
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);
+ public function newResultObject() {
+ return new PhameBlog();
+ }
- return $blogs;
+ protected function loadPage() {
+ return $this->loadStandardPage($this->newResultObject());
}
- protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
- $where = array();
+ protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
+ $where = parent::buildWhereClauseParts($conn);
- if ($this->ids) {
+ 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
--- /dev/null
+++ b/src/applications/phame/query/PhameBlogSearchEngine.php
@@ -0,0 +1,80 @@
+<?php
+
+final class PhameBlogSearchEngine
+ extends PhabricatorApplicationSearchEngine {
+
+ public function getResultTypeDescription() {
+ return pht('Phame Blogs');
+ }
+
+ public function getApplicationClassName() {
+ return 'PhabricatorPhameApplication';
+ }
+
+ public function newQuery() {
+ return new PhameBlogQuery();
+ }
+
+ protected function buildQueryFromParameters(array $map) {
+ $query = $this->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;
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 9, 1:06 PM (1 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6763113
Default Alt Text
D13670.diff (5 KB)

Event Timeline