Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / releeph / query / ReleephRequestSearchEngine.php
blob7f866405c107400670dd6c1da341b8f73b70af9b
1 <?php
3 final class ReleephRequestSearchEngine
4 extends PhabricatorApplicationSearchEngine {
6 private $branch;
7 private $baseURI;
9 public function getResultTypeDescription() {
10 return pht('Releeph Pull Requests');
13 public function getApplicationClassName() {
14 return 'PhabricatorReleephApplication';
17 public function canUseInPanelContext() {
18 return false;
21 public function setBranch(ReleephBranch $branch) {
22 $this->branch = $branch;
23 return $this;
26 public function getBranch() {
27 return $this->branch;
30 public function setBaseURI($base_uri) {
31 $this->baseURI = $base_uri;
32 return $this;
35 public function buildSavedQueryFromRequest(AphrontRequest $request) {
36 $saved = new PhabricatorSavedQuery();
38 $saved->setParameter('status', $request->getStr('status'));
39 $saved->setParameter('severity', $request->getStr('severity'));
40 $saved->setParameter(
41 'requestorPHIDs',
42 $this->readUsersFromRequest($request, 'requestors'));
44 return $saved;
47 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
48 $query = id(new ReleephRequestQuery())
49 ->withBranchIDs(array($this->getBranch()->getID()));
51 $status = $saved->getParameter('status');
52 $status = idx($this->getStatusValues(), $status);
53 if ($status) {
54 $query->withStatus($status);
57 $severity = $saved->getParameter('severity');
58 if ($severity) {
59 $query->withSeverities(array($severity));
62 $requestor_phids = $saved->getParameter('requestorPHIDs');
63 if ($requestor_phids) {
64 $query->withRequestorPHIDs($requestor_phids);
67 return $query;
70 public function buildSearchForm(
71 AphrontFormView $form,
72 PhabricatorSavedQuery $saved_query) {
74 $requestor_phids = $saved_query->getParameter('requestorPHIDs', array());
76 $form
77 ->appendChild(
78 id(new AphrontFormSelectControl())
79 ->setName('status')
80 ->setLabel(pht('Status'))
81 ->setValue($saved_query->getParameter('status'))
82 ->setOptions($this->getStatusOptions()))
83 ->appendChild(
84 id(new AphrontFormSelectControl())
85 ->setName('severity')
86 ->setLabel(pht('Severity'))
87 ->setValue($saved_query->getParameter('severity'))
88 ->setOptions($this->getSeverityOptions()))
89 ->appendControl(
90 id(new AphrontFormTokenizerControl())
91 ->setDatasource(new PhabricatorPeopleDatasource())
92 ->setName('requestors')
93 ->setLabel(pht('Requestors'))
94 ->setValue($requestor_phids));
97 protected function getURI($path) {
98 return $this->baseURI.$path;
101 protected function getBuiltinQueryNames() {
102 $names = array(
103 'open' => pht('Open Requests'),
104 'all' => pht('All Requests'),
107 if ($this->requireViewer()->isLoggedIn()) {
108 $names['requested'] = pht('Requested');
111 return $names;
114 public function buildSavedQueryFromBuiltin($query_key) {
116 $query = $this->newSavedQuery();
117 $query->setQueryKey($query_key);
119 switch ($query_key) {
120 case 'open':
121 return $query->setParameter('status', 'open');
122 case 'all':
123 return $query;
124 case 'requested':
125 return $query->setParameter(
126 'requestorPHIDs',
127 array($this->requireViewer()->getPHID()));
130 return parent::buildSavedQueryFromBuiltin($query_key);
133 private function getStatusOptions() {
134 return array(
135 '' => pht('(All Requests)'),
136 'open' => pht('Open Requests'),
137 'requested' => pht('Pull Requested'),
138 'needs-pull' => pht('Needs Pull'),
139 'rejected' => pht('Rejected'),
140 'abandoned' => pht('Abandoned'),
141 'pulled' => pht('Pulled'),
142 'needs-revert' => pht('Needs Revert'),
143 'reverted' => pht('Reverted'),
147 private function getStatusValues() {
148 return array(
149 'open' => ReleephRequestQuery::STATUS_OPEN,
150 'requested' => ReleephRequestQuery::STATUS_REQUESTED,
151 'needs-pull' => ReleephRequestQuery::STATUS_NEEDS_PULL,
152 'rejected' => ReleephRequestQuery::STATUS_REJECTED,
153 'abandoned' => ReleephRequestQuery::STATUS_ABANDONED,
154 'pulled' => ReleephRequestQuery::STATUS_PULLED,
155 'needs-revert' => ReleephRequestQuery::STATUS_NEEDS_REVERT,
156 'reverted' => ReleephRequestQuery::STATUS_REVERTED,
160 private function getSeverityOptions() {
161 if (ReleephDefaultFieldSelector::isFacebook()) {
162 return array(
163 '' => pht('(All Severities)'),
164 11 => pht('HOTFIX'),
165 12 => pht('PIGGYBACK'),
166 13 => pht('RELEASE'),
167 14 => pht('DAILY'),
168 15 => pht('PARKING'),
170 } else {
171 return array(
172 '' => pht('(All Severities)'),
173 ReleephSeverityFieldSpecification::HOTFIX => pht('Hotfix'),
174 ReleephSeverityFieldSpecification::RELEASE => pht('Release'),
179 protected function renderResultList(
180 array $requests,
181 PhabricatorSavedQuery $query,
182 array $handles) {
184 assert_instances_of($requests, 'ReleephRequest');
185 $viewer = $this->requireViewer();
187 // TODO: This is generally a bit sketchy, but we don't do this kind of
188 // thing elsewhere at the moment. For the moment it shouldn't be hugely
189 // costly, and we can batch things later. Generally, this commits fewer
190 // sins than the old code did.
192 $engine = id(new PhabricatorMarkupEngine())
193 ->setViewer($viewer);
195 $list = array();
196 foreach ($requests as $pull) {
197 $field_list = PhabricatorCustomField::getObjectFields(
198 $pull,
199 PhabricatorCustomField::ROLE_VIEW);
201 $field_list
202 ->setViewer($viewer)
203 ->readFieldsFromStorage($pull);
205 foreach ($field_list->getFields() as $field) {
206 if ($field->shouldMarkup()) {
207 $field->setMarkupEngine($engine);
211 $list[] = id(new ReleephRequestView())
212 ->setUser($viewer)
213 ->setCustomFields($field_list)
214 ->setPullRequest($pull)
215 ->setIsListView(true);
218 // This is quite sketchy, but the list has not actually rendered yet, so
219 // this still allows us to batch the markup rendering.
220 $engine->process();
222 return id(new PhabricatorApplicationSearchResultView())
223 ->setContent($list);