Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/query/AlmanacServiceQuery.php
| <?php | <?php | ||||
| final class AlmanacServiceQuery | final class AlmanacServiceQuery | ||||
| extends AlmanacQuery { | extends AlmanacQuery { | ||||
| private $ids; | private $ids; | ||||
| private $phids; | private $phids; | ||||
| private $names; | private $names; | ||||
| private $needBindings; | |||||
| 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 withNames(array $names) { | public function withNames(array $names) { | ||||
| $this->names = $names; | $this->names = $names; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function needBindings($need_bindings) { | |||||
| $this->needBindings = $need_bindings; | |||||
| return $this; | |||||
| } | |||||
| protected function loadPage() { | protected function loadPage() { | ||||
| $table = new AlmanacService(); | $table = new AlmanacService(); | ||||
| $conn_r = $table->establishConnection('r'); | $conn_r = $table->establishConnection('r'); | ||||
| $data = queryfx_all( | $data = queryfx_all( | ||||
| $conn_r, | $conn_r, | ||||
| 'SELECT * FROM %T %Q %Q %Q', | 'SELECT * FROM %T %Q %Q %Q', | ||||
| $table->getTableName(), | $table->getTableName(), | ||||
| Show All 33 Lines | if ($this->names !== null) { | ||||
| $hashes); | $hashes); | ||||
| } | } | ||||
| $where[] = $this->buildPagingClause($conn_r); | $where[] = $this->buildPagingClause($conn_r); | ||||
| return $this->formatWhereClause($where); | return $this->formatWhereClause($where); | ||||
| } | } | ||||
| protected function didFilterPage(array $services) { | |||||
| if ($this->needBindings) { | |||||
| $service_phids = mpull($services, 'getPHID'); | |||||
| $bindings = id(new AlmanacBindingQuery()) | |||||
| ->setViewer($this->getViewer()) | |||||
| ->withServicePHIDs($service_phids) | |||||
| ->execute(); | |||||
| $bindings = mgroup($bindings, 'getServicePHID'); | |||||
| foreach ($services as $service) { | |||||
| $service_bindings = idx($bindings, $service->getPHID(), array()); | |||||
| $service->attachBindings($service_bindings); | |||||
| } | |||||
| } | |||||
| return parent::didFilterPage($services); | |||||
| } | |||||
| } | } | ||||