Page MenuHomePhorge

No OneTemporary

diff --git a/src/applications/fund/query/FundInitiativeQuery.php b/src/applications/fund/query/FundInitiativeQuery.php
index 9efbcfbf27..aeeb0942b9 100644
--- a/src/applications/fund/query/FundInitiativeQuery.php
+++ b/src/applications/fund/query/FundInitiativeQuery.php
@@ -1,107 +1,77 @@
<?php
final class FundInitiativeQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $phids;
private $ownerPHIDs;
private $statuses;
- private $needProjectPHIDs;
-
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withOwnerPHIDs(array $phids) {
$this->ownerPHIDs = $phids;
return $this;
}
public function withStatuses(array $statuses) {
$this->statuses = $statuses;
return $this;
}
- public function needProjectPHIDs($need) {
- $this->needProjectPHIDs = $need;
- return $this;
- }
-
public function newResultObject() {
return new FundInitiative();
}
protected function loadPage() {
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) {
$where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
$conn,
'phid IN (%Ls)',
$this->phids);
}
if ($this->ownerPHIDs !== null) {
$where[] = qsprintf(
$conn,
'ownerPHID IN (%Ls)',
$this->ownerPHIDs);
}
if ($this->statuses !== null) {
$where[] = qsprintf(
$conn,
'status IN (%Ls)',
$this->statuses);
}
return $where;
}
public function getQueryApplicationClass() {
return 'PhabricatorFundApplication';
}
}
diff --git a/src/applications/fund/query/FundInitiativeSearchEngine.php b/src/applications/fund/query/FundInitiativeSearchEngine.php
index 3c339c1a64..e075fe5063 100644
--- a/src/applications/fund/query/FundInitiativeSearchEngine.php
+++ b/src/applications/fund/query/FundInitiativeSearchEngine.php
@@ -1,176 +1,154 @@
<?php
final class FundInitiativeSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Fund Initiatives');
}
public function getApplicationClassName() {
return 'PhabricatorFundApplication';
}
- public function buildSavedQueryFromRequest(AphrontRequest $request) {
- $saved = new PhabricatorSavedQuery();
-
- $saved->setParameter(
- 'ownerPHIDs',
- $this->readUsersFromRequest($request, 'owners'));
-
- $saved->setParameter(
- 'statuses',
- $this->readListFromRequest($request, 'statuses'));
+ public function newQuery() {
+ return new FundInitiativeQuery();
+ }
- return $saved;
+ protected function buildCustomSearchFields() {
+ return array(
+ id(new PhabricatorUsersSearchField())
+ ->setKey('ownerPHIDs')
+ ->setAliases(array('owner', 'ownerPHID', 'owners'))
+ ->setLabel(pht('Owners')),
+ id(new PhabricatorSearchCheckboxesField())
+ ->setKey('statuses')
+ ->setLabel(pht('Statuses'))
+ ->setOptions(FundInitiative::getStatusNameMap()),
+ );
}
- public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
- $query = id(new FundInitiativeQuery())
- ->needProjectPHIDs(true);
+ protected function buildQueryFromParameters(array $map) {
+ $query = $this->newQuery();
- $owner_phids = $saved->getParameter('ownerPHIDs');
- if ($owner_phids) {
- $query->withOwnerPHIDs($owner_phids);
+ if ($map['ownerPHIDs']) {
+ $query->withOwnerPHIDs($map['ownerPHIDs']);
}
- $statuses = $saved->getParameter('statuses');
- if ($statuses) {
- $query->withStatuses($statuses);
+ if ($map['statuses']) {
+ $query->withStatuses($map['statuses']);
}
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) {
return '/fund/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array();
$names['open'] = pht('Open Initiatives');
if ($this->requireViewer()->isLoggedIn()) {
$names['owned'] = pht('Owned Initiatives');
}
$names['all'] = pht('All Initiatives');
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':
return $query;
case 'owned':
return $query->setParameter(
'ownerPHIDs',
array(
$this->requireViewer()->getPHID(),
));
case 'open':
return $query->setParameter(
'statuses',
array(
FundInitiative::STATUS_OPEN,
));
}
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(
array $initiatives,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($initiatives, 'FundInitiative');
$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) {
$owner_handle = $handles[$initiative->getOwnerPHID()];
$item = id(new PHUIObjectItemView())
->setObjectName($initiative->getMonogram())
->setHeader($initiative->getName())
->setHref('/'.$initiative->getMonogram())
->addByline(pht('Owner: %s', $owner_handle->renderLink()));
if ($initiative->isClosed()) {
$item->setDisabled(true);
}
- $project_handles = array_select_keys(
- $handles,
- $initiative->getProjectPHIDs());
+ $project_phids = $edge_query->getDestinationPHIDs(
+ array(
+ $initiative->getPHID(),
+ ));
+
+ $project_handles = array_select_keys($handles, $project_phids);
if ($project_handles) {
$item->addAttribute(
id(new PHUIHandleTagListView())
->setLimit(4)
->setSlim(true)
->setHandles($project_handles));
}
$list->addItem($item);
}
$result = new PhabricatorApplicationSearchResultView();
$result->setObjectList($list);
$result->setNoDataString(pht('No initiatives found.'));
return $result;
-
-
- return $list;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Sun, Jan 19, 13:02 (3 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1124867
Default Alt Text
(9 KB)

Event Timeline