Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/herald/query/HeraldTranscriptSearchEngine.php
12256 views
1
<?php
2
3
final class HeraldTranscriptSearchEngine
4
extends PhabricatorApplicationSearchEngine {
5
6
public function getResultTypeDescription() {
7
return pht('Herald Transcripts');
8
}
9
10
public function getApplicationClassName() {
11
return 'PhabricatorHeraldApplication';
12
}
13
14
public function canUseInPanelContext() {
15
return false;
16
}
17
18
public function buildSavedQueryFromRequest(AphrontRequest $request) {
19
$saved = new PhabricatorSavedQuery();
20
21
$object_monograms = $request->getStrList('objectMonograms');
22
$saved->setParameter('objectMonograms', $object_monograms);
23
24
$ids = $request->getStrList('ids');
25
foreach ($ids as $key => $id) {
26
if (!$id || !is_numeric($id)) {
27
unset($ids[$key]);
28
} else {
29
$ids[$key] = $id;
30
}
31
}
32
$saved->setParameter('ids', $ids);
33
34
return $saved;
35
}
36
37
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
38
$query = id(new HeraldTranscriptQuery());
39
40
$object_monograms = $saved->getParameter('objectMonograms');
41
if ($object_monograms) {
42
$objects = id(new PhabricatorObjectQuery())
43
->setViewer($this->requireViewer())
44
->withNames($object_monograms)
45
->execute();
46
$query->withObjectPHIDs(mpull($objects, 'getPHID'));
47
}
48
49
$ids = $saved->getParameter('ids');
50
if ($ids) {
51
$query->withIDs($ids);
52
}
53
54
return $query;
55
}
56
57
public function buildSearchForm(
58
AphrontFormView $form,
59
PhabricatorSavedQuery $saved) {
60
61
$object_monograms = $saved->getParameter('objectMonograms', array());
62
$ids = $saved->getParameter('ids', array());
63
64
$form
65
->appendChild(
66
id(new AphrontFormTextControl())
67
->setName('objectMonograms')
68
->setLabel(pht('Object Monograms'))
69
->setValue(implode(', ', $object_monograms)))
70
->appendChild(
71
id(new AphrontFormTextControl())
72
->setName('ids')
73
->setLabel(pht('Transcript IDs'))
74
->setValue(implode(', ', $ids)));
75
}
76
77
protected function getURI($path) {
78
return '/herald/transcript/'.$path;
79
}
80
81
protected function getBuiltinQueryNames() {
82
return array(
83
'all' => pht('All Transcripts'),
84
);
85
}
86
87
public function buildSavedQueryFromBuiltin($query_key) {
88
$query = $this->newSavedQuery();
89
$query->setQueryKey($query_key);
90
91
$viewer_phid = $this->requireViewer()->getPHID();
92
93
switch ($query_key) {
94
case 'all':
95
return $query;
96
}
97
98
return parent::buildSavedQueryFromBuiltin($query_key);
99
}
100
101
protected function getRequiredHandlePHIDsForResultList(
102
array $transcripts,
103
PhabricatorSavedQuery $query) {
104
return mpull($transcripts, 'getObjectPHID');
105
}
106
107
protected function renderResultList(
108
array $transcripts,
109
PhabricatorSavedQuery $query,
110
array $handles) {
111
assert_instances_of($transcripts, 'HeraldTranscript');
112
113
$viewer = $this->requireViewer();
114
115
$list = new PHUIObjectItemListView();
116
foreach ($transcripts as $xscript) {
117
$view_href = phutil_tag(
118
'a',
119
array(
120
'href' => '/herald/transcript/'.$xscript->getID().'/',
121
),
122
pht('View Full Transcript'));
123
124
$item = new PHUIObjectItemView();
125
$item->setObjectName($xscript->getID());
126
$item->setHeader($view_href);
127
if ($xscript->getDryRun()) {
128
$item->addAttribute(pht('Dry Run'));
129
}
130
$item->addAttribute($handles[$xscript->getObjectPHID()]->renderLink());
131
$item->addAttribute(
132
pht('%s ms', new PhutilNumber((int)(1000 * $xscript->getDuration()))));
133
$item->addIcon(
134
'none',
135
phabricator_datetime($xscript->getTime(), $viewer));
136
137
$list->addItem($item);
138
}
139
140
$result = new PhabricatorApplicationSearchResultView();
141
$result->setObjectList($list);
142
$result->setNoDataString(pht('No transcripts found.'));
143
144
return $result;
145
}
146
147
}
148
149