Path: blob/master/src/applications/diviner/query/DivinerAtomSearchEngine.php
12256 views
<?php12final class DivinerAtomSearchEngine extends PhabricatorApplicationSearchEngine {34public function getResultTypeDescription() {5return pht('Documentation Atoms');6}78public function getApplicationClassName() {9return 'PhabricatorDivinerApplication';10}1112public function canUseInPanelContext() {13return false;14}1516public function buildSavedQueryFromRequest(AphrontRequest $request) {17$saved = new PhabricatorSavedQuery();1819$saved->setParameter(20'bookPHIDs',21$this->readPHIDsFromRequest($request, 'bookPHIDs'));22$saved->setParameter(23'repositoryPHIDs',24$this->readPHIDsFromRequest($request, 'repositoryPHIDs'));25$saved->setParameter('name', $request->getStr('name'));26$saved->setParameter(27'types',28$this->readListFromRequest($request, 'types'));2930return $saved;31}3233public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {34$query = id(new DivinerAtomQuery());3536$books = $saved->getParameter('bookPHIDs');37if ($books) {38$query->withBookPHIDs($books);39}4041$repository_phids = $saved->getParameter('repositoryPHIDs');42if ($repository_phids) {43$query->withRepositoryPHIDs($repository_phids);44}4546$name = $saved->getParameter('name');47if ($name) {48$query->withNameContains($name);49}5051$types = $saved->getParameter('types');52if ($types) {53$query->withTypes($types);54}5556return $query;57}5859public function buildSearchForm(60AphrontFormView $form,61PhabricatorSavedQuery $saved) {6263$form->appendChild(64id(new AphrontFormTextControl())65->setLabel(pht('Name Contains'))66->setName('name')67->setValue($saved->getParameter('name')));6869$all_types = array();70foreach (DivinerAtom::getAllTypes() as $type) {71$all_types[$type] = DivinerAtom::getAtomTypeNameString($type);72}73asort($all_types);7475$types = $saved->getParameter('types', array());76$types = array_fuse($types);77$type_control = id(new AphrontFormCheckboxControl())78->setLabel(pht('Types'));79foreach ($all_types as $type => $name) {80$type_control->addCheckbox(81'types[]',82$type,83$name,84isset($types[$type]));85}86$form->appendChild($type_control);8788$form->appendControl(89id(new AphrontFormTokenizerControl())90->setDatasource(new DivinerBookDatasource())91->setName('bookPHIDs')92->setLabel(pht('Books'))93->setValue($saved->getParameter('bookPHIDs')));9495$form->appendControl(96id(new AphrontFormTokenizerControl())97->setLabel(pht('Repositories'))98->setName('repositoryPHIDs')99->setDatasource(new DiffusionRepositoryDatasource())100->setValue($saved->getParameter('repositoryPHIDs')));101}102103protected function getURI($path) {104return '/diviner/'.$path;105}106107protected function getBuiltinQueryNames() {108return array(109'all' => pht('All Atoms'),110);111}112113public function buildSavedQueryFromBuiltin($query_key) {114$query = $this->newSavedQuery();115$query->setQueryKey($query_key);116117switch ($query_key) {118case 'all':119return $query;120}121122return parent::buildSavedQueryFromBuiltin($query_key);123}124125protected function renderResultList(126array $symbols,127PhabricatorSavedQuery $query,128array $handles) {129130assert_instances_of($symbols, 'DivinerLiveSymbol');131132$viewer = $this->requireViewer();133134$list = id(new PHUIObjectItemListView())135->setUser($viewer);136137foreach ($symbols as $symbol) {138$type = $symbol->getType();139$type_name = DivinerAtom::getAtomTypeNameString($type);140141$item = id(new PHUIObjectItemView())142->setHeader($symbol->getTitle())143->setHref($symbol->getURI())144->addAttribute($symbol->getSummary())145->addIcon('none', $type_name);146147$list->addItem($item);148}149150$result = new PhabricatorApplicationSearchResultView();151$result->setObjectList($list);152$result->setNoDataString(pht('No books found.'));153154return $result;155}156157}158159160