2012-03-27 05:54:26 +02:00
|
|
|
<?php
|
|
|
|
|
2013-12-26 21:30:17 +01:00
|
|
|
final class DrydockLogQuery extends PhabricatorCursorPagedPolicyAwareQuery {
|
2012-11-02 00:53:17 +01:00
|
|
|
|
2012-03-27 05:54:26 +02:00
|
|
|
private $resourceIDs;
|
|
|
|
private $leaseIDs;
|
|
|
|
|
|
|
|
public function withResourceIDs(array $ids) {
|
|
|
|
$this->resourceIDs = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withLeaseIDs(array $ids) {
|
|
|
|
$this->leaseIDs = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-12-26 21:30:17 +01:00
|
|
|
public function loadPage() {
|
2012-03-27 05:54:26 +02:00
|
|
|
$table = new DrydockLog();
|
|
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
|
|
|
|
$data = queryfx_all(
|
|
|
|
$conn_r,
|
|
|
|
'SELECT log.* FROM %T log %Q %Q %Q',
|
|
|
|
$table->getTableName(),
|
2012-11-02 00:53:17 +01:00
|
|
|
$this->buildWhereClause($conn_r),
|
|
|
|
$this->buildOrderClause($conn_r),
|
|
|
|
$this->buildLimitClause($conn_r));
|
2012-03-27 05:54:26 +02:00
|
|
|
|
|
|
|
return $table->loadAllFromArray($data);
|
|
|
|
}
|
|
|
|
|
2013-12-26 21:30:17 +01:00
|
|
|
public function willFilterPage(array $logs) {
|
|
|
|
$resource_ids = mpull($logs, 'getResourceID');
|
|
|
|
$resources = id(new DrydockResourceQuery())
|
|
|
|
->setParentQuery($this)
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
->withIDs($resource_ids)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
foreach ($logs as $key => $log) {
|
|
|
|
$resource = idx($resources, $log->getResourceID());
|
|
|
|
$log->attachResource($resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $logs;
|
|
|
|
}
|
|
|
|
|
2012-11-02 00:53:17 +01:00
|
|
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
2012-03-27 05:54:26 +02:00
|
|
|
$where = array();
|
|
|
|
|
|
|
|
if ($this->resourceIDs) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'resourceID IN (%Ld)',
|
|
|
|
$this->resourceIDs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->leaseIDs) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'leaseID IN (%Ld)',
|
|
|
|
$this->leaseIDs);
|
|
|
|
}
|
|
|
|
|
2013-12-26 21:30:17 +01:00
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
2012-11-02 00:53:17 +01:00
|
|
|
|
2012-03-27 05:54:26 +02:00
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
|
|
|
|
2013-12-26 21:30:17 +01:00
|
|
|
public function getQueryApplicationClass() {
|
|
|
|
return 'PhabricatorApplicationDrydock';
|
2012-03-27 05:54:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|