2013-02-15 16:47:14 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorTokenGivenQuery
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
|
|
|
|
private $authorPHIDs;
|
|
|
|
private $objectPHIDs;
|
|
|
|
private $tokenPHIDs;
|
|
|
|
|
|
|
|
public function withTokenPHIDs(array $token_phids) {
|
|
|
|
$this->tokenPHIDs = $token_phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withObjectPHIDs(array $object_phids) {
|
|
|
|
$this->objectPHIDs = $object_phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withAuthorPHIDs(array $author_phids) {
|
|
|
|
$this->authorPHIDs = $author_phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-03-01 20:28:02 +01:00
|
|
|
protected function loadPage() {
|
2013-02-15 16:47:14 +01:00
|
|
|
$table = new PhabricatorTokenGiven();
|
|
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
|
|
|
|
$rows = queryfx_all(
|
|
|
|
$conn_r,
|
|
|
|
'SELECT * FROM %T %Q %Q %Q',
|
|
|
|
$table->getTableName(),
|
|
|
|
$this->buildWhereClause($conn_r),
|
|
|
|
$this->buildOrderClause($conn_r),
|
|
|
|
$this->buildLimitClause($conn_r));
|
|
|
|
|
|
|
|
return $table->loadAllFromArray($rows);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
|
|
|
$where = array();
|
|
|
|
|
|
|
|
if ($this->authorPHIDs) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'authorPHID IN (%Ls)',
|
|
|
|
$this->authorPHIDs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->objectPHIDs) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'objectPHID IN (%Ls)',
|
|
|
|
$this->objectPHIDs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->tokenPHIDs) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'tokenPHID IN (%Ls)',
|
|
|
|
$this->tokenPHIDs);
|
|
|
|
}
|
|
|
|
|
2013-03-31 21:30:06 +02:00
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
|
|
|
2013-02-15 16:47:14 +01:00
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function willFilterPage(array $results) {
|
|
|
|
$object_phids = array_filter(mpull($results, 'getObjectPHID'));
|
|
|
|
if (!$object_phids) {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2013-09-11 21:27:28 +02:00
|
|
|
$objects = id(new PhabricatorObjectQuery())
|
2013-02-15 16:47:14 +01:00
|
|
|
->setViewer($this->getViewer())
|
2013-09-11 21:27:28 +02:00
|
|
|
->withPHIDs($object_phids)
|
|
|
|
->execute();
|
2013-02-15 16:47:14 +01:00
|
|
|
|
|
|
|
foreach ($results as $key => $result) {
|
|
|
|
$phid = $result->getObjectPHID();
|
|
|
|
if (empty($objects[$phid])) {
|
|
|
|
unset($results[$key]);
|
|
|
|
} else {
|
|
|
|
$result->attachObject($objects[$phid]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|