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