Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/almanac/query/AlmanacServiceSearchEngine.php
12256 views
1
<?php
2
3
final class AlmanacServiceSearchEngine
4
extends PhabricatorApplicationSearchEngine {
5
6
public function getResultTypeDescription() {
7
return pht('Almanac Services');
8
}
9
10
public function getApplicationClassName() {
11
return 'PhabricatorAlmanacApplication';
12
}
13
14
public function newQuery() {
15
return new AlmanacServiceQuery();
16
}
17
18
protected function buildQueryFromParameters(array $map) {
19
$query = $this->newQuery();
20
21
if ($map['match'] !== null) {
22
$query->withNameNgrams($map['match']);
23
}
24
25
if ($map['names']) {
26
$query->withNames($map['names']);
27
}
28
29
if ($map['devicePHIDs']) {
30
$query->withDevicePHIDs($map['devicePHIDs']);
31
}
32
33
if ($map['serviceTypes']) {
34
$query->withServiceTypes($map['serviceTypes']);
35
}
36
37
return $query;
38
}
39
40
41
protected function buildCustomSearchFields() {
42
return array(
43
id(new PhabricatorSearchTextField())
44
->setLabel(pht('Name Contains'))
45
->setKey('match')
46
->setDescription(pht('Search for services by name substring.')),
47
id(new PhabricatorSearchStringListField())
48
->setLabel(pht('Exact Names'))
49
->setKey('names')
50
->setDescription(pht('Search for services with specific names.')),
51
id(new PhabricatorSearchDatasourceField())
52
->setLabel(pht('Service Types'))
53
->setKey('serviceTypes')
54
->setDescription(pht('Find services by type.'))
55
->setDatasource(id(new AlmanacServiceTypeDatasource())),
56
id(new PhabricatorPHIDsSearchField())
57
->setLabel(pht('Devices'))
58
->setKey('devicePHIDs')
59
->setDescription(
60
pht('Search for services bound to particular devices.')),
61
);
62
}
63
64
protected function getURI($path) {
65
return '/almanac/service/'.$path;
66
}
67
68
protected function getBuiltinQueryNames() {
69
$names = array(
70
'all' => pht('All Services'),
71
);
72
73
return $names;
74
}
75
76
public function buildSavedQueryFromBuiltin($query_key) {
77
78
$query = $this->newSavedQuery();
79
$query->setQueryKey($query_key);
80
81
switch ($query_key) {
82
case 'all':
83
return $query;
84
}
85
86
return parent::buildSavedQueryFromBuiltin($query_key);
87
}
88
89
protected function renderResultList(
90
array $services,
91
PhabricatorSavedQuery $query,
92
array $handles) {
93
assert_instances_of($services, 'AlmanacService');
94
95
$viewer = $this->requireViewer();
96
97
$list = new PHUIObjectItemListView();
98
$list->setUser($viewer);
99
foreach ($services as $service) {
100
$item = id(new PHUIObjectItemView())
101
->setObjectName(pht('Service %d', $service->getID()))
102
->setHeader($service->getName())
103
->setHref($service->getURI())
104
->setObject($service)
105
->addIcon(
106
$service->getServiceImplementation()->getServiceTypeIcon(),
107
$service->getServiceImplementation()->getServiceTypeShortName());
108
109
$list->addItem($item);
110
}
111
112
$result = new PhabricatorApplicationSearchResultView();
113
$result->setObjectList($list);
114
$result->setNoDataString(pht('No Almanac Services found.'));
115
116
return $result;
117
}
118
}
119
120