Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diviner/query/DivinerBookQuery.php
| <?php | <?php | ||||
| final class DivinerBookQuery extends PhabricatorCursorPagedPolicyAwareQuery { | final class DivinerBookQuery extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
| private $ids; | private $ids; | ||||
| private $phids; | private $phids; | ||||
| private $names; | private $names; | ||||
| 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 withNames(array $names) { | public function withNames(array $names) { | ||||
| $this->names = $names; | $this->names = $names; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function needProjectPHIDs($need_phids) { | |||||
| $this->needProjectPHIDs = $need_phids; | |||||
| return $this; | |||||
| } | |||||
| protected function loadPage() { | protected function loadPage() { | ||||
| $table = new DivinerLiveBook(); | $table = new DivinerLiveBook(); | ||||
| $conn_r = $table->establishConnection('r'); | $conn_r = $table->establishConnection('r'); | ||||
| $data = queryfx_all( | $data = queryfx_all( | ||||
| $conn_r, | $conn_r, | ||||
| 'SELECT * FROM %T %Q %Q %Q', | 'SELECT * FROM %T %Q %Q %Q', | ||||
| $table->getTableName(), | $table->getTableName(), | ||||
| $this->buildWhereClause($conn_r), | $this->buildWhereClause($conn_r), | ||||
| $this->buildOrderClause($conn_r), | $this->buildOrderClause($conn_r), | ||||
| $this->buildLimitClause($conn_r)); | $this->buildLimitClause($conn_r)); | ||||
| return $table->loadAllFromArray($data); | return $table->loadAllFromArray($data); | ||||
| } | } | ||||
| protected function didFilterPage(array $books) { | |||||
| assert_instances_of($books, 'DivinerLiveBook'); | |||||
| if ($this->needProjectPHIDs) { | |||||
| $edge_query = id(new PhabricatorEdgeQuery()) | |||||
| ->withSourcePHIDs(mpull($books, 'getPHID')) | |||||
| ->withEdgeTypes( | |||||
| array( | |||||
| PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, | |||||
| )); | |||||
| $edge_query->execute(); | |||||
| foreach ($books as $book) { | |||||
| $project_phids = $edge_query->getDestinationPHIDs( | |||||
| array( | |||||
| $book->getPHID(), | |||||
| )); | |||||
| $book->attachProjectPHIDs($project_phids); | |||||
| } | |||||
| } | |||||
| return $books; | |||||
| } | |||||
| protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { | protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { | ||||
| $where = array(); | $where = array(); | ||||
| if ($this->ids) { | if ($this->ids) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn_r, | ||||
| 'id IN (%Ld)', | 'id IN (%Ld)', | ||||
| $this->ids); | $this->ids); | ||||
| Show All 26 Lines | |||||