1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-28 17:52:43 +01:00
phorge-phorge/src/applications/releeph/query/ReleephRequestSearchEngine.php
Bob Trahan b902005bed Kill PhabricatorObjectDataHandle
Summary: Ref T603. Killing this class is cool because the classes that replace it are policy-aware. Tried to keep my wits about me as I did this and fixed a few random things along the way. (Ones I remember right now are pulling a query outside of a foreach loop in Releeph and fixing the text in UIExample to note that the ace of hearts if "a powerful" card and not the "most powerful" card (Q of spades gets that honor IMO))

Test Plan: tested the first few changes (execute, executeOne X handle, object) then got real mechanical / careful with the other changes.

Reviewers: epriestley

Reviewed By: epriestley

CC: Korvin, aran, FacebookPOC

Maniphest Tasks: T603

Differential Revision: https://secure.phabricator.com/D6941
2013-09-11 12:27:28 -07:00

172 lines
4.8 KiB
PHP

<?php
final class ReleephRequestSearchEngine
extends PhabricatorApplicationSearchEngine {
private $branch;
private $baseURI;
public function setBranch(ReleephBranch $branch) {
$this->branch = $branch;
return $this;
}
public function getBranch() {
return $this->branch;
}
public function setBaseURI($base_uri) {
$this->baseURI = $base_uri;
return $this;
}
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();
$saved->setParameter('status', $request->getStr('status'));
$saved->setParameter('severity', $request->getStr('severity'));
$saved->setParameter(
'requestorPHIDs',
$this->readUsersFromRequest($request, 'requestors'));
return $saved;
}
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new ReleephRequestQuery())
->withBranchIDs(array($this->getBranch()->getID()));
$status = $saved->getParameter('status');
$status = idx($this->getStatusValues(), $status);
if ($status) {
$query->withStatus($status);
}
$severity = $saved->getParameter('severity');
if ($severity) {
$query->withSeverities(array($severity));
}
$requestor_phids = $saved->getParameter('requestorPHIDs');
if ($requestor_phids) {
$query->withRequestorPHIDs($requestor_phids);
}
return $query;
}
public function buildSearchForm(
AphrontFormView $form,
PhabricatorSavedQuery $saved_query) {
$phids = $saved_query->getParameter('requestorPHIDs', array());
$handles = id(new PhabricatorHandleQuery())
->setViewer($this->requireViewer())
->withPHIDs($phids)
->execute();
$requestor_tokens = mpull($handles, 'getFullName', 'getPHID');
$form
->appendChild(
id(new AphrontFormSelectControl())
->setName('status')
->setLabel(pht('Status'))
->setValue($saved_query->getParameter('status'))
->setOptions($this->getStatusOptions()))
->appendChild(
id(new AphrontFormSelectControl())
->setName('severity')
->setLabel(pht('Severity'))
->setValue($saved_query->getParameter('severity'))
->setOptions($this->getSeverityOptions()))
->appendChild(
id(new AphrontFormTokenizerControl())
->setDatasource('/typeahead/common/users/')
->setName('requestors')
->setLabel(pht('Requestors'))
->setValue($requestor_tokens));
}
protected function getURI($path) {
return $this->baseURI.$path;
}
public function getBuiltinQueryNames() {
$names = array(
'open' => pht('Open Requests'),
'all' => pht('All Requests'),
);
if ($this->requireViewer()->isLoggedIn()) {
$names['requested'] = pht('Requested');
}
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'open':
return $query->setParameter('status', 'open');
case 'all':
return $query;
case 'requested':
return $query->setParameter(
'requestorPHIDs',
array($this->requireViewer()->getPHID()));
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
private function getStatusOptions() {
return array(
'' => pht('(All Requests)'),
'open' => pht('Open Requests'),
'requested' => pht('Pull Requested'),
'needs-pull' => pht('Needs Pull'),
'rejected' => pht('Rejected'),
'abandoned' => pht('Abandoned'),
'pulled' => pht('Pulled'),
'needs-revert' => pht('Needs Revert'),
'reverted' => pht('Reverted'),
);
}
private function getStatusValues() {
return array(
'open' => ReleephRequestQuery::STATUS_OPEN,
'requested' => ReleephRequestQuery::STATUS_REQUESTED,
'needs-pull' => ReleephRequestQuery::STATUS_NEEDS_PULL,
'rejected' => ReleephRequestQuery::STATUS_REJECTED,
'abandoned' => ReleephRequestQuery::STATUS_ABANDONED,
'pulled' => ReleephRequestQuery::STATUS_PULLED,
'needs-revert' => ReleephRequestQuery::STATUS_NEEDS_REVERT,
'reverted' => ReleephRequestQuery::STATUS_REVERTED,
);
}
private function getSeverityOptions() {
if (ReleephDefaultFieldSelector::isFacebook()) {
return array(
'' => pht('(All Severities)'),
11 => 'HOTFIX',
12 => 'PIGGYBACK',
13 => 'RELEASE',
14 => 'DAILY',
15 => 'PARKING',
);
} else {
return array(
'' => pht('(All Severities)'),
ReleephSeverityFieldSpecification::HOTFIX => pht('Hotfix'),
ReleephSeverityFieldSpecification::RELEASE => pht('Release'),
);
}
}
}