Path: blob/master/src/applications/herald/query/HeraldRuleSearchEngine.php
12256 views
<?php12final class HeraldRuleSearchEngine extends PhabricatorApplicationSearchEngine {34public function getResultTypeDescription() {5return pht('Herald Rules');6}78public function getApplicationClassName() {9return 'PhabricatorHeraldApplication';10}1112public function newQuery() {13return id(new HeraldRuleQuery())14->needValidateAuthors(true);15}1617protected function buildCustomSearchFields() {18$viewer = $this->requireViewer();1920$rule_types = HeraldRuleTypeConfig::getRuleTypeMap();21$content_types = HeraldAdapter::getEnabledAdapterMap($viewer);2223return array(24id(new PhabricatorUsersSearchField())25->setLabel(pht('Authors'))26->setKey('authorPHIDs')27->setAliases(array('author', 'authors', 'authorPHID'))28->setDescription(29pht('Search for rules with given authors.')),30id(new PhabricatorSearchCheckboxesField())31->setKey('ruleTypes')32->setAliases(array('ruleType'))33->setLabel(pht('Rule Type'))34->setDescription(35pht('Search for rules of given types.'))36->setOptions($rule_types),37id(new PhabricatorSearchCheckboxesField())38->setKey('contentTypes')39->setLabel(pht('Content Type'))40->setDescription(41pht('Search for rules affecting given types of content.'))42->setOptions($content_types),43id(new PhabricatorSearchThreeStateField())44->setLabel(pht('Active Rules'))45->setKey('active')46->setOptions(47pht('(Show All)'),48pht('Show Only Active Rules'),49pht('Show Only Inactive Rules')),50id(new PhabricatorSearchThreeStateField())51->setLabel(pht('Disabled Rules'))52->setKey('disabled')53->setOptions(54pht('(Show All)'),55pht('Show Only Disabled Rules'),56pht('Show Only Enabled Rules')),57id(new PhabricatorPHIDsSearchField())58->setLabel(pht('Affected Objects'))59->setKey('affectedPHIDs')60->setAliases(array('affectedPHID')),61);62}6364protected function buildQueryFromParameters(array $map) {65$query = $this->newQuery();6667if ($map['authorPHIDs']) {68$query->withAuthorPHIDs($map['authorPHIDs']);69}7071if ($map['contentTypes']) {72$query->withContentTypes($map['contentTypes']);73}7475if ($map['ruleTypes']) {76$query->withRuleTypes($map['ruleTypes']);77}7879if ($map['disabled'] !== null) {80$query->withDisabled($map['disabled']);81}8283if ($map['active'] !== null) {84$query->withActive($map['active']);85}8687if ($map['affectedPHIDs']) {88$query->withAffectedObjectPHIDs($map['affectedPHIDs']);89}9091return $query;92}9394protected function getURI($path) {95return '/herald/'.$path;96}9798protected function getBuiltinQueryNames() {99$names = array();100101if ($this->requireViewer()->isLoggedIn()) {102$names['authored'] = pht('Authored');103}104105$names['active'] = pht('Active');106$names['all'] = pht('All');107108return $names;109}110111public function buildSavedQueryFromBuiltin($query_key) {112$query = $this->newSavedQuery();113$query->setQueryKey($query_key);114115$viewer_phid = $this->requireViewer()->getPHID();116117switch ($query_key) {118case 'all':119return $query;120case 'active':121return $query122->setParameter('active', true);123case 'authored':124return $query125->setParameter('authorPHIDs', array($viewer_phid))126->setParameter('disabled', false);127}128129return parent::buildSavedQueryFromBuiltin($query_key);130}131132protected function renderResultList(133array $rules,134PhabricatorSavedQuery $query,135array $handles) {136assert_instances_of($rules, 'HeraldRule');137$viewer = $this->requireViewer();138139$list = id(new HeraldRuleListView())140->setViewer($viewer)141->setRules($rules)142->newObjectList();143144$result = new PhabricatorApplicationSearchResultView();145$result->setObjectList($list);146$result->setNoDataString(pht('No rules found.'));147148return $result;149}150151protected function getNewUserBody() {152$create_button = id(new PHUIButtonView())153->setTag('a')154->setText(pht('Create Herald Rule'))155->setHref('/herald/create/')156->setColor(PHUIButtonView::GREEN);157158$icon = $this->getApplication()->getIcon();159$app_name = $this->getApplication()->getName();160$view = id(new PHUIBigInfoView())161->setIcon($icon)162->setTitle(pht('Welcome to %s', $app_name))163->setDescription(164pht('A flexible rules engine that can notify and act on '.165'other actions such as tasks, diffs, and commits.'))166->addAction($create_button);167168return $view;169}170171}172173174