Changeset View
Changeset View
Standalone View
Standalone View
src/applications/release/query/ReleaseReleaseQuery.php
- This file was added.
<?php | |||||
final class ReleaseReleaseQuery | |||||
extends PhabricatorCursorPagedPolicyAwareQuery { | |||||
private $ids; | |||||
private $phids; | |||||
private $names; | |||||
private $states; | |||||
private $templates; | |||||
private $datasourceQuery; | |||||
private $groupBy = 'group-none'; | |||||
const GROUP_NONE = 'group-none'; | |||||
const GROUP_TEMPLATE = 'group-template'; | |||||
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 withNames(array $names) { | |||||
$this->names = $names; | |||||
return $this; | |||||
} | |||||
public function withStates(array $states) { | |||||
$this->states = $states; | |||||
return $this; | |||||
} | |||||
public function withTemplateKeys(array $templates) { | |||||
$this->templates = $templates; | |||||
return $this; | |||||
} | |||||
public function withDatasourceQuery($query) { | |||||
$this->datasourceQuery = $query; | |||||
return $this; | |||||
} | |||||
public function newResultObject() { | |||||
return new ReleaseRelease(); | |||||
} | |||||
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->names !== null) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'name IN (%Ls)', | |||||
$this->names); | |||||
} | |||||
if ($this->states !== null) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'state IN (%Ls)', | |||||
$this->states); | |||||
} | |||||
if ($this->templates !== null) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'releaseTemplateKey IN (%Ls)', | |||||
$this->templates); | |||||
} | |||||
if (strlen($this->datasourceQuery)) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'name LIKE %~', | |||||
$this->datasourceQuery); | |||||
} | |||||
return $where; | |||||
} | |||||
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_TEMPLATE: | |||||
$vector = array('releaseTemplateKey'); | |||||
break; | |||||
case self::GROUP_STATE: | |||||
$vector = array('state'); | |||||
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, | |||||
), | |||||
'releaseTemplateKey' => array( | |||||
'table' => $this->getPrimaryTableAlias(), | |||||
'column' => 'releaseTemplateKey', | |||||
'reverse' => true, | |||||
'type' => 'string', | |||||
'unique' => false, | |||||
), | |||||
'state' => array( | |||||
'table' => $this->getPrimaryTableAlias(), | |||||
'column' => 'state', | |||||
'reverse' => false, | |||||
'type' => 'string', | |||||
'unique' => false, | |||||
), | |||||
); | |||||
} | |||||
public function getQueryApplicationClass() { | |||||
return 'PhabricatorReleaseApplication'; | |||||
} | |||||
} |