Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/query/AlmanacBindingQuery.php
Show All 28 Lines | public function withDevicePHIDs(array $phids) { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withInterfacePHIDs(array $phids) { | public function withInterfacePHIDs(array $phids) { | ||||
$this->interfacePHIDs = $phids; | $this->interfacePHIDs = $phids; | ||||
return $this; | return $this; | ||||
} | } | ||||
protected function loadPage() { | public function newResultObject() { | ||||
$table = new AlmanacBinding(); | return new AlmanacBinding(); | ||||
$conn_r = $table->establishConnection('r'); | } | ||||
$data = queryfx_all( | |||||
$conn_r, | |||||
'SELECT * FROM %T %Q %Q %Q', | |||||
$table->getTableName(), | |||||
$this->buildWhereClause($conn_r), | |||||
$this->buildOrderClause($conn_r), | |||||
$this->buildLimitClause($conn_r)); | |||||
return $table->loadAllFromArray($data); | protected function loadPage() { | ||||
return $this->loadStandardPage($this->newResultObject()); | |||||
} | } | ||||
protected function willFilterPage(array $bindings) { | protected function willFilterPage(array $bindings) { | ||||
$service_phids = mpull($bindings, 'getServicePHID'); | $service_phids = mpull($bindings, 'getServicePHID'); | ||||
$device_phids = mpull($bindings, 'getDevicePHID'); | $device_phids = mpull($bindings, 'getDevicePHID'); | ||||
$interface_phids = mpull($bindings, 'getInterfacePHID'); | $interface_phids = mpull($bindings, 'getInterfacePHID'); | ||||
$services = id(new AlmanacServiceQuery()) | $services = id(new AlmanacServiceQuery()) | ||||
->setParentQuery($this) | ->setParentQuery($this) | ||||
->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
->withPHIDs($service_phids) | ->withPHIDs($service_phids) | ||||
->needProperties($this->getNeedProperties()) | |||||
->execute(); | ->execute(); | ||||
$services = mpull($services, null, 'getPHID'); | $services = mpull($services, null, 'getPHID'); | ||||
$devices = id(new AlmanacDeviceQuery()) | $devices = id(new AlmanacDeviceQuery()) | ||||
->setParentQuery($this) | ->setParentQuery($this) | ||||
->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
->withPHIDs($device_phids) | ->withPHIDs($device_phids) | ||||
->needProperties($this->getNeedProperties()) | |||||
->execute(); | ->execute(); | ||||
$devices = mpull($devices, null, 'getPHID'); | $devices = mpull($devices, null, 'getPHID'); | ||||
$interfaces = id(new AlmanacInterfaceQuery()) | $interfaces = id(new AlmanacInterfaceQuery()) | ||||
->setParentQuery($this) | ->setParentQuery($this) | ||||
->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
->withPHIDs($interface_phids) | ->withPHIDs($interface_phids) | ||||
->needProperties($this->getNeedProperties()) | |||||
->execute(); | ->execute(); | ||||
$interfaces = mpull($interfaces, null, 'getPHID'); | $interfaces = mpull($interfaces, null, 'getPHID'); | ||||
foreach ($bindings as $key => $binding) { | foreach ($bindings as $key => $binding) { | ||||
$service = idx($services, $binding->getServicePHID()); | $service = idx($services, $binding->getServicePHID()); | ||||
$device = idx($devices, $binding->getDevicePHID()); | $device = idx($devices, $binding->getDevicePHID()); | ||||
$interface = idx($interfaces, $binding->getInterfacePHID()); | $interface = idx($interfaces, $binding->getInterfacePHID()); | ||||
if (!$service || !$device || !$interface) { | if (!$service || !$device || !$interface) { | ||||
$this->didRejectResult($binding); | $this->didRejectResult($binding); | ||||
unset($bindings[$key]); | unset($bindings[$key]); | ||||
continue; | continue; | ||||
} | } | ||||
$binding->attachService($service); | $binding->attachService($service); | ||||
$binding->attachDevice($device); | $binding->attachDevice($device); | ||||
$binding->attachInterface($interface); | $binding->attachInterface($interface); | ||||
} | } | ||||
return $bindings; | return $bindings; | ||||
} | } | ||||
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
$where = array(); | $where = parent::buildWhereClauseParts($conn); | ||||
if ($this->ids !== null) { | if ($this->ids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'id IN (%Ld)', | 'id IN (%Ld)', | ||||
$this->ids); | $this->ids); | ||||
} | } | ||||
if ($this->phids !== null) { | if ($this->phids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'phid IN (%Ls)', | 'phid IN (%Ls)', | ||||
$this->phids); | $this->phids); | ||||
} | } | ||||
if ($this->servicePHIDs !== null) { | if ($this->servicePHIDs !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'servicePHID IN (%Ls)', | 'servicePHID IN (%Ls)', | ||||
$this->servicePHIDs); | $this->servicePHIDs); | ||||
} | } | ||||
if ($this->devicePHIDs !== null) { | if ($this->devicePHIDs !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'devicePHID IN (%Ls)', | 'devicePHID IN (%Ls)', | ||||
$this->devicePHIDs); | $this->devicePHIDs); | ||||
} | } | ||||
if ($this->interfacePHIDs !== null) { | if ($this->interfacePHIDs !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'interfacePHID IN (%Ls)', | 'interfacePHID IN (%Ls)', | ||||
$this->interfacePHIDs); | $this->interfacePHIDs); | ||||
} | } | ||||
$where[] = $this->buildPagingClause($conn_r); | return $where; | ||||
return $this->formatWhereClause($where); | |||||
} | } | ||||
} | } |