Changeset View
Changeset View
Standalone View
Standalone View
src/applications/fund/query/FundInitiativeQuery.php
<?php | <?php | ||||
final class FundInitiativeQuery | final class FundInitiativeQuery | ||||
extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
private $ids; | private $ids; | ||||
private $phids; | private $phids; | ||||
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; | ||||
} | } | ||||
public function withPHIDs(array $phids) { | public function withPHIDs(array $phids) { | ||||
$this->phids = $phids; | $this->phids = $phids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withOwnerPHIDs(array $phids) { | public function withOwnerPHIDs(array $phids) { | ||||
$this->ownerPHIDs = $phids; | $this->ownerPHIDs = $phids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withStatuses(array $statuses) { | public function withStatuses(array $statuses) { | ||||
$this->statuses = $statuses; | $this->statuses = $statuses; | ||||
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(); | ||||
} | } | ||||
protected function loadPage() { | protected function loadPage() { | ||||
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); | ||||
if ($this->ids !== null) { | if ($this->ids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'id IN (%Ld)', | 'id IN (%Ld)', | ||||
$this->ids); | $this->ids); | ||||
Show All 31 Lines |