Remove product literal strings in "pht()", part 25
[phabricator.git] / src / applications / releeph / query / ReleephProductQuery.php
blob118b9919a84671aacb4f8013efa6131eb4e0e140
1 <?php
3 final class ReleephProductQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $active;
7 private $ids;
8 private $phids;
9 private $repositoryPHIDs;
11 const ORDER_ID = 'order-id';
12 const ORDER_NAME = 'order-name';
14 public function withActive($active) {
15 $this->active = $active;
16 return $this;
19 public function setOrder($order) {
20 switch ($order) {
21 case self::ORDER_ID:
22 $this->setOrderVector(array('id'));
23 break;
24 case self::ORDER_NAME:
25 $this->setOrderVector(array('name'));
26 break;
27 default:
28 throw new Exception(pht('Order "%s" not supported.', $order));
30 return $this;
33 public function withIDs(array $ids) {
34 $this->ids = $ids;
35 return $this;
38 public function withPHIDs(array $phids) {
39 $this->phids = $phids;
40 return $this;
43 public function withRepositoryPHIDs(array $repository_phids) {
44 $this->repositoryPHIDs = $repository_phids;
45 return $this;
48 protected function loadPage() {
49 $table = new ReleephProject();
50 $conn_r = $table->establishConnection('r');
52 $rows = queryfx_all(
53 $conn_r,
54 'SELECT * FROM %T %Q %Q %Q',
55 $table->getTableName(),
56 $this->buildWhereClause($conn_r),
57 $this->buildOrderClause($conn_r),
58 $this->buildLimitClause($conn_r));
60 return $table->loadAllFromArray($rows);
63 protected function willFilterPage(array $projects) {
64 assert_instances_of($projects, 'ReleephProject');
66 $repository_phids = mpull($projects, 'getRepositoryPHID');
68 $repositories = id(new PhabricatorRepositoryQuery())
69 ->setViewer($this->getViewer())
70 ->withPHIDs($repository_phids)
71 ->execute();
72 $repositories = mpull($repositories, null, 'getPHID');
74 foreach ($projects as $key => $project) {
75 $repo = idx($repositories, $project->getRepositoryPHID());
76 if (!$repo) {
77 unset($projects[$key]);
78 continue;
80 $project->attachRepository($repo);
83 return $projects;
86 protected function buildWhereClause(AphrontDatabaseConnection $conn) {
87 $where = array();
89 if ($this->active !== null) {
90 $where[] = qsprintf(
91 $conn,
92 'isActive = %d',
93 (int)$this->active);
96 if ($this->ids !== null) {
97 $where[] = qsprintf(
98 $conn,
99 'id IN (%Ls)',
100 $this->ids);
103 if ($this->phids !== null) {
104 $where[] = qsprintf(
105 $conn,
106 'phid IN (%Ls)',
107 $this->phids);
110 if ($this->repositoryPHIDs !== null) {
111 $where[] = qsprintf(
112 $conn,
113 'repositoryPHID IN (%Ls)',
114 $this->repositoryPHIDs);
117 $where[] = $this->buildPagingClause($conn);
119 return $this->formatWhereClause($conn, $where);
122 public function getOrderableColumns() {
123 return parent::getOrderableColumns() + array(
124 'name' => array(
125 'column' => 'name',
126 'unique' => true,
127 'reverse' => true,
128 'type' => 'string',
133 protected function newPagingMapFromPartialObject($object) {
134 return array(
135 'id' => (int)$object->getID(),
136 'name' => $object->getName(),
140 public function getQueryApplicationClass() {
141 return 'PhabricatorReleephApplication';