Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diviner/query/DivinerAtomSearchEngine.php
| <?php | <?php | ||||
| final class DivinerAtomSearchEngine extends PhabricatorApplicationSearchEngine { | final class DivinerAtomSearchEngine extends PhabricatorApplicationSearchEngine { | ||||
| public function getResultTypeDescription() { | public function getResultTypeDescription() { | ||||
| return pht('Documentation Atoms'); | return pht('Documentation Atoms'); | ||||
| } | } | ||||
| public function getApplicationClassName() { | public function getApplicationClassName() { | ||||
| return 'PhabricatorDivinerApplication'; | return 'PhabricatorDivinerApplication'; | ||||
| } | } | ||||
| public function buildSavedQueryFromRequest(AphrontRequest $request) { | public function newResultObject() { | ||||
| $saved = new PhabricatorSavedQuery(); | return new DivinerLiveAtom(); | ||||
| } | |||||
| $saved->setParameter( | |||||
| 'bookPHIDs', | |||||
| $this->readPHIDsFromRequest($request, 'bookPHIDs')); | |||||
| $saved->setParameter( | |||||
| 'repositoryPHIDs', | |||||
| $this->readPHIDsFromRequest($request, 'repositoryPHIDs')); | |||||
| $saved->setParameter('name', $request->getStr('name')); | |||||
| $saved->setParameter( | |||||
| 'types', | |||||
| $this->readListFromRequest($request, 'types')); | |||||
| return $saved; | protected function buildCustomSearchFields() { | ||||
| return array( | |||||
| id(new PhabricatorSearchTextField()) | |||||
| ->setKey('name') | |||||
| ->setLabel(pht('Name Contains')), | |||||
| id(new PhabricatorSearchCheckboxesField()) | |||||
| ->setKey('types') | |||||
| ->setLabel(pht('Types')) | |||||
| ->setOptions(DivinerAtom::getAllTypes()), | |||||
| id(new PhabricatorSearchBooksField()) | |||||
| ->setKey('bookPHIDs') | |||||
| ->setAliases(array('books')) | |||||
| ->setLabel(pht('Books')), | |||||
| id(new PhabricatorSearchRepositoryField()) | |||||
| ->setKey('repositoryPHIDs') | |||||
| ->setAliases(array('repositories')) | |||||
| ->setLabel(pht('Repositories')), | |||||
| ); | |||||
| } | } | ||||
| public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { | protected function buildQueryFromParameters(array $map) { | ||||
| $query = id(new DivinerAtomQuery()); | $query = id(new DivinerAtomQuery()); | ||||
| $books = $saved->getParameter('bookPHIDs'); | if ($map['bookPHIDs']) { | ||||
| if ($books) { | $query->withBookPHIDs($map['bookPHIDs']); | ||||
| $query->withBookPHIDs($books); | |||||
| } | } | ||||
| $repository_phids = $saved->getParameter('repositoryPHIDs'); | if ($map['repositoryPHIDs']) { | ||||
| if ($repository_phids) { | $query->withRepositoryPHIDs($map['repositoryPHIDs']); | ||||
| $query->withRepositoryPHIDs($repository_phids); | |||||
| } | } | ||||
| $name = $saved->getParameter('name'); | if ($map['name']) { | ||||
| if ($name) { | $query->withNameContains($map['name']); | ||||
| $query->withNameContains($name); | |||||
| } | } | ||||
| $types = $saved->getParameter('types'); | if ($map['types']) { | ||||
| if ($types) { | $query->withTypes($map['types']); | ||||
| $query->withTypes($types); | |||||
| } | } | ||||
| return $query; | return $query; | ||||
| } | } | ||||
| public function buildSearchForm( | |||||
| AphrontFormView $form, | |||||
| PhabricatorSavedQuery $saved) { | |||||
| $form->appendChild( | |||||
| id(new AphrontFormTextControl()) | |||||
| ->setLabel(pht('Name Contains')) | |||||
| ->setName('name') | |||||
| ->setValue($saved->getParameter('name'))); | |||||
| $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($type_control); | |||||
| $form->appendControl( | |||||
| id(new AphrontFormTokenizerControl()) | |||||
| ->setDatasource(new DivinerBookDatasource()) | |||||
| ->setName('bookPHIDs') | |||||
| ->setLabel(pht('Books')) | |||||
| ->setValue($saved->getParameter('bookPHIDs'))); | |||||
| $form->appendControl( | |||||
| id(new AphrontFormTokenizerControl()) | |||||
| ->setLabel(pht('Repositories')) | |||||
| ->setName('repositoryPHIDs') | |||||
| ->setDatasource(new DiffusionRepositoryDatasource()) | |||||
| ->setValue($saved->getParameter('repositoryPHIDs'))); | |||||
| } | |||||
| protected function getURI($path) { | protected function getURI($path) { | ||||
| return '/diviner/'.$path; | return '/diviner/'.$path; | ||||
| } | } | ||||
| protected function getBuiltinQueryNames() { | protected function getBuiltinQueryNames() { | ||||
| return array( | return array( | ||||
| 'all' => pht('All'), | 'all' => pht('All'), | ||||
| ▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines | |||||