Changeset View
Changeset View
Standalone View
Standalone View
src/applications/release/query/ReleaseChangeRequestQuery.php
- This file was added.
Property | Old Value | New Value |
---|---|---|
File Mode | null | 100755 |
<?php | |||||
final class ReleaseChangeRequestQuery | |||||
extends PhabricatorCursorPagedPolicyAwareQuery { | |||||
private $ids; | |||||
private $phids; | |||||
private $releasePHIDs; | |||||
private $statuses; | |||||
private $implementationKeys; | |||||
private $datasourceQuery; | |||||
private $needReleases; | |||||
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 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 $objects) { | |||||
$viewer = $this->getViewer(); | |||||
if ($this->needReleases) { | |||||
$release_phids = mpull($objects, 'getReleasePHID'); | |||||
$releases = id(new PhabricatorReleaseReleaseQuery()) | |||||
->setViewer($viewer) | |||||
->setParentQuery($this) | |||||
->withPHIDs($release_phids) | |||||
->execute(); | |||||
$releases = mpull($releases, null, 'getPHID'); | |||||
foreach ($objects as $change) { | |||||
$change->attachRelease(idx($releases, $change->getReleasePHID())); | |||||
} | |||||
} | |||||
return $objects; | |||||
} | |||||
// protected function getDefaultOrderVector() { | |||||
// return array('name'); | |||||
// } | |||||
public function getBuiltinOrders() { | |||||
return array( | |||||
'name' => array( | |||||
'vector' => array('name'), | |||||
'name' => pht('Name'), | |||||
), | |||||
'select' => array( | |||||
'vector' => array('state', 'name'), | |||||
'name' => pht('Name'), | |||||
), | |||||
) + 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( | |||||
'name' => array( | |||||
'table' => $this->getPrimaryTableAlias(), | |||||
'column' => 'name', | |||||
'reverse' => true, | |||||
'type' => 'string', | |||||
'unique' => true, | |||||
), | |||||
'release' => array( | |||||
'table' => $this->getPrimaryTableAlias(), | |||||
'column' => 'releasePHID', | |||||
'reverse' => false, | |||||
'type' => 'phid', | |||||
'unique' => false, | |||||
), | |||||
'state' => array( | |||||
'table' => $this->getPrimaryTableAlias(), | |||||
'column' => 'state', | |||||
'reverse' => false, | |||||
'type' => 'string', | |||||
'unique' => false, | |||||
), | |||||
); | |||||
} | |||||
public function getQueryApplicationClass() { | |||||
return 'PhabricatorReleaseApplication'; | |||||
} | |||||
} |