Path: blob/master/src/applications/almanac/query/AlmanacServiceSearchEngine.php
12256 views
<?php12final class AlmanacServiceSearchEngine3extends PhabricatorApplicationSearchEngine {45public function getResultTypeDescription() {6return pht('Almanac Services');7}89public function getApplicationClassName() {10return 'PhabricatorAlmanacApplication';11}1213public function newQuery() {14return new AlmanacServiceQuery();15}1617protected function buildQueryFromParameters(array $map) {18$query = $this->newQuery();1920if ($map['match'] !== null) {21$query->withNameNgrams($map['match']);22}2324if ($map['names']) {25$query->withNames($map['names']);26}2728if ($map['devicePHIDs']) {29$query->withDevicePHIDs($map['devicePHIDs']);30}3132if ($map['serviceTypes']) {33$query->withServiceTypes($map['serviceTypes']);34}3536return $query;37}383940protected function buildCustomSearchFields() {41return array(42id(new PhabricatorSearchTextField())43->setLabel(pht('Name Contains'))44->setKey('match')45->setDescription(pht('Search for services by name substring.')),46id(new PhabricatorSearchStringListField())47->setLabel(pht('Exact Names'))48->setKey('names')49->setDescription(pht('Search for services with specific names.')),50id(new PhabricatorSearchDatasourceField())51->setLabel(pht('Service Types'))52->setKey('serviceTypes')53->setDescription(pht('Find services by type.'))54->setDatasource(id(new AlmanacServiceTypeDatasource())),55id(new PhabricatorPHIDsSearchField())56->setLabel(pht('Devices'))57->setKey('devicePHIDs')58->setDescription(59pht('Search for services bound to particular devices.')),60);61}6263protected function getURI($path) {64return '/almanac/service/'.$path;65}6667protected function getBuiltinQueryNames() {68$names = array(69'all' => pht('All Services'),70);7172return $names;73}7475public function buildSavedQueryFromBuiltin($query_key) {7677$query = $this->newSavedQuery();78$query->setQueryKey($query_key);7980switch ($query_key) {81case 'all':82return $query;83}8485return parent::buildSavedQueryFromBuiltin($query_key);86}8788protected function renderResultList(89array $services,90PhabricatorSavedQuery $query,91array $handles) {92assert_instances_of($services, 'AlmanacService');9394$viewer = $this->requireViewer();9596$list = new PHUIObjectItemListView();97$list->setUser($viewer);98foreach ($services as $service) {99$item = id(new PHUIObjectItemView())100->setObjectName(pht('Service %d', $service->getID()))101->setHeader($service->getName())102->setHref($service->getURI())103->setObject($service)104->addIcon(105$service->getServiceImplementation()->getServiceTypeIcon(),106$service->getServiceImplementation()->getServiceTypeShortName());107108$list->addItem($item);109}110111$result = new PhabricatorApplicationSearchResultView();112$result->setObjectList($list);113$result->setNoDataString(pht('No Almanac Services found.'));114115return $result;116}117}118119120