Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/query/AlmanacDevicePropertyQuery.php
- This file was added.
<?php | |||||
final class AlmanacDevicePropertyQuery | |||||
extends PhabricatorCursorPagedPolicyAwareQuery { | |||||
private $keys; | |||||
private $devicePHIDs; | |||||
public function withKeys(array $keys) { | |||||
$this->keys = $keys; | |||||
return $this; | |||||
} | |||||
public function withDevicePHIDs(array $device_phids) { | |||||
$this->devicePHIDs = $device_phids; | |||||
return $this; | |||||
} | |||||
protected function loadPage() { | |||||
$table = new AlmanacDeviceProperty(); | |||||
$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 buildWhereClause($conn_r) { | |||||
$where = array(); | |||||
if ($this->keys !== null) { | |||||
$where[] = qsprintf( | |||||
$conn_r, | |||||
'`key` IN (%Ls)', | |||||
$this->keys); | |||||
} | |||||
if ($this->devicePHIDs !== null) { | |||||
$where[] = qsprintf( | |||||
$conn_r, | |||||
'devicePHIDs IN (%Ls)', | |||||
$this->devicePHIDs); | |||||
} | |||||
$where[] = $this->buildPagingClause($conn_r); | |||||
return $this->formatWhereClause($where); | |||||
} | |||||
public function getQueryApplicationClass() { | |||||
return 'PhabricatorAlmanacApplication'; | |||||
} | |||||
} |