Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / drydock / query / DrydockLogQuery.php
blob80f47f584f2913b39f7873f5fec9039f41939a13
1 <?php
3 final class DrydockLogQuery extends DrydockQuery {
5 private $ids;
6 private $blueprintPHIDs;
7 private $resourcePHIDs;
8 private $leasePHIDs;
9 private $operationPHIDs;
11 public function withIDs(array $ids) {
12 $this->ids = $ids;
13 return $this;
16 public function withBlueprintPHIDs(array $phids) {
17 $this->blueprintPHIDs = $phids;
18 return $this;
21 public function withResourcePHIDs(array $phids) {
22 $this->resourcePHIDs = $phids;
23 return $this;
26 public function withLeasePHIDs(array $phids) {
27 $this->leasePHIDs = $phids;
28 return $this;
31 public function withOperationPHIDs(array $phids) {
32 $this->operationPHIDs = $phids;
33 return $this;
36 public function newResultObject() {
37 return new DrydockLog();
40 protected function loadPage() {
41 return $this->loadStandardPage($this->newResultObject());
44 protected function didFilterPage(array $logs) {
45 $blueprint_phids = array_filter(mpull($logs, 'getBlueprintPHID'));
46 if ($blueprint_phids) {
47 $blueprints = id(new DrydockBlueprintQuery())
48 ->setParentQuery($this)
49 ->setViewer($this->getViewer())
50 ->withPHIDs($blueprint_phids)
51 ->execute();
52 $blueprints = mpull($blueprints, null, 'getPHID');
53 } else {
54 $blueprints = array();
57 foreach ($logs as $key => $log) {
58 $blueprint = null;
59 $blueprint_phid = $log->getBlueprintPHID();
60 if ($blueprint_phid) {
61 $blueprint = idx($blueprints, $blueprint_phid);
63 $log->attachBlueprint($blueprint);
66 $resource_phids = array_filter(mpull($logs, 'getResourcePHID'));
67 if ($resource_phids) {
68 $resources = id(new DrydockResourceQuery())
69 ->setParentQuery($this)
70 ->setViewer($this->getViewer())
71 ->withPHIDs($resource_phids)
72 ->execute();
73 $resources = mpull($resources, null, 'getPHID');
74 } else {
75 $resources = array();
78 foreach ($logs as $key => $log) {
79 $resource = null;
80 $resource_phid = $log->getResourcePHID();
81 if ($resource_phid) {
82 $resource = idx($resources, $resource_phid);
84 $log->attachResource($resource);
87 $lease_phids = array_filter(mpull($logs, 'getLeasePHID'));
88 if ($lease_phids) {
89 $leases = id(new DrydockLeaseQuery())
90 ->setParentQuery($this)
91 ->setViewer($this->getViewer())
92 ->withPHIDs($lease_phids)
93 ->execute();
94 $leases = mpull($leases, null, 'getPHID');
95 } else {
96 $leases = array();
99 foreach ($logs as $key => $log) {
100 $lease = null;
101 $lease_phid = $log->getLeasePHID();
102 if ($lease_phid) {
103 $lease = idx($leases, $lease_phid);
105 $log->attachLease($lease);
108 $operation_phids = array_filter(mpull($logs, 'getOperationPHID'));
109 if ($operation_phids) {
110 $operations = id(new DrydockRepositoryOperationQuery())
111 ->setParentQuery($this)
112 ->setViewer($this->getViewer())
113 ->withPHIDs($operation_phids)
114 ->execute();
115 $operations = mpull($operations, null, 'getPHID');
116 } else {
117 $operations = array();
120 foreach ($logs as $key => $log) {
121 $operation = null;
122 $operation_phid = $log->getOperationPHID();
123 if ($operation_phid) {
124 $operation = idx($operations, $operation_phid);
126 $log->attachOperation($operation);
129 return $logs;
132 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
133 $where = parent::buildWhereClauseParts($conn);
135 if ($this->ids !== null) {
136 $where[] = qsprintf(
137 $conn,
138 'id IN (%Ls)',
139 $this->ids);
142 if ($this->blueprintPHIDs !== null) {
143 $where[] = qsprintf(
144 $conn,
145 'blueprintPHID IN (%Ls)',
146 $this->blueprintPHIDs);
149 if ($this->resourcePHIDs !== null) {
150 $where[] = qsprintf(
151 $conn,
152 'resourcePHID IN (%Ls)',
153 $this->resourcePHIDs);
156 if ($this->leasePHIDs !== null) {
157 $where[] = qsprintf(
158 $conn,
159 'leasePHID IN (%Ls)',
160 $this->leasePHIDs);
163 if ($this->operationPHIDs !== null) {
164 $where[] = qsprintf(
165 $conn,
166 'operationPHID IN (%Ls)',
167 $this->operationPHIDs);
170 return $where;