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 $namePrefix; | |||||
| private $repositoryPHIDs; | private $repositoryPHIDs; | ||||
| 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; | ||||
| } | } | ||||
| public function withPHIDs(array $phids) { | public function withPHIDs(array $phids) { | ||||
| $this->phids = $phids; | $this->phids = $phids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withNameLike($name) { | |||||
| $this->nameLike = $name; | |||||
| return $this; | |||||
| } | |||||
| public function withNames(array $names) { | public function withNames(array $names) { | ||||
| $this->names = $names; | $this->names = $names; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withNamePrefix($prefix) { | |||||
| $this->namePrefix = $prefix; | |||||
| 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 needProjectPHIDs($need_phids) { | public function needProjectPHIDs($need_phids) { | ||||
| $this->needProjectPHIDs = $need_phids; | $this->needProjectPHIDs = $need_phids; | ||||
| return $this; | return $this; | ||||
| ▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { | ||||
| if ($this->phids) { | if ($this->phids) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn_r, | ||||
| 'phid IN (%Ls)', | 'phid IN (%Ls)', | ||||
| $this->phids); | $this->phids); | ||||
| } | } | ||||
| if ($this->names) { | if (strlen($this->nameLike)) { | ||||
| $where[] = qsprintf( | |||||
| $conn_r, | |||||
| 'name LIKE %~', | |||||
| $this->nameLike); | |||||
| } | |||||
| if ($this->names !== null) { | |||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn_r, | ||||
| 'name IN (%Ls)', | 'name IN (%Ls)', | ||||
| $this->names); | $this->names); | ||||
| } | } | ||||
| if (strlen($this->namePrefix)) { | |||||
| $where[] = qsprintf( | |||||
| $conn_r, | |||||
| 'name LIKE %>', | |||||
| $this->namePrefix); | |||||
| } | |||||
| if ($this->repositoryPHIDs !== null) { | if ($this->repositoryPHIDs !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn_r, | ||||
| 'repositoryPHID IN (%Ls)', | 'repositoryPHID IN (%Ls)', | ||||
| $this->repositoryPHIDs); | $this->repositoryPHIDs); | ||||
| } | } | ||||
| $where[] = $this->buildPagingClause($conn_r); | $where[] = $this->buildPagingClause($conn_r); | ||||
| return $this->formatWhereClause($where); | return $this->formatWhereClause($where); | ||||
| } | } | ||||
| public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
| return 'PhabricatorDivinerApplication'; | return 'PhabricatorDivinerApplication'; | ||||
| } | } | ||||
| public function getOrderableColumns() { | |||||
| return parent::getOrderableColumns() + array( | |||||
| 'name' => array( | |||||
| 'column' => 'name', | |||||
| 'type' => 'string', | |||||
| 'reverse' => true, | |||||
| 'unique' => true, | |||||
| ), | |||||
| ); | |||||
| } | |||||
| protected function getPagingValueMap($cursor, array $keys) { | |||||
| $book = $this->loadCursorObject($cursor); | |||||
| return array( | |||||
| 'name' => $book->getName(), | |||||
| ); | |||||
| } | |||||
| public function getBuiltinOrders() { | |||||
epriestley: This is maybe a little confusing because `name` can be `zebrafacts` ("Z") and the title can be… | |||||
| return array( | |||||
| 'name' => array( | |||||
| 'vector' => array('name'), | |||||
| 'name' => pht('Name'), | |||||
| ), | |||||
| ) + parent::getBuiltinOrders(); | |||||
| } | |||||
| } | } | ||||
This is maybe a little confusing because name can be zebrafacts ("Z") and the title can be A Collection of Fine Facts about Zebras ("A" or "C", depending on how smart we want to be), which puts the book at totally separate ends of the list.
Ideally we would probably define a sortableTitle column, strip common articles ("A", "An", "The") in some central algorithm, dump the rest of the title in there in a normalized form, then sort by that.
This can happen some time far in the future, though.