2012-08-08 12:25:11 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorOwnersPackageQuery
|
2012-09-13 10:15:08 -07:00
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
2012-08-08 12:25:11 -07:00
|
|
|
|
2013-07-26 10:31:26 -07:00
|
|
|
private $phids;
|
2012-08-08 12:25:11 -07:00
|
|
|
private $ownerPHIDs;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Owners are direct owners, and members of owning projects.
|
|
|
|
*/
|
|
|
|
public function withOwnerPHIDs(array $phids) {
|
|
|
|
$this->ownerPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2013-07-26 10:31:26 -07:00
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
$this->phids = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-08-08 12:25:11 -07:00
|
|
|
protected function loadPage() {
|
|
|
|
$table = new PhabricatorOwnersPackage();
|
|
|
|
$conn_r = $table->establishConnection('r');
|
|
|
|
|
|
|
|
$data = queryfx_all(
|
|
|
|
$conn_r,
|
|
|
|
'SELECT p.* FROM %T p %Q %Q %Q %Q',
|
|
|
|
$table->getTableName(),
|
|
|
|
$this->buildJoinClause($conn_r),
|
|
|
|
$this->buildWhereClause($conn_r),
|
|
|
|
$this->buildOrderClause($conn_r),
|
|
|
|
$this->buildLimitClause($conn_r));
|
|
|
|
|
|
|
|
return $table->loadAllFromArray($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function buildJoinClause(AphrontDatabaseConnection $conn_r) {
|
|
|
|
$joins = array();
|
|
|
|
|
|
|
|
if ($this->ownerPHIDs) {
|
|
|
|
$joins[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'JOIN %T o ON o.packageID = p.id',
|
|
|
|
id(new PhabricatorOwnersOwner())->getTableName());
|
|
|
|
}
|
|
|
|
|
2013-07-26 10:31:26 -07:00
|
|
|
return implode(' ', $joins);
|
2012-08-08 12:25:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
|
|
|
$where = array();
|
|
|
|
|
2013-07-26 10:31:26 -07:00
|
|
|
if ($this->phids) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'p.phid IN (%Ls)',
|
|
|
|
$this->phids);
|
|
|
|
}
|
|
|
|
|
2012-08-08 12:25:11 -07:00
|
|
|
if ($this->ownerPHIDs) {
|
|
|
|
$base_phids = $this->ownerPHIDs;
|
|
|
|
|
|
|
|
$query = new PhabricatorProjectQuery();
|
2012-08-08 17:10:10 -07:00
|
|
|
$query->setViewer($this->getViewer());
|
2012-08-08 12:25:11 -07:00
|
|
|
$query->withMemberPHIDs($base_phids);
|
|
|
|
$projects = $query->execute();
|
|
|
|
$project_phids = mpull($projects, 'getPHID');
|
|
|
|
|
|
|
|
$all_phids = array_merge($base_phids, $project_phids);
|
|
|
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn_r,
|
|
|
|
'o.userPHID IN (%Ls)',
|
|
|
|
$all_phids);
|
|
|
|
}
|
|
|
|
|
|
|
|
$where[] = $this->buildPagingClause($conn_r);
|
|
|
|
return $this->formatWhereClause($where);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|