mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-25 23:10:57 +01:00
PhameBlogSearchEngine
Summary: Modernize PhameBlogQuery, create a skeleton Search Engine. Test Plan: Built a dashboard for testing, verify view pages still work. Reviewers: btrahan, epriestley Reviewed By: epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T6269 Differential Revision: https://secure.phabricator.com/D13670
This commit is contained in:
parent
44d5dff832
commit
22740f1752
3 changed files with 97 additions and 30 deletions
|
@ -3014,6 +3014,7 @@ phutil_register_library_map(array(
|
||||||
'PhameBlogLiveController' => 'applications/phame/controller/blog/PhameBlogLiveController.php',
|
'PhameBlogLiveController' => 'applications/phame/controller/blog/PhameBlogLiveController.php',
|
||||||
'PhameBlogQuery' => 'applications/phame/query/PhameBlogQuery.php',
|
'PhameBlogQuery' => 'applications/phame/query/PhameBlogQuery.php',
|
||||||
'PhameBlogResourceSite' => 'applications/phame/site/PhameBlogResourceSite.php',
|
'PhameBlogResourceSite' => 'applications/phame/site/PhameBlogResourceSite.php',
|
||||||
|
'PhameBlogSearchEngine' => 'applications/phame/query/PhameBlogSearchEngine.php',
|
||||||
'PhameBlogSite' => 'applications/phame/site/PhameBlogSite.php',
|
'PhameBlogSite' => 'applications/phame/site/PhameBlogSite.php',
|
||||||
'PhameBlogSkin' => 'applications/phame/skins/PhameBlogSkin.php',
|
'PhameBlogSkin' => 'applications/phame/skins/PhameBlogSkin.php',
|
||||||
'PhameBlogTransaction' => 'applications/phame/storage/PhameBlogTransaction.php',
|
'PhameBlogTransaction' => 'applications/phame/storage/PhameBlogTransaction.php',
|
||||||
|
@ -6979,6 +6980,7 @@ phutil_register_library_map(array(
|
||||||
'PhameBlogLiveController' => 'PhameController',
|
'PhameBlogLiveController' => 'PhameController',
|
||||||
'PhameBlogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'PhameBlogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
'PhameBlogResourceSite' => 'PhameSite',
|
'PhameBlogResourceSite' => 'PhameSite',
|
||||||
|
'PhameBlogSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
'PhameBlogSite' => 'PhameSite',
|
'PhameBlogSite' => 'PhameSite',
|
||||||
'PhameBlogSkin' => 'PhabricatorController',
|
'PhameBlogSkin' => 'PhabricatorController',
|
||||||
'PhameBlogTransaction' => 'PhabricatorApplicationTransaction',
|
'PhameBlogTransaction' => 'PhabricatorApplicationTransaction',
|
||||||
|
|
|
@ -22,54 +22,39 @@ final class PhameBlogQuery extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function loadPage() {
|
public function newResultObject() {
|
||||||
$table = new PhameBlog();
|
return 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
protected function loadPage() {
|
||||||
$where = array();
|
return $this->loadStandardPage($this->newResultObject());
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->ids) {
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
||||||
|
$where = parent::buildWhereClauseParts($conn);
|
||||||
|
|
||||||
|
if ($this->ids !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'id IN (%Ls)',
|
'id IN (%Ls)',
|
||||||
$this->ids);
|
$this->ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->phids) {
|
if ($this->phids !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'phid IN (%Ls)',
|
'phid IN (%Ls)',
|
||||||
$this->phids);
|
$this->phids);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->domain) {
|
if ($this->domain !== null) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn,
|
||||||
'domain = %s',
|
'domain = %s',
|
||||||
$this->domain);
|
$this->domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
$where[] = $this->buildPagingClause($conn_r);
|
return $where;
|
||||||
|
|
||||||
return $this->formatWhereClause($where);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getQueryApplicationClass() {
|
public function getQueryApplicationClass() {
|
||||||
|
|
80
src/applications/phame/query/PhameBlogSearchEngine.php
Normal file
80
src/applications/phame/query/PhameBlogSearchEngine.php
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue