mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-26 07:20:57 +01:00
1ba52fac86
Summary: Ref T2015. All the Drydock query classes share the application method; move it into a shared base class to slightly shrink the codebase. Test Plan: Browsed query UIs. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2015 Differential Revision: https://secure.phabricator.com/D7837
96 lines
1.9 KiB
PHP
96 lines
1.9 KiB
PHP
<?php
|
|
|
|
final class DrydockResourceQuery extends DrydockQuery {
|
|
|
|
private $ids;
|
|
private $phids;
|
|
private $statuses;
|
|
private $types;
|
|
private $blueprintPHIDs;
|
|
|
|
public function withIDs(array $ids) {
|
|
$this->ids = $ids;
|
|
return $this;
|
|
}
|
|
|
|
public function withPHIDs(array $phids) {
|
|
$this->phids = $phids;
|
|
return $this;
|
|
}
|
|
|
|
public function withTypes(array $types) {
|
|
$this->types = $types;
|
|
return $this;
|
|
}
|
|
|
|
public function withStatuses(array $statuses) {
|
|
$this->statuses = $statuses;
|
|
return $this;
|
|
}
|
|
|
|
public function withBlueprintPHIDs(array $blueprint_phids) {
|
|
$this->blueprintPHIDs = $blueprint_phids;
|
|
return $this;
|
|
}
|
|
|
|
public function loadPage() {
|
|
$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);
|
|
}
|
|
|
|
if ($this->phids) {
|
|
$where[] = qsprintf(
|
|
$conn_r,
|
|
'phid IN (%Ls)',
|
|
$this->phids);
|
|
}
|
|
|
|
if ($this->types) {
|
|
$where[] = qsprintf(
|
|
$conn_r,
|
|
'type IN (%Ls)',
|
|
$this->types);
|
|
}
|
|
|
|
if ($this->statuses) {
|
|
$where[] = qsprintf(
|
|
$conn_r,
|
|
'status IN (%Ls)',
|
|
$this->statuses);
|
|
}
|
|
|
|
if ($this->blueprintPHIDs) {
|
|
$where[] = qsprintf(
|
|
$conn_r,
|
|
'blueprintPHID IN (%Ls)',
|
|
$this->blueprintPHIDs);
|
|
}
|
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
|
|
return $this->formatWhereClause($where);
|
|
}
|
|
|
|
}
|