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 $serviceTypes; | private $serviceTypes; | ||||
private $devicePHIDs; | private $devicePHIDs; | ||||
private $namePrefix; | private $namePrefix; | ||||
private $nameSuffix; | private $nameSuffix; | ||||
private $needBindings; | private $needBindings; | ||||
private $needActiveBindings; | |||||
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; | ||||
Show All 31 Lines | return $this->withNgramsConstraint( | ||||
$ngrams); | $ngrams); | ||||
} | } | ||||
public function needBindings($need_bindings) { | public function needBindings($need_bindings) { | ||||
$this->needBindings = $need_bindings; | $this->needBindings = $need_bindings; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function needActiveBindings($need_active) { | |||||
$this->needActiveBindings = $need_active; | |||||
return $this; | |||||
} | |||||
public function newResultObject() { | public function newResultObject() { | ||||
return new AlmanacService(); | return new AlmanacService(); | ||||
} | } | ||||
protected function loadPage() { | protected function loadPage() { | ||||
return $this->loadStandardPage($this->newResultObject()); | return $this->loadStandardPage($this->newResultObject()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | foreach ($services as $key => $service) { | ||||
$implementation = clone $implementation; | $implementation = clone $implementation; | ||||
$service->attachServiceImplementation($implementation); | $service->attachServiceImplementation($implementation); | ||||
} | } | ||||
return $services; | return $services; | ||||
} | } | ||||
protected function didFilterPage(array $services) { | protected function didFilterPage(array $services) { | ||||
if ($this->needBindings) { | $need_all = $this->needBindings; | ||||
$need_active = $this->needActiveBindings; | |||||
$need_any = ($need_all || $need_active); | |||||
$only_active = ($need_active && !$need_all); | |||||
if ($need_any) { | |||||
$service_phids = mpull($services, 'getPHID'); | $service_phids = mpull($services, 'getPHID'); | ||||
$bindings = id(new AlmanacBindingQuery()) | |||||
$bindings_query = id(new AlmanacBindingQuery()) | |||||
->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
->withServicePHIDs($service_phids) | ->withServicePHIDs($service_phids) | ||||
->needProperties($this->getNeedProperties()) | ->needProperties($this->getNeedProperties()); | ||||
->execute(); | |||||
if ($only_active) { | |||||
$bindings_query->withIsActive(true); | |||||
} | |||||
$bindings = $bindings_query->execute(); | |||||
$bindings = mgroup($bindings, 'getServicePHID'); | $bindings = mgroup($bindings, 'getServicePHID'); | ||||
foreach ($services as $service) { | foreach ($services as $service) { | ||||
$service_bindings = idx($bindings, $service->getPHID(), array()); | $service_bindings = idx($bindings, $service->getPHID(), array()); | ||||
if ($only_active) { | |||||
$service->attachActiveBindings($service_bindings); | |||||
} else { | |||||
$service->attachBindings($service_bindings); | $service->attachBindings($service_bindings); | ||||
} | } | ||||
} | } | ||||
} | |||||
return parent::didFilterPage($services); | return parent::didFilterPage($services); | ||||
} | } | ||||
private function shouldJoinBindingTable() { | private function shouldJoinBindingTable() { | ||||
return ($this->devicePHIDs !== null); | return ($this->devicePHIDs !== null); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |