Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / drydock / query / DrydockRepositoryOperationQuery.php
bloba5fbe0acc982e12c4fd101c044082c52575b065c
1 <?php
3 final class DrydockRepositoryOperationQuery extends DrydockQuery {
5 private $ids;
6 private $phids;
7 private $objectPHIDs;
8 private $repositoryPHIDs;
9 private $operationStates;
10 private $operationTypes;
11 private $isDismissed;
12 private $authorPHIDs;
14 public function withIDs(array $ids) {
15 $this->ids = $ids;
16 return $this;
19 public function withPHIDs(array $phids) {
20 $this->phids = $phids;
21 return $this;
24 public function withObjectPHIDs(array $object_phids) {
25 $this->objectPHIDs = $object_phids;
26 return $this;
29 public function withRepositoryPHIDs(array $repository_phids) {
30 $this->repositoryPHIDs = $repository_phids;
31 return $this;
34 public function withOperationStates(array $states) {
35 $this->operationStates = $states;
36 return $this;
39 public function withOperationTypes(array $types) {
40 $this->operationTypes = $types;
41 return $this;
44 public function withIsDismissed($dismissed) {
45 $this->isDismissed = $dismissed;
46 return $this;
49 public function withAuthorPHIDs(array $phids) {
50 $this->authorPHIDs = $phids;
51 return $this;
54 public function newResultObject() {
55 return new DrydockRepositoryOperation();
58 protected function loadPage() {
59 return $this->loadStandardPage($this->newResultObject());
62 protected function willFilterPage(array $operations) {
63 $implementations = DrydockRepositoryOperationType::getAllOperationTypes();
65 $viewer = $this->getViewer();
67 foreach ($operations as $key => $operation) {
68 $impl = idx($implementations, $operation->getOperationType());
69 if (!$impl) {
70 $this->didRejectResult($operation);
71 unset($operations[$key]);
72 continue;
74 $impl = id(clone $impl)
75 ->setViewer($viewer)
76 ->setOperation($operation);
78 $operation->attachImplementation($impl);
81 $repository_phids = mpull($operations, 'getRepositoryPHID');
82 if ($repository_phids) {
83 $repositories = id(new PhabricatorRepositoryQuery())
84 ->setViewer($this->getViewer())
85 ->setParentQuery($this)
86 ->withPHIDs($repository_phids)
87 ->execute();
88 $repositories = mpull($repositories, null, 'getPHID');
89 } else {
90 $repositories = array();
93 foreach ($operations as $key => $operation) {
94 $repository = idx($repositories, $operation->getRepositoryPHID());
95 if (!$repository) {
96 $this->didRejectResult($operation);
97 unset($operations[$key]);
98 continue;
100 $operation->attachRepository($repository);
103 return $operations;
106 protected function didFilterPage(array $operations) {
107 $object_phids = mpull($operations, 'getObjectPHID');
108 if ($object_phids) {
109 $objects = id(new PhabricatorObjectQuery())
110 ->setViewer($this->getViewer())
111 ->setParentQuery($this)
112 ->withPHIDs($object_phids)
113 ->execute();
114 $objects = mpull($objects, null, 'getPHID');
115 } else {
116 $objects = array();
119 foreach ($operations as $key => $operation) {
120 $object = idx($objects, $operation->getObjectPHID());
121 $operation->attachObject($object);
124 return $operations;
127 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
128 $where = parent::buildWhereClauseParts($conn);
130 if ($this->ids !== null) {
131 $where[] = qsprintf(
132 $conn,
133 'id IN (%Ld)',
134 $this->ids);
137 if ($this->phids !== null) {
138 $where[] = qsprintf(
139 $conn,
140 'phid IN (%Ls)',
141 $this->phids);
144 if ($this->objectPHIDs !== null) {
145 $where[] = qsprintf(
146 $conn,
147 'objectPHID IN (%Ls)',
148 $this->objectPHIDs);
151 if ($this->repositoryPHIDs !== null) {
152 $where[] = qsprintf(
153 $conn,
154 'repositoryPHID IN (%Ls)',
155 $this->repositoryPHIDs);
158 if ($this->operationStates !== null) {
159 $where[] = qsprintf(
160 $conn,
161 'operationState IN (%Ls)',
162 $this->operationStates);
165 if ($this->operationTypes !== null) {
166 $where[] = qsprintf(
167 $conn,
168 'operationType IN (%Ls)',
169 $this->operationTypes);
172 if ($this->isDismissed !== null) {
173 $where[] = qsprintf(
174 $conn,
175 'isDismissed = %d',
176 (int)$this->isDismissed);
179 if ($this->authorPHIDs !== null) {
180 $where[] = qsprintf(
181 $conn,
182 'authorPHID IN (%Ls)',
183 $this->authorPHIDs);
186 return $where;