Changeset View
Changeset View
Standalone View
Standalone View
src/applications/almanac/query/AlmanacDeviceQuery.php
Show All 28 Lines | public function withNamePrefix($prefix) { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withNameSuffix($suffix) { | public function withNameSuffix($suffix) { | ||||
$this->nameSuffix = $suffix; | $this->nameSuffix = $suffix; | ||||
return $this; | return $this; | ||||
} | } | ||||
protected function loadPage() { | public function withNameNgrams($ngrams) { | ||||
$table = new AlmanacDevice(); | return $this->withNgramsConstraint( | ||||
$conn_r = $table->establishConnection('r'); | new AlmanacDeviceNameNgrams(), | ||||
$ngrams); | |||||
} | |||||
$data = queryfx_all( | public function newResultObject() { | ||||
$conn_r, | return new AlmanacDevice(); | ||||
'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 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)', | 'device.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)', | 'device.phid IN (%Ls)', | ||||
$this->phids); | $this->phids); | ||||
} | } | ||||
if ($this->names !== null) { | if ($this->names !== null) { | ||||
$hashes = array(); | $hashes = array(); | ||||
foreach ($this->names as $name) { | foreach ($this->names as $name) { | ||||
$hashes[] = PhabricatorHash::digestForIndex($name); | $hashes[] = PhabricatorHash::digestForIndex($name); | ||||
} | } | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'nameIndex IN (%Ls)', | 'device.nameIndex IN (%Ls)', | ||||
$hashes); | $hashes); | ||||
} | } | ||||
if ($this->namePrefix !== null) { | if ($this->namePrefix !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'name LIKE %>', | 'device.name LIKE %>', | ||||
$this->namePrefix); | $this->namePrefix); | ||||
} | } | ||||
if ($this->nameSuffix !== null) { | if ($this->nameSuffix !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn_r, | $conn, | ||||
'name LIKE %<', | 'device.name LIKE %<', | ||||
$this->nameSuffix); | $this->nameSuffix); | ||||
} | } | ||||
$where[] = $this->buildPagingClause($conn_r); | return $where; | ||||
} | |||||
protected function getPrimaryTableAlias() { | |||||
return 'device'; | |||||
} | |||||
return $this->formatWhereClause($where); | public function getOrderableColumns() { | ||||
return parent::getOrderableColumns() + array( | |||||
'name' => array( | |||||
'table' => $this->getPrimaryTableAlias(), | |||||
'column' => 'name', | |||||
'type' => 'string', | |||||
'unique' => true, | |||||
'reverse' => true, | |||||
), | |||||
); | |||||
} | |||||
protected function getPagingValueMap($cursor, array $keys) { | |||||
$device = $this->loadCursorObject($cursor); | |||||
return array( | |||||
'id' => $device->getID(), | |||||
'name' => $device->getName(), | |||||
); | |||||
} | |||||
public function getBuiltinOrders() { | |||||
return array( | |||||
'name' => array( | |||||
'vector' => array('name'), | |||||
'name' => pht('Device Name'), | |||||
), | |||||
) + parent::getBuiltinOrders(); | |||||
} | } | ||||
public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
return 'PhabricatorAlmanacApplication'; | return 'PhabricatorAlmanacApplication'; | ||||
} | } | ||||
} | } |