Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/herald/query/HeraldRuleSearchEngine.php
12256 views
1
<?php
2
3
final class HeraldRuleSearchEngine extends PhabricatorApplicationSearchEngine {
4
5
public function getResultTypeDescription() {
6
return pht('Herald Rules');
7
}
8
9
public function getApplicationClassName() {
10
return 'PhabricatorHeraldApplication';
11
}
12
13
public function newQuery() {
14
return id(new HeraldRuleQuery())
15
->needValidateAuthors(true);
16
}
17
18
protected function buildCustomSearchFields() {
19
$viewer = $this->requireViewer();
20
21
$rule_types = HeraldRuleTypeConfig::getRuleTypeMap();
22
$content_types = HeraldAdapter::getEnabledAdapterMap($viewer);
23
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')),
62
);
63
}
64
65
protected function buildQueryFromParameters(array $map) {
66
$query = $this->newQuery();
67
68
if ($map['authorPHIDs']) {
69
$query->withAuthorPHIDs($map['authorPHIDs']);
70
}
71
72
if ($map['contentTypes']) {
73
$query->withContentTypes($map['contentTypes']);
74
}
75
76
if ($map['ruleTypes']) {
77
$query->withRuleTypes($map['ruleTypes']);
78
}
79
80
if ($map['disabled'] !== null) {
81
$query->withDisabled($map['disabled']);
82
}
83
84
if ($map['active'] !== null) {
85
$query->withActive($map['active']);
86
}
87
88
if ($map['affectedPHIDs']) {
89
$query->withAffectedObjectPHIDs($map['affectedPHIDs']);
90
}
91
92
return $query;
93
}
94
95
protected function getURI($path) {
96
return '/herald/'.$path;
97
}
98
99
protected function getBuiltinQueryNames() {
100
$names = array();
101
102
if ($this->requireViewer()->isLoggedIn()) {
103
$names['authored'] = pht('Authored');
104
}
105
106
$names['active'] = pht('Active');
107
$names['all'] = pht('All');
108
109
return $names;
110
}
111
112
public function buildSavedQueryFromBuiltin($query_key) {
113
$query = $this->newSavedQuery();
114
$query->setQueryKey($query_key);
115
116
$viewer_phid = $this->requireViewer()->getPHID();
117
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);
128
}
129
130
return parent::buildSavedQueryFromBuiltin($query_key);
131
}
132
133
protected function renderResultList(
134
array $rules,
135
PhabricatorSavedQuery $query,
136
array $handles) {
137
assert_instances_of($rules, 'HeraldRule');
138
$viewer = $this->requireViewer();
139
140
$list = id(new HeraldRuleListView())
141
->setViewer($viewer)
142
->setRules($rules)
143
->newObjectList();
144
145
$result = new PhabricatorApplicationSearchResultView();
146
$result->setObjectList($list);
147
$result->setNoDataString(pht('No rules found.'));
148
149
return $result;
150
}
151
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);
158
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);
168
169
return $view;
170
}
171
172
}
173
174