Differential D14382 Diff 34770 src/applications/search/engine/PhabricatorApplicationSearchEngine.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/engine/PhabricatorApplicationSearchEngine.php
Show All 16 Lines | |||||
abstract class PhabricatorApplicationSearchEngine extends Phobject { | abstract class PhabricatorApplicationSearchEngine extends Phobject { | ||||
private $application; | private $application; | ||||
private $viewer; | private $viewer; | ||||
private $errors = array(); | private $errors = array(); | ||||
private $customFields = false; | private $customFields = false; | ||||
private $request; | private $request; | ||||
private $context; | private $context; | ||||
private $controller; | |||||
private $namedQueries; | |||||
const CONTEXT_LIST = 'list'; | const CONTEXT_LIST = 'list'; | ||||
const CONTEXT_PANEL = 'panel'; | const CONTEXT_PANEL = 'panel'; | ||||
public function setController(PhabricatorController $controller) { | |||||
$this->controller = $controller; | |||||
return $this; | |||||
} | |||||
public function getController() { | |||||
return $this->controller; | |||||
} | |||||
public function buildResponse() { | |||||
$controller = $this->getController(); | |||||
$request = $controller->getRequest(); | |||||
$search = id(new PhabricatorApplicationSearchController()) | |||||
->setQueryKey($request->getURIData('queryKey')) | |||||
->setSearchEngine($this); | |||||
return $controller->delegateToController($search); | |||||
} | |||||
public function newResultObject() { | public function newResultObject() { | ||||
// We may be able to get this automatically if newQuery() is implemented. | // We may be able to get this automatically if newQuery() is implemented. | ||||
$query = $this->newQuery(); | $query = $this->newQuery(); | ||||
if ($query) { | if ($query) { | ||||
$object = $query->newResultObject(); | $object = $query->newResultObject(); | ||||
if ($object) { | if ($object) { | ||||
return $object; | return $object; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 417 Lines • ▼ Show 20 Lines | public function addNavigationItems(PHUIListView $menu) { | ||||
$advanced_uri = $this->getQueryResultsPageURI('advanced'); | $advanced_uri = $this->getQueryResultsPageURI('advanced'); | ||||
$menu->newLink(pht('Advanced Search'), $advanced_uri, 'query/advanced'); | $menu->newLink(pht('Advanced Search'), $advanced_uri, 'query/advanced'); | ||||
return $this; | return $this; | ||||
} | } | ||||
public function loadAllNamedQueries() { | public function loadAllNamedQueries() { | ||||
$viewer = $this->requireViewer(); | $viewer = $this->requireViewer(); | ||||
$builtin = $this->getBuiltinQueries($viewer); | |||||
if ($this->namedQueries === null) { | |||||
$named_queries = id(new PhabricatorNamedQueryQuery()) | $named_queries = id(new PhabricatorNamedQueryQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withUserPHIDs(array($viewer->getPHID())) | ->withUserPHIDs(array($viewer->getPHID())) | ||||
->withEngineClassNames(array(get_class($this))) | ->withEngineClassNames(array(get_class($this))) | ||||
->execute(); | ->execute(); | ||||
$named_queries = mpull($named_queries, null, 'getQueryKey'); | $named_queries = mpull($named_queries, null, 'getQueryKey'); | ||||
$builtin = $this->getBuiltinQueries($viewer); | |||||
$builtin = mpull($builtin, null, 'getQueryKey'); | $builtin = mpull($builtin, null, 'getQueryKey'); | ||||
foreach ($named_queries as $key => $named_query) { | foreach ($named_queries as $key => $named_query) { | ||||
if ($named_query->getIsBuiltin()) { | if ($named_query->getIsBuiltin()) { | ||||
if (isset($builtin[$key])) { | if (isset($builtin[$key])) { | ||||
$named_queries[$key]->setQueryName($builtin[$key]->getQueryName()); | $named_queries[$key]->setQueryName($builtin[$key]->getQueryName()); | ||||
unset($builtin[$key]); | unset($builtin[$key]); | ||||
} else { | } else { | ||||
unset($named_queries[$key]); | unset($named_queries[$key]); | ||||
} | } | ||||
} | } | ||||
unset($builtin[$key]); | unset($builtin[$key]); | ||||
} | } | ||||
$named_queries = msort($named_queries, 'getSortKey'); | $named_queries = msort($named_queries, 'getSortKey'); | ||||
$this->namedQueries = $named_queries; | |||||
} | |||||
return $named_queries + $builtin; | return $this->namedQueries + $builtin; | ||||
} | } | ||||
public function loadEnabledNamedQueries() { | public function loadEnabledNamedQueries() { | ||||
$named_queries = $this->loadAllNamedQueries(); | $named_queries = $this->loadAllNamedQueries(); | ||||
foreach ($named_queries as $key => $named_query) { | foreach ($named_queries as $key => $named_query) { | ||||
if ($named_query->getIsBuiltin() && $named_query->getIsDisabled()) { | if ($named_query->getIsBuiltin() && $named_query->getIsDisabled()) { | ||||
unset($named_queries[$key]); | unset($named_queries[$key]); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 637 Lines • Show Last 20 Lines |