Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/feed/query/PhabricatorFeedTransactionSearchEngine.php
12242 views
1
<?php
2
3
final class PhabricatorFeedTransactionSearchEngine
4
extends PhabricatorApplicationSearchEngine {
5
6
public function getResultTypeDescription() {
7
return pht('Transactions');
8
}
9
10
public function getApplicationClassName() {
11
return 'PhabricatorFeedApplication';
12
}
13
14
public function newQuery() {
15
return new PhabricatorFeedTransactionQuery();
16
}
17
18
protected function buildCustomSearchFields() {
19
return array(
20
id(new PhabricatorUsersSearchField())
21
->setLabel(pht('Authors'))
22
->setKey('authorPHIDs')
23
->setAliases(array('author', 'authors')),
24
id(new PhabricatorSearchDatasourceField())
25
->setLabel(pht('Object Types'))
26
->setKey('objectTypes')
27
->setAliases(array('objectType'))
28
->setDatasource(new PhabricatorTransactionsObjectTypeDatasource()),
29
id(new PhabricatorSearchDateField())
30
->setLabel(pht('Created After'))
31
->setKey('createdStart'),
32
id(new PhabricatorSearchDateField())
33
->setLabel(pht('Created Before'))
34
->setKey('createdEnd'),
35
);
36
}
37
38
protected function buildQueryFromParameters(array $map) {
39
$query = $this->newQuery();
40
41
if ($map['authorPHIDs']) {
42
$query->withAuthorPHIDs($map['authorPHIDs']);
43
}
44
45
if ($map['objectTypes']) {
46
$query->withObjectTypes($map['objectTypes']);
47
}
48
49
$created_min = $map['createdStart'];
50
$created_max = $map['createdEnd'];
51
52
if ($created_min && $created_max) {
53
if ($created_min > $created_max) {
54
throw new PhabricatorSearchConstraintException(
55
pht(
56
'The specified "Created Before" date is earlier in time than the '.
57
'specified "Created After" date, so this query can never match '.
58
'any results.'));
59
}
60
}
61
62
if ($created_min || $created_max) {
63
$query->withDateCreatedBetween($created_min, $created_max);
64
}
65
66
return $query;
67
}
68
69
protected function getURI($path) {
70
return '/feed/transactions/'.$path;
71
}
72
73
protected function getBuiltinQueryNames() {
74
$names = array(
75
'all' => pht('All Transactions'),
76
);
77
78
return $names;
79
}
80
81
public function buildSavedQueryFromBuiltin($query_key) {
82
$query = $this->newSavedQuery()
83
->setQueryKey($query_key);
84
85
switch ($query_key) {
86
case 'all':
87
return $query;
88
}
89
90
return parent::buildSavedQueryFromBuiltin($query_key);
91
}
92
93
protected function renderResultList(
94
array $objects,
95
PhabricatorSavedQuery $query,
96
array $handles) {
97
assert_instances_of($objects, 'PhabricatorApplicationTransaction');
98
99
$viewer = $this->requireViewer();
100
101
$handle_phids = array();
102
foreach ($objects as $object) {
103
$author_phid = $object->getAuthorPHID();
104
if ($author_phid !== null) {
105
$handle_phids[] = $author_phid;
106
}
107
$object_phid = $object->getObjectPHID();
108
if ($object_phid !== null) {
109
$handle_phids[] = $object_phid;
110
}
111
}
112
113
$handles = $viewer->loadHandles($handle_phids);
114
115
$rows = array();
116
foreach ($objects as $object) {
117
$author_phid = $object->getAuthorPHID();
118
$object_phid = $object->getObjectPHID();
119
120
try {
121
$title = $object->getTitle();
122
} catch (Exception $ex) {
123
$title = null;
124
}
125
126
$rows[] = array(
127
$handles[$author_phid]->renderLink(),
128
$handles[$object_phid]->renderLink(),
129
AphrontTableView::renderSingleDisplayLine($title),
130
phabricator_datetime($object->getDateCreated(), $viewer),
131
);
132
}
133
134
$table = id(new AphrontTableView($rows))
135
->setHeaders(
136
array(
137
pht('Author'),
138
pht('Object'),
139
pht('Transaction'),
140
pht('Date'),
141
))
142
->setColumnClasses(
143
array(
144
null,
145
null,
146
'wide',
147
'right',
148
));
149
150
return id(new PhabricatorApplicationSearchResultView())
151
->setTable($table);
152
}
153
154
protected function newExportFields() {
155
$fields = array(
156
id(new PhabricatorPHIDExportField())
157
->setKey('authorPHID')
158
->setLabel(pht('Author PHID')),
159
id(new PhabricatorStringExportField())
160
->setKey('author')
161
->setLabel(pht('Author')),
162
id(new PhabricatorStringExportField())
163
->setKey('objectType')
164
->setLabel(pht('Object Type')),
165
id(new PhabricatorPHIDExportField())
166
->setKey('objectPHID')
167
->setLabel(pht('Object PHID')),
168
id(new PhabricatorStringExportField())
169
->setKey('objectName')
170
->setLabel(pht('Object Name')),
171
id(new PhabricatorStringExportField())
172
->setKey('description')
173
->setLabel(pht('Description')),
174
);
175
176
return $fields;
177
}
178
179
protected function newExportData(array $xactions) {
180
$viewer = $this->requireViewer();
181
182
$phids = array();
183
foreach ($xactions as $xaction) {
184
$phids[] = $xaction->getAuthorPHID();
185
$phids[] = $xaction->getObjectPHID();
186
}
187
$handles = $viewer->loadHandles($phids);
188
189
$export = array();
190
foreach ($xactions as $xaction) {
191
$xaction_phid = $xaction->getPHID();
192
193
$author_phid = $xaction->getAuthorPHID();
194
if ($author_phid) {
195
$author_name = $handles[$author_phid]->getName();
196
} else {
197
$author_name = null;
198
}
199
200
$object_phid = $xaction->getObjectPHID();
201
if ($object_phid) {
202
$object_name = $handles[$object_phid]->getName();
203
} else {
204
$object_name = null;
205
}
206
207
$old_target = $xaction->getRenderingTarget();
208
try {
209
$description = $xaction
210
->setRenderingTarget(PhabricatorApplicationTransaction::TARGET_TEXT)
211
->getTitle();
212
} catch (Exception $ex) {
213
$description = null;
214
}
215
$xaction->setRenderingTarget($old_target);
216
217
$export[] = array(
218
'authorPHID' => $author_phid,
219
'author' => $author_name,
220
'objectType' => phid_get_subtype($xaction_phid),
221
'objectPHID' => $object_phid,
222
'objectName' => $object_name,
223
'description' => $description,
224
);
225
}
226
227
return $export;
228
}
229
230
}
231
232