@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final 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::class;
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 /**
80 * @param array<HarbormasterBuildPlan> $plans
81 * @param PhabricatorSavedQuery $query
82 * @param array<PhabricatorObjectHandle> $handles
83 */
84 protected function renderResultList(
85 array $plans,
86 PhabricatorSavedQuery $query,
87 array $handles) {
88 assert_instances_of($plans, HarbormasterBuildPlan::class);
89
90 $viewer = $this->requireViewer();
91
92 if ($plans) {
93 $edge_query = id(new PhabricatorEdgeQuery())
94 ->withSourcePHIDs(mpull($plans, 'getPHID'))
95 ->withEdgeTypes(
96 array(
97 PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
98 ));
99
100 $edge_query->execute();
101 }
102
103 $list = new PHUIObjectItemListView();
104 foreach ($plans as $plan) {
105 $id = $plan->getID();
106
107 $item = id(new PHUIObjectItemView())
108 ->setObjectName(pht('Plan %d', $id))
109 ->setHeader($plan->getName());
110
111 if ($plan->isDisabled()) {
112 $item->setDisabled(true);
113 }
114
115 if ($plan->isAutoplan()) {
116 $item->addIcon('fa-lock grey', pht('Autoplan'));
117 }
118
119 $item->setHref($this->getApplicationURI("plan/{$id}/"));
120
121 $phid = $plan->getPHID();
122 $project_phids = $edge_query->getDestinationPHIDs(array($phid));
123 $project_handles = $viewer->loadHandles($project_phids);
124
125 $item->addAttribute(
126 id(new PHUIHandleTagListView())
127 ->setLimit(4)
128 ->setNoDataString(pht('No Projects'))
129 ->setSlim(true)
130 ->setHandles($project_handles));
131
132 $list->addItem($item);
133 }
134
135 $result = new PhabricatorApplicationSearchResultView();
136 $result->setObjectList($list);
137 $result->setNoDataString(pht('No build plans found.'));
138
139 return $result;
140
141 }
142
143}