2012-12-17 23:47:21 +01:00
|
|
|
<?php
|
|
|
|
|
2013-12-27 22:15:30 +01:00
|
|
|
final class DrydockResourceQuery extends DrydockQuery {
|
2012-12-17 23:47:21 +01:00
|
|
|
|
|
|
|
private $ids;
|
2013-12-26 21:29:58 +01:00
|
|
|
private $phids;
|
2013-11-27 22:32:51 +01:00
|
|
|
private $statuses;
|
|
|
|
private $types;
|
2013-12-03 01:09:07 +01:00
|
|
|
private $blueprintPHIDs;
|
2012-12-17 23:47:21 +01:00
|
|
|
|
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-12-26 21:29:58 +01:00
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
$this->phids = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-11-27 22:32:51 +01:00
|
|
|
public function withTypes(array $types) {
|
|
|
|
$this->types = $types;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withStatuses(array $statuses) {
|
|
|
|
$this->statuses = $statuses;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-12-03 01:09:07 +01:00
|
|
|
public function withBlueprintPHIDs(array $blueprint_phids) {
|
|
|
|
$this->blueprintPHIDs = $blueprint_phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-11-27 22:32:51 +01:00
|
|
|
public function loadPage() {
|
2012-12-17 23:47:21 +01: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-12-26 21:29:58 +01:00
|
|
|
if ($this->phids) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'phid IN (%Ls)',
|
|
|
|
$this->phids);
|
|
|
|
}
|
|
|
|
|
2013-11-27 22:32:51 +01: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);
|
|
|
|
}
|
|
|
|
|
2013-12-03 01:09:07 +01:00
|
|
|
if ($this->blueprintPHIDs) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'blueprintPHID IN (%Ls)',
|
|
|
|
$this->blueprintPHIDs);
|
|
|
|
}
|
|
|
|
|
2013-11-27 22:32:51 +01:00
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
|
|
|
2012-12-17 23:47:21 +01:00
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|