Path: blob/master/src/applications/herald/query/HeraldWebhookSearchEngine.php
12256 views
<?php12final class HeraldWebhookSearchEngine3extends PhabricatorApplicationSearchEngine {45public function getResultTypeDescription() {6return pht('Webhooks');7}89public function getApplicationClassName() {10return 'PhabricatorHeraldApplication';11}1213public function newQuery() {14return new HeraldWebhookQuery();15}1617protected function buildQueryFromParameters(array $map) {18$query = $this->newQuery();1920if ($map['statuses']) {21$query->withStatuses($map['statuses']);22}2324return $query;25}2627protected function buildCustomSearchFields() {28return array(29id(new PhabricatorSearchCheckboxesField())30->setKey('statuses')31->setLabel(pht('Status'))32->setDescription(33pht('Search for archived or active pastes.'))34->setOptions(HeraldWebhook::getStatusDisplayNameMap()),35);36}3738protected function getURI($path) {39return '/herald/webhook/'.$path;40}4142protected function getBuiltinQueryNames() {43$names = array();4445$names['active'] = pht('Active');46$names['all'] = pht('All');4748return $names;49}5051public function buildSavedQueryFromBuiltin($query_key) {52$query = $this->newSavedQuery();53$query->setQueryKey($query_key);5455switch ($query_key) {56case 'all':57return $query;58case 'active':59return $query->setParameter(60'statuses',61array(62HeraldWebhook::HOOKSTATUS_FIREHOSE,63HeraldWebhook::HOOKSTATUS_ENABLED,64));65}6667return parent::buildSavedQueryFromBuiltin($query_key);68}6970protected function renderResultList(71array $hooks,72PhabricatorSavedQuery $query,73array $handles) {74assert_instances_of($hooks, 'HeraldWebhook');7576$viewer = $this->requireViewer();7778$list = id(new PHUIObjectItemListView())79->setViewer($viewer);80foreach ($hooks as $hook) {81$item = id(new PHUIObjectItemView())82->setObjectName(pht('Webhook %d', $hook->getID()))83->setHeader($hook->getName())84->setHref($hook->getURI())85->addAttribute($hook->getWebhookURI());8687$item->addIcon($hook->getStatusIcon(), $hook->getStatusDisplayName());8889if ($hook->isDisabled()) {90$item->setDisabled(true);91}9293$list->addItem($item);94}9596return id(new PhabricatorApplicationSearchResultView())97->setObjectList($list)98->setNoDataString(pht('No webhooks found.'));99}100101}102103104