Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/almanac/query/AlmanacNamespaceSearchEngine.php
12256 views
1
<?php
2
3
final class AlmanacNamespaceSearchEngine
4
extends PhabricatorApplicationSearchEngine {
5
6
public function getResultTypeDescription() {
7
return pht('Almanac Namespaces');
8
}
9
10
public function getApplicationClassName() {
11
return 'PhabricatorAlmanacApplication';
12
}
13
14
public function newQuery() {
15
return new AlmanacNamespaceQuery();
16
}
17
18
protected function buildCustomSearchFields() {
19
return array(
20
id(new PhabricatorSearchTextField())
21
->setLabel(pht('Name Contains'))
22
->setKey('match')
23
->setDescription(pht('Search for namespaces by name substring.')),
24
);
25
}
26
27
protected function buildQueryFromParameters(array $map) {
28
$query = $this->newQuery();
29
30
if ($map['match'] !== null) {
31
$query->withNameNgrams($map['match']);
32
}
33
34
return $query;
35
}
36
37
protected function getURI($path) {
38
return '/almanac/namespace/'.$path;
39
}
40
41
protected function getBuiltinQueryNames() {
42
$names = array(
43
'all' => pht('All Namespaces'),
44
);
45
46
return $names;
47
}
48
49
public function buildSavedQueryFromBuiltin($query_key) {
50
51
$query = $this->newSavedQuery();
52
$query->setQueryKey($query_key);
53
54
switch ($query_key) {
55
case 'all':
56
return $query;
57
}
58
59
return parent::buildSavedQueryFromBuiltin($query_key);
60
}
61
62
protected function renderResultList(
63
array $namespaces,
64
PhabricatorSavedQuery $query,
65
array $handles) {
66
assert_instances_of($namespaces, 'AlmanacNamespace');
67
68
$viewer = $this->requireViewer();
69
70
$list = new PHUIObjectItemListView();
71
$list->setUser($viewer);
72
foreach ($namespaces as $namespace) {
73
$id = $namespace->getID();
74
75
$item = id(new PHUIObjectItemView())
76
->setObjectName(pht('Namespace %d', $id))
77
->setHeader($namespace->getName())
78
->setHref($this->getApplicationURI("namespace/{$id}/"))
79
->setObject($namespace);
80
81
$list->addItem($item);
82
}
83
84
$result = new PhabricatorApplicationSearchResultView();
85
$result->setObjectList($list);
86
$result->setNoDataString(pht('No Almanac namespaces found.'));
87
88
return $result;
89
}
90
}
91
92