mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-23 13:08:18 +01:00
Lightly modernize FundInitiativeSearchEngine
Summary: Ref T12819. Prepares for Ferret engine support. Test Plan: Queried for various initiatives. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12819 Differential Revision: https://secure.phabricator.com/D18554
This commit is contained in:
parent
60deec36d8
commit
cf0bc32e18
2 changed files with 51 additions and 103 deletions
|
@ -8,8 +8,6 @@ final class FundInitiativeQuery
|
||||||
private $ownerPHIDs;
|
private $ownerPHIDs;
|
||||||
private $statuses;
|
private $statuses;
|
||||||
|
|
||||||
private $needProjectPHIDs;
|
|
||||||
|
|
||||||
public function withIDs(array $ids) {
|
public function withIDs(array $ids) {
|
||||||
$this->ids = $ids;
|
$this->ids = $ids;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -30,11 +28,6 @@ final class FundInitiativeQuery
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function needProjectPHIDs($need) {
|
|
||||||
$this->needProjectPHIDs = $need;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function newResultObject() {
|
public function newResultObject() {
|
||||||
return new FundInitiative();
|
return new FundInitiative();
|
||||||
}
|
}
|
||||||
|
@ -43,29 +36,6 @@ final class FundInitiativeQuery
|
||||||
return $this->loadStandardPage($this->newResultObject());
|
return $this->loadStandardPage($this->newResultObject());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function didFilterPage(array $initiatives) {
|
|
||||||
|
|
||||||
if ($this->needProjectPHIDs) {
|
|
||||||
$edge_query = id(new PhabricatorEdgeQuery())
|
|
||||||
->withSourcePHIDs(mpull($initiatives, 'getPHID'))
|
|
||||||
->withEdgeTypes(
|
|
||||||
array(
|
|
||||||
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
|
|
||||||
));
|
|
||||||
$edge_query->execute();
|
|
||||||
|
|
||||||
foreach ($initiatives as $initiative) {
|
|
||||||
$phids = $edge_query->getDestinationPHIDs(
|
|
||||||
array(
|
|
||||||
$initiative->getPHID(),
|
|
||||||
));
|
|
||||||
$initiative->attachProjectPHIDs($phids);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $initiatives;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
||||||
$where = parent::buildWhereClauseParts($conn);
|
$where = parent::buildWhereClauseParts($conn);
|
||||||
|
|
||||||
|
|
|
@ -11,67 +11,37 @@ final class FundInitiativeSearchEngine
|
||||||
return 'PhabricatorFundApplication';
|
return 'PhabricatorFundApplication';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
public function newQuery() {
|
||||||
$saved = new PhabricatorSavedQuery();
|
return new FundInitiativeQuery();
|
||||||
|
|
||||||
$saved->setParameter(
|
|
||||||
'ownerPHIDs',
|
|
||||||
$this->readUsersFromRequest($request, 'owners'));
|
|
||||||
|
|
||||||
$saved->setParameter(
|
|
||||||
'statuses',
|
|
||||||
$this->readListFromRequest($request, 'statuses'));
|
|
||||||
|
|
||||||
return $saved;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
protected function buildCustomSearchFields() {
|
||||||
$query = id(new FundInitiativeQuery())
|
return array(
|
||||||
->needProjectPHIDs(true);
|
id(new PhabricatorUsersSearchField())
|
||||||
|
->setKey('ownerPHIDs')
|
||||||
|
->setAliases(array('owner', 'ownerPHID', 'owners'))
|
||||||
|
->setLabel(pht('Owners')),
|
||||||
|
id(new PhabricatorSearchCheckboxesField())
|
||||||
|
->setKey('statuses')
|
||||||
|
->setLabel(pht('Statuses'))
|
||||||
|
->setOptions(FundInitiative::getStatusNameMap()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$owner_phids = $saved->getParameter('ownerPHIDs');
|
protected function buildQueryFromParameters(array $map) {
|
||||||
if ($owner_phids) {
|
$query = $this->newQuery();
|
||||||
$query->withOwnerPHIDs($owner_phids);
|
|
||||||
|
if ($map['ownerPHIDs']) {
|
||||||
|
$query->withOwnerPHIDs($map['ownerPHIDs']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$statuses = $saved->getParameter('statuses');
|
if ($map['statuses']) {
|
||||||
if ($statuses) {
|
$query->withStatuses($map['statuses']);
|
||||||
$query->withStatuses($statuses);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildSearchForm(
|
|
||||||
AphrontFormView $form,
|
|
||||||
PhabricatorSavedQuery $saved) {
|
|
||||||
|
|
||||||
$statuses = $saved->getParameter('statuses', array());
|
|
||||||
$statuses = array_fuse($statuses);
|
|
||||||
|
|
||||||
$owner_phids = $saved->getParameter('ownerPHIDs', array());
|
|
||||||
|
|
||||||
$status_map = FundInitiative::getStatusNameMap();
|
|
||||||
$status_control = id(new AphrontFormCheckboxControl())
|
|
||||||
->setLabel(pht('Statuses'));
|
|
||||||
foreach ($status_map as $status => $name) {
|
|
||||||
$status_control->addCheckbox(
|
|
||||||
'statuses[]',
|
|
||||||
$status,
|
|
||||||
$name,
|
|
||||||
isset($statuses[$status]));
|
|
||||||
}
|
|
||||||
|
|
||||||
$form
|
|
||||||
->appendControl(
|
|
||||||
id(new AphrontFormTokenizerControl())
|
|
||||||
->setLabel(pht('Owners'))
|
|
||||||
->setName('owners')
|
|
||||||
->setDatasource(new PhabricatorPeopleDatasource())
|
|
||||||
->setValue($owner_phids))
|
|
||||||
->appendChild($status_control);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getURI($path) {
|
protected function getURI($path) {
|
||||||
return '/fund/'.$path;
|
return '/fund/'.$path;
|
||||||
}
|
}
|
||||||
|
@ -112,21 +82,6 @@ final class FundInitiativeSearchEngine
|
||||||
return parent::buildSavedQueryFromBuiltin($query_key);
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getRequiredHandlePHIDsForResultList(
|
|
||||||
array $initiatives,
|
|
||||||
PhabricatorSavedQuery $query) {
|
|
||||||
|
|
||||||
$phids = array();
|
|
||||||
foreach ($initiatives as $initiative) {
|
|
||||||
$phids[] = $initiative->getOwnerPHID();
|
|
||||||
foreach ($initiative->getProjectPHIDs() as $project_phid) {
|
|
||||||
$phids[] = $project_phid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $phids;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function renderResultList(
|
protected function renderResultList(
|
||||||
array $initiatives,
|
array $initiatives,
|
||||||
PhabricatorSavedQuery $query,
|
PhabricatorSavedQuery $query,
|
||||||
|
@ -135,7 +90,30 @@ final class FundInitiativeSearchEngine
|
||||||
|
|
||||||
$viewer = $this->requireViewer();
|
$viewer = $this->requireViewer();
|
||||||
|
|
||||||
$list = id(new PHUIObjectItemListView());
|
$load_phids = array();
|
||||||
|
foreach ($initiatives as $initiative) {
|
||||||
|
$load_phids[] = $initiative->getOwnerPHID();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($initiatives) {
|
||||||
|
$edge_query = id(new PhabricatorEdgeQuery())
|
||||||
|
->withSourcePHIDs(mpull($initiatives, 'getPHID'))
|
||||||
|
->withEdgeTypes(
|
||||||
|
array(
|
||||||
|
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
|
||||||
|
));
|
||||||
|
|
||||||
|
$edge_query->execute();
|
||||||
|
|
||||||
|
foreach ($edge_query->getDestinationPHIDs() as $phid) {
|
||||||
|
$load_phids[] = $phid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$handles = $viewer->loadHandles($load_phids);
|
||||||
|
$handles = iterator_to_array($handles);
|
||||||
|
|
||||||
|
$list = new PHUIObjectItemListView();
|
||||||
foreach ($initiatives as $initiative) {
|
foreach ($initiatives as $initiative) {
|
||||||
$owner_handle = $handles[$initiative->getOwnerPHID()];
|
$owner_handle = $handles[$initiative->getOwnerPHID()];
|
||||||
|
|
||||||
|
@ -149,9 +127,12 @@ final class FundInitiativeSearchEngine
|
||||||
$item->setDisabled(true);
|
$item->setDisabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$project_handles = array_select_keys(
|
$project_phids = $edge_query->getDestinationPHIDs(
|
||||||
$handles,
|
array(
|
||||||
$initiative->getProjectPHIDs());
|
$initiative->getPHID(),
|
||||||
|
));
|
||||||
|
|
||||||
|
$project_handles = array_select_keys($handles, $project_phids);
|
||||||
if ($project_handles) {
|
if ($project_handles) {
|
||||||
$item->addAttribute(
|
$item->addAttribute(
|
||||||
id(new PHUIHandleTagListView())
|
id(new PHUIHandleTagListView())
|
||||||
|
@ -168,9 +149,6 @@ final class FundInitiativeSearchEngine
|
||||||
$result->setNoDataString(pht('No initiatives found.'));
|
$result->setNoDataString(pht('No initiatives found.'));
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|
||||||
|
|
||||||
return $list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue