Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/query/AlmanacBindingQuery.php
<?php | <?php | ||||
final class AlmanacBindingQuery | final class AlmanacBindingQuery | ||||
extends AlmanacQuery { | extends AlmanacQuery { | ||||
private $ids; | private $ids; | ||||
private $phids; | private $phids; | ||||
private $servicePHIDs; | private $servicePHIDs; | ||||
private $devicePHIDs; | private $devicePHIDs; | ||||
private $interfacePHIDs; | private $interfacePHIDs; | ||||
private $isActive; | |||||
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 10 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; | ||||
} | } | ||||
public function withIsActive($active) { | |||||
$this->isActive = $active; | |||||
return $this; | |||||
} | |||||
public function newResultObject() { | public function newResultObject() { | ||||
return new AlmanacBinding(); | return new AlmanacBinding(); | ||||
} | } | ||||
protected function loadPage() { | protected function loadPage() { | ||||
return $this->loadStandardPage($this->newResultObject()); | return $this->loadStandardPage($this->newResultObject()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | final class AlmanacBindingQuery | ||||
} | } | ||||
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
$where = parent::buildWhereClauseParts($conn); | $where = parent::buildWhereClauseParts($conn); | ||||
if ($this->ids !== null) { | if ($this->ids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'id IN (%Ld)', | 'binding.id IN (%Ld)', | ||||
$this->ids); | $this->ids); | ||||
} | } | ||||
if ($this->phids !== null) { | if ($this->phids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'phid IN (%Ls)', | 'binding.phid IN (%Ls)', | ||||
$this->phids); | $this->phids); | ||||
} | } | ||||
if ($this->servicePHIDs !== null) { | if ($this->servicePHIDs !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'servicePHID IN (%Ls)', | 'binding.servicePHID IN (%Ls)', | ||||
$this->servicePHIDs); | $this->servicePHIDs); | ||||
} | } | ||||
if ($this->devicePHIDs !== null) { | if ($this->devicePHIDs !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'devicePHID IN (%Ls)', | 'binding.devicePHID IN (%Ls)', | ||||
$this->devicePHIDs); | $this->devicePHIDs); | ||||
} | } | ||||
if ($this->interfacePHIDs !== null) { | if ($this->interfacePHIDs !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'interfacePHID IN (%Ls)', | 'binding.interfacePHID IN (%Ls)', | ||||
$this->interfacePHIDs); | $this->interfacePHIDs); | ||||
} | } | ||||
if ($this->isActive !== null) { | |||||
if ($this->isActive) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'(binding.isDisabled = 0) AND (device.status IN (%Ls))', | |||||
AlmanacDeviceStatus::getActiveStatusList()); | |||||
} else { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'(binding.isDisabled = 1) OR (device.status IN (%Ls))', | |||||
AlmanacDeviceStatus::getDisabledStatusList()); | |||||
} | |||||
} | |||||
return $where; | return $where; | ||||
} | } | ||||
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { | |||||
$joins = parent::buildJoinClauseParts($conn); | |||||
if ($this->shouldJoinDeviceTable()) { | |||||
$device_table = new AlmanacDevice(); | |||||
$joins[] = qsprintf( | |||||
$conn, | |||||
'JOIN %R device ON binding.devicePHID = device.phid', | |||||
$device_table); | |||||
} | |||||
return $joins; | |||||
} | |||||
private function shouldJoinDeviceTable() { | |||||
if ($this->isActive !== null) { | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
protected function getPrimaryTableAlias() { | |||||
return 'binding'; | |||||
} | |||||
} | } |