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 $nameLike; | private $nameLike; | ||||
| private $namePrefix; | private $namePrefix; | ||||
| private $repositoryPHIDs; | private $repositoryPHIDs; | ||||
| private $isArchived; | |||||
| private $needProjectPHIDs; | private $needProjectPHIDs; | ||||
| private $needRepositories; | private $needRepositories; | ||||
| public function withIDs(array $ids) { | public function withIDs(array $ids) { | ||||
| $this->ids = $ids; | $this->ids = $ids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| Show All 18 Lines | public function withNamePrefix($prefix) { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withRepositoryPHIDs(array $repository_phids) { | public function withRepositoryPHIDs(array $repository_phids) { | ||||
| $this->repositoryPHIDs = $repository_phids; | $this->repositoryPHIDs = $repository_phids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withIsArchived($is_archived) { | |||||
| $this->isArchived = $is_archived; | |||||
| return $this; | |||||
| } | |||||
| public function needProjectPHIDs($need_phids) { | public function needProjectPHIDs($need_phids) { | ||||
| $this->needProjectPHIDs = $need_phids; | $this->needProjectPHIDs = $need_phids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function needRepositories($need_repositories) { | public function needRepositories($need_repositories) { | ||||
| $this->needRepositories = $need_repositories; | $this->needRepositories = $need_repositories; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| protected function loadPage() { | protected function loadPage() { | ||||
| $table = new DivinerLiveBook(); | return $this->loadStandardPage(new DivinerLiveBook()); | ||||
| $conn_r = $table->establishConnection('r'); | |||||
| $data = queryfx_all( | |||||
| $conn_r, | |||||
| 'SELECT * FROM %T %Q %Q %Q', | |||||
| $table->getTableName(), | |||||
| $this->buildWhereClause($conn_r), | |||||
| $this->buildOrderClause($conn_r), | |||||
| $this->buildLimitClause($conn_r)); | |||||
| return $table->loadAllFromArray($data); | |||||
| } | } | ||||
| protected function didFilterPage(array $books) { | protected function didFilterPage(array $books) { | ||||
| assert_instances_of($books, 'DivinerLiveBook'); | assert_instances_of($books, 'DivinerLiveBook'); | ||||
| if ($this->needRepositories) { | if ($this->needRepositories) { | ||||
| $repositories = id(new PhabricatorRepositoryQuery()) | $repositories = id(new PhabricatorRepositoryQuery()) | ||||
| ->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
| Show All 35 Lines | if ($this->needProjectPHIDs) { | ||||
| )); | )); | ||||
| $book->attachProjectPHIDs($project_phids); | $book->attachProjectPHIDs($project_phids); | ||||
| } | } | ||||
| } | } | ||||
| return $books; | return $books; | ||||
| } | } | ||||
| protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
| $where = array(); | $where = parent::buildWhereClauseParts($conn); | ||||
| if ($this->ids) { | if ($this->ids) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'id IN (%Ld)', | 'id IN (%Ld)', | ||||
| $this->ids); | $this->ids); | ||||
| } | } | ||||
| if ($this->phids) { | if ($this->phids) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'phid IN (%Ls)', | 'phid IN (%Ls)', | ||||
| $this->phids); | $this->phids); | ||||
| } | } | ||||
| if (strlen($this->nameLike)) { | if (strlen($this->nameLike)) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'name LIKE %~', | 'name LIKE %~', | ||||
| $this->nameLike); | $this->nameLike); | ||||
| } | } | ||||
| if ($this->names !== null) { | if ($this->names !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'name IN (%Ls)', | 'name IN (%Ls)', | ||||
| $this->names); | $this->names); | ||||
| } | } | ||||
| if (strlen($this->namePrefix)) { | if (strlen($this->namePrefix)) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'name LIKE %>', | 'name LIKE %>', | ||||
| $this->namePrefix); | $this->namePrefix); | ||||
| } | } | ||||
| if ($this->repositoryPHIDs !== null) { | if ($this->repositoryPHIDs !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'repositoryPHID IN (%Ls)', | 'repositoryPHID IN (%Ls)', | ||||
| $this->repositoryPHIDs); | $this->repositoryPHIDs); | ||||
| } | } | ||||
| $where[] = $this->buildPagingClause($conn_r); | if ($this->isArchived !== null) { | ||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'isArchived = %d', | |||||
| (int)$this->isArchived); | |||||
joshuaspence: This doesn't feel right to me | |||||
| } | |||||
| $where[] = $this->buildPagingClause($conn); | |||||
| return $this->formatWhereClause($where); | return $where; | ||||
| } | } | ||||
| public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
| return 'PhabricatorDivinerApplication'; | return 'PhabricatorDivinerApplication'; | ||||
| } | } | ||||
| public function getOrderableColumns() { | public function getOrderableColumns() { | ||||
| return parent::getOrderableColumns() + array( | return parent::getOrderableColumns() + array( | ||||
| Show All 27 Lines | |||||
This doesn't feel right to me