Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/harbormaster/query/HarbormasterBuildPlanSearchEngine.php
12256 views
1
<?php
2
3
final class HarbormasterBuildPlanSearchEngine
4
extends PhabricatorApplicationSearchEngine {
5
6
public function getResultTypeDescription() {
7
return pht('Harbormaster Build Plans');
8
}
9
10
public function getApplicationClassName() {
11
return 'PhabricatorHarbormasterApplication';
12
}
13
14
public function newQuery() {
15
return new HarbormasterBuildPlanQuery();
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
id(new PhabricatorSearchCheckboxesField())
25
->setLabel(pht('Status'))
26
->setKey('status')
27
->setAliases(array('statuses'))
28
->setOptions(
29
array(
30
HarbormasterBuildPlan::STATUS_ACTIVE => pht('Active'),
31
HarbormasterBuildPlan::STATUS_DISABLED => pht('Disabled'),
32
)),
33
);
34
}
35
36
protected function buildQueryFromParameters(array $map) {
37
$query = $this->newQuery();
38
39
if ($map['match'] !== null) {
40
$query->withNameNgrams($map['match']);
41
}
42
43
if ($map['status']) {
44
$query->withStatuses($map['status']);
45
}
46
47
return $query;
48
}
49
50
protected function getURI($path) {
51
return '/harbormaster/plan/'.$path;
52
}
53
54
protected function getBuiltinQueryNames() {
55
return array(
56
'active' => pht('Active Plans'),
57
'all' => pht('All Plans'),
58
);
59
}
60
61
public function buildSavedQueryFromBuiltin($query_key) {
62
$query = $this->newSavedQuery();
63
$query->setQueryKey($query_key);
64
65
switch ($query_key) {
66
case 'active':
67
return $query->setParameter(
68
'status',
69
array(
70
HarbormasterBuildPlan::STATUS_ACTIVE,
71
));
72
case 'all':
73
return $query;
74
}
75
76
return parent::buildSavedQueryFromBuiltin($query_key);
77
}
78
79
protected function renderResultList(
80
array $plans,
81
PhabricatorSavedQuery $query,
82
array $handles) {
83
assert_instances_of($plans, 'HarbormasterBuildPlan');
84
85
$viewer = $this->requireViewer();
86
87
if ($plans) {
88
$edge_query = id(new PhabricatorEdgeQuery())
89
->withSourcePHIDs(mpull($plans, 'getPHID'))
90
->withEdgeTypes(
91
array(
92
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
93
));
94
95
$edge_query->execute();
96
}
97
98
$list = new PHUIObjectItemListView();
99
foreach ($plans as $plan) {
100
$id = $plan->getID();
101
102
$item = id(new PHUIObjectItemView())
103
->setObjectName(pht('Plan %d', $id))
104
->setHeader($plan->getName());
105
106
if ($plan->isDisabled()) {
107
$item->setDisabled(true);
108
}
109
110
if ($plan->isAutoplan()) {
111
$item->addIcon('fa-lock grey', pht('Autoplan'));
112
}
113
114
$item->setHref($this->getApplicationURI("plan/{$id}/"));
115
116
$phid = $plan->getPHID();
117
$project_phids = $edge_query->getDestinationPHIDs(array($phid));
118
$project_handles = $viewer->loadHandles($project_phids);
119
120
$item->addAttribute(
121
id(new PHUIHandleTagListView())
122
->setLimit(4)
123
->setNoDataString(pht('No Projects'))
124
->setSlim(true)
125
->setHandles($project_handles));
126
127
$list->addItem($item);
128
}
129
130
$result = new PhabricatorApplicationSearchResultView();
131
$result->setObjectList($list);
132
$result->setNoDataString(pht('No build plans found.'));
133
134
return $result;
135
136
}
137
138
}
139
140