@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 DrydockAuthorizationSearchEngine
4 extends PhabricatorApplicationSearchEngine {
5
6 private $blueprint;
7
8 public function setBlueprint(DrydockBlueprint $blueprint) {
9 $this->blueprint = $blueprint;
10 return $this;
11 }
12
13 public function getBlueprint() {
14 return $this->blueprint;
15 }
16
17 public function getResultTypeDescription() {
18 return pht('Drydock Authorizations');
19 }
20
21 public function getApplicationClassName() {
22 return PhabricatorDrydockApplication::class;
23 }
24
25 public function canUseInPanelContext() {
26 return false;
27 }
28
29 public function newQuery() {
30 $query = new DrydockAuthorizationQuery();
31
32 $blueprint = $this->getBlueprint();
33 if ($blueprint) {
34 $query->withBlueprintPHIDs(array($blueprint->getPHID()));
35 }
36
37 return $query;
38 }
39
40 protected function buildQueryFromParameters(array $map) {
41 $query = $this->newQuery();
42
43 if ($map['blueprintPHIDs']) {
44 $query->withBlueprintPHIDs($map['blueprintPHIDs']);
45 }
46
47 if ($map['objectPHIDs']) {
48 $query->withObjectPHIDs($map['objectPHIDs']);
49 }
50
51 return $query;
52 }
53
54 protected function buildCustomSearchFields() {
55 return array(
56 id(new PhabricatorSearchDatasourceField())
57 ->setLabel(pht('Blueprints'))
58 ->setKey('blueprintPHIDs')
59 ->setConduitParameterType(new ConduitPHIDListParameterType())
60 ->setDescription(pht('Search authorizations for specific blueprints.'))
61 ->setAliases(array('blueprint', 'blueprints'))
62 ->setDatasource(new DrydockBlueprintDatasource()),
63 id(new PhabricatorPHIDsSearchField())
64 ->setLabel(pht('Objects'))
65 ->setKey('objectPHIDs')
66 ->setDescription(pht('Search authorizations from specific objects.'))
67 ->setAliases(array('object', 'objects')),
68 );
69 }
70
71 protected function getHiddenFields() {
72 return array(
73 'blueprintPHIDs',
74 'objectPHIDs',
75 );
76 }
77
78 protected function getURI($path) {
79 $blueprint = $this->getBlueprint();
80 if (!$blueprint) {
81 throw new PhutilInvalidStateException('setBlueprint');
82 }
83 $id = $blueprint->getID();
84 return "/drydock/blueprint/{$id}/authorizations/".$path;
85 }
86
87 protected function getBuiltinQueryNames() {
88 return array(
89 'all' => pht('All Authorizations'),
90 );
91 }
92
93 public function buildSavedQueryFromBuiltin($query_key) {
94 $query = $this->newSavedQuery();
95 $query->setQueryKey($query_key);
96
97 switch ($query_key) {
98 case 'all':
99 return $query;
100 }
101
102 return parent::buildSavedQueryFromBuiltin($query_key);
103 }
104
105 protected function renderResultList(
106 array $authorizations,
107 PhabricatorSavedQuery $query,
108 array $handles) {
109
110 $list = id(new DrydockAuthorizationListView())
111 ->setUser($this->requireViewer())
112 ->setAuthorizations($authorizations);
113
114 $result = new PhabricatorApplicationSearchResultView();
115 $result->setTable($list);
116
117 return $result;
118 }
119
120}