2012-12-17 14:47:21 -08:00
|
|
|
<?php
|
|
|
|
|
2013-11-28 08:32:51 +11:00
|
|
|
final class DrydockResourceQuery
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
2012-12-17 14:47:21 -08:00
|
|
|
|
|
|
|
private $ids;
|
2013-11-28 08:32:51 +11:00
|
|
|
private $statuses;
|
|
|
|
private $types;
|
2012-12-17 14:47:21 -08:00
|
|
|
|
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-11-28 08:32:51 +11:00
|
|
|
public function withTypes(array $types) {
|
|
|
|
$this->types = $types;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withStatuses(array $statuses) {
|
|
|
|
$this->statuses = $statuses;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function loadPage() {
|
2012-12-17 14:47:21 -08:00
|
|
|
$table = new DrydockResource();
|
|
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
|
|
|
|
$data = queryfx_all(
|
|
|
|
$conn_r,
|
|
|
|
'SELECT resource.* FROM %T resource %Q %Q %Q',
|
|
|
|
$table->getTableName(),
|
|
|
|
$this->buildWhereClause($conn_r),
|
|
|
|
$this->buildOrderClause($conn_r),
|
|
|
|
$this->buildLimitClause($conn_r));
|
|
|
|
|
|
|
|
$resources = $table->loadAllFromArray($data);
|
|
|
|
|
|
|
|
return $resources;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
|
|
|
$where = array();
|
|
|
|
|
|
|
|
if ($this->ids) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'id IN (%Ld)',
|
|
|
|
$this->ids);
|
|
|
|
}
|
|
|
|
|
2013-11-28 08:32:51 +11:00
|
|
|
if ($this->types) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'type IN (%Ls)',
|
|
|
|
$this->types);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->statuses) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'status IN (%Ls)',
|
|
|
|
$this->statuses);
|
|
|
|
}
|
|
|
|
|
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
|
|
|
2012-12-17 14:47:21 -08:00
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
|
|
|
|
2013-11-28 08:32:51 +11:00
|
|
|
public function getQueryApplicationClass() {
|
|
|
|
return 'PhabricatorApplicationDrydock';
|
2012-12-17 14:47:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|