1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-03-26 11:10:16 +01:00
phorge-phorge/src/applications/diviner/query/DivinerAtomSearchEngine.php
epriestley 78b89711cb Move a bunch more rendering into SearchEngine
Summary: Ref T4986. These are mostly mechanical now, I skipped a couple of slightly tricky ones. Still a bunch to go.

Test Plan:
For each engine:

  - Viewed the application;
  - created a panel to issue the query.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4986

Differential Revision: https://secure.phabricator.com/D9017
2014-05-08 20:04:19 -07:00

123 lines
2.8 KiB
PHP

<?php
final class DivinerAtomSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getApplicationClassName() {
return 'PhabricatorApplicationDiviner';
}
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();
$saved->setParameter(
'types',
$this->readListFromRequest($request, 'types'));
$saved->setParameter('name', $request->getStr('name'));
return $saved;
}
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new DivinerAtomQuery());
$types = $saved->getParameter('types');
if ($types) {
$query->withTypes($types);
}
$name = $saved->getParameter('name');
if ($name) {
$query->withNameContains($name);
}
return $query;
}
public function buildSearchForm(
AphrontFormView $form,
PhabricatorSavedQuery $saved) {
$all_types = array();
foreach (DivinerAtom::getAllTypes() as $type) {
$all_types[$type] = DivinerAtom::getAtomTypeNameString($type);
}
asort($all_types);
$types = $saved->getParameter('types', array());
$types = array_fuse($types);
$type_control = id(new AphrontFormCheckboxControl())
->setLabel(pht('Types'));
foreach ($all_types as $type => $name) {
$type_control->addCheckbox(
'types[]',
$type,
$name,
isset($types[$type]));
}
$form
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Name Contains'))
->setName('name')
->setValue($saved->getParameter('name')))
->appendChild($type_control);
}
protected function getURI($path) {
return '/diviner/'.$path;
}
public 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 $symbols,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($symbols, 'DivinerLiveSymbol');
$viewer = $this->requireViewer();
$list = id(new PHUIObjectItemListView())
->setUser($viewer);
foreach ($symbols as $symbol) {
$type = $symbol->getType();
$type_name = DivinerAtom::getAtomTypeNameString($type);
$item = id(new PHUIObjectItemView())
->setHeader($symbol->getTitle())
->setHref($symbol->getURI())
->addAttribute($symbol->getSummary())
->addIcon('none', $type_name);
$list->addItem($item);
}
return $list;
}
}