Changeset View
Changeset View
Standalone View
Standalone View
src/applications/release/query/ReleaseChangeRequestQuery.php
- This file was added.
<?php | |||||
final class ReleaseChangeRequestQuery | |||||
extends PhabricatorCursorPagedPolicyAwareQuery { | |||||
private $ids; | |||||
private $phids; | |||||
private $releasePHIDs; | |||||
private $statuses; | |||||
private $implementationKeys; | |||||
private $datasourceQuery; | |||||
private $needReleases; | |||||
private $needRequestObjects; | |||||
private $groupBy = 'group-none'; | |||||
const GROUP_NONE = 'group-none'; | |||||
const GROUP_STATE = 'group-state'; | |||||
public function withIDs(array $ids) { | |||||
$this->ids = $ids; | |||||
return $this; | |||||
} | |||||
public function withPHIDs(array $phids) { | |||||
$this->phids = $phids; | |||||
return $this; | |||||
} | |||||
public function withReleasePHIDs(array $release_phids) { | |||||
$this->releasePHIDs = $release_phids; | |||||
return $this; | |||||
} | |||||
public function withStatuses(array $statuses) { | |||||
$this->statuses = $statuses; | |||||
return $this; | |||||
} | |||||
public function withImplementationKeys(array $implementation_keys) { | |||||
$this->implementationKeys = $implementation_keys; | |||||
return $this; | |||||
} | |||||
public function withDatasourceQuery($query) { | |||||
$this->datasourceQuery = $query; | |||||
return $this; | |||||
} | |||||
public function needReleases($need_releases) { | |||||
$this->needReleases = $need_releases; | |||||
return $this; | |||||
} | |||||
public function needRequestObjects($need_request_objects) { | |||||
$this->needRequestObjects = $need_request_objects; | |||||
return $this; | |||||
} | |||||
public function newResultObject() { | |||||
return new ReleaseChangeRequest(); | |||||
} | |||||
protected function loadPage() { | |||||
return $this->loadStandardPage($this->newResultObject()); | |||||
} | |||||
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | |||||
$where = parent::buildWhereClauseParts($conn); | |||||
if ($this->ids !== null) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'id IN (%Ld)', | |||||
$this->ids); | |||||
} | |||||
if ($this->phids !== null) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'phid IN (%Ls)', | |||||
$this->phids); | |||||
} | |||||
if ($this->releasePHIDs !== null) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'releasePHID IN (%Ls)', | |||||
$this->releasePHIDs); | |||||
} | |||||
if ($this->statuses !== null) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'status IN (%Ls)', | |||||
$this->statuses); | |||||
} | |||||
if ($this->implementationKeys !== null) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'implementationKey IN (%Ls)', | |||||
$this->implementationKeys); | |||||
} | |||||
if (strlen($this->datasourceQuery)) { | |||||
// TODO | |||||
// $where[] = qsprintf( | |||||
// $conn, | |||||
// 'name LIKE %~', | |||||
// $this->datasourceQuery); | |||||
} | |||||
return $where; | |||||
} | |||||
protected function didFilterPage(array $changes) { | |||||
$viewer = $this->getViewer(); | |||||
if ($this->needReleases) { | |||||
$release_phids = mpull($changes, 'getReleasePHID'); | |||||
$releases = id(new PhabricatorReleaseReleaseQuery()) | |||||
->setViewer($viewer) | |||||
->setParentQuery($this) | |||||
->withPHIDs($release_phids) | |||||
->execute(); | |||||
$releases = mpull($releases, null, 'getPHID'); | |||||
foreach ($changes as $change) { | |||||
$change->attachRelease(idx($releases, $change->getReleasePHID())); | |||||
} | |||||
} | |||||
if ($this->needRequestObjects) { | |||||
$object_phids = mpull($changes, 'getRequestedObjectPHID'); | |||||
$objects = id(new PhabricatorObjectQuery()) | |||||
->setViewer($viewer) | |||||
->setParentQuery($this) | |||||
->withPHIDs($object_phids) | |||||
->execute(); | |||||
$objects = mpull($objects, null, 'getPHID'); | |||||
foreach ($changes as $change) { | |||||
$change->attachRequestedObject(idx($objects, $change->getRequestedObjectPHID())); | |||||
} | |||||
} | |||||
return $changes; | |||||
} | |||||
// protected function getDefaultOrderVector() { | |||||
// return array('name'); | |||||
// } | |||||
public function getBuiltinOrders() { | |||||
return array( | |||||
'select' => array( | |||||
'vector' => array('status', '-id'), | |||||
'name' => pht('Status'), | |||||
), | |||||
) + parent::getBuiltinOrders(); | |||||
} | |||||
public function setGroupBy($group) { | |||||
$this->groupBy = $group; | |||||
$vector = array(); | |||||
switch ($this->groupBy) { | |||||
case self::GROUP_NONE: | |||||
$vector = array(); | |||||
break; | |||||
case self::GROUP_STATE: | |||||
$vector = array('status'); | |||||
break; | |||||
} | |||||
// $this->setGroupVector($vector); | |||||
return $this; | |||||
} | |||||
public function getOrderableColumns() { | |||||
return parent::getOrderableColumns() + array( | |||||
'release' => array( | |||||
'table' => $this->getPrimaryTableAlias(), | |||||
'column' => 'releasePHID', | |||||
'reverse' => false, | |||||
'type' => 'phid', | |||||
'unique' => false, | |||||
), | |||||
'status' => array( | |||||
'table' => $this->getPrimaryTableAlias(), | |||||
'column' => 'status', | |||||
'reverse' => false, | |||||
'type' => 'string', | |||||
'unique' => false, | |||||
), | |||||
); | |||||
} | |||||
public function getQueryApplicationClass() { | |||||
return 'PhabricatorReleaseApplication'; | |||||
} | |||||
} |