Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/query/PhabricatorProjectColumnQuery.php
<?php | <?php | ||||
final class PhabricatorProjectColumnQuery | final class PhabricatorProjectColumnQuery | ||||
extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
private $ids; | private $ids; | ||||
private $phids; | private $phids; | ||||
private $projectPHIDs; | private $projectPHIDs; | ||||
private $proxyPHIDs; | private $proxyPHIDs; | ||||
private $statuses; | private $statuses; | ||||
private $datasourceQuery; | |||||
public function withIDs(array $ids) { | public function withIDs(array $ids) { | ||||
$this->ids = $ids; | $this->ids = $ids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withPHIDs(array $phids) { | public function withPHIDs(array $phids) { | ||||
$this->phids = $phids; | $this->phids = $phids; | ||||
Show All 10 Lines | public function withProxyPHIDs(array $proxy_phids) { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withStatuses(array $status) { | public function withStatuses(array $status) { | ||||
$this->statuses = $status; | $this->statuses = $status; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withDatasourceQuery($query) { | |||||
$this->datasourceQuery = $query; | |||||
return $this; | |||||
} | |||||
public function newResultObject() { | public function newResultObject() { | ||||
return new PhabricatorProjectColumn(); | return new PhabricatorProjectColumn(); | ||||
} | } | ||||
protected function loadPage() { | protected function loadPage() { | ||||
return $this->loadStandardPage($this->newResultObject()); | return $this->loadStandardPage($this->newResultObject()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | foreach ($page as $key => $column) { | ||||
} | } | ||||
$column->attachProxy($proxy); | $column->attachProxy($proxy); | ||||
} | } | ||||
return $page; | return $page; | ||||
} | } | ||||
protected function getPrimaryTableAlias() { | |||||
return 'col'; | |||||
} | |||||
protected function buildSelectClauseParts(AphrontDatabaseConnection $conn) { | |||||
$parts = parent::buildSelectClauseParts($conn); | |||||
$parts[] = 'col.*'; | |||||
if ($this->shouldJoinProjectTable()) { | |||||
$parts[] = 'proj.name projectName'; | |||||
kislinsk: Joining is a bit tricky here as the project column table and the project table have common… | |||||
} | |||||
return $parts; | |||||
} | |||||
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { | |||||
$joins = parent::buildJoinClauseParts($conn); | |||||
if ($this->shouldJoinProjectTable()) { | |||||
$joins[] = qsprintf( | |||||
$conn, | |||||
'LEFT JOIN %T proj ON col.projectPHID = proj.phid', | |||||
id(new PhabricatorProject())->getTableName()); | |||||
} | |||||
return $joins; | |||||
} | |||||
private function shouldJoinProjectTable() { | |||||
return (strlen($this->datasourceQuery) ? true : false); | |||||
} | |||||
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
$where = parent::buildWhereClauseParts($conn); | $where = parent::buildWhereClauseParts($conn); | ||||
if ($this->ids !== null) { | if ($this->ids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'id IN (%Ld)', | 'col.id IN (%Ld)', | ||||
$this->ids); | $this->ids); | ||||
} | } | ||||
if ($this->phids !== null) { | if ($this->phids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'phid IN (%Ls)', | 'col.phid IN (%Ls)', | ||||
$this->phids); | $this->phids); | ||||
} | } | ||||
if ($this->projectPHIDs !== null) { | if ($this->projectPHIDs !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'projectPHID IN (%Ls)', | 'col.projectPHID IN (%Ls)', | ||||
$this->projectPHIDs); | $this->projectPHIDs); | ||||
} | } | ||||
if ($this->proxyPHIDs !== null) { | if ($this->proxyPHIDs !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'proxyPHID IN (%Ls)', | 'col.proxyPHID IN (%Ls)', | ||||
$this->proxyPHIDs); | $this->proxyPHIDs); | ||||
} | } | ||||
if ($this->statuses !== null) { | if ($this->statuses !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'status IN (%Ld)', | 'col.status IN (%Ld)', | ||||
$this->statuses); | $this->statuses); | ||||
} | } | ||||
if (strlen($this->datasourceQuery)) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'LOWER(col.name) LIKE LOWER(%>) OR proj.name LIKE %>', | |||||
Not Done Inline ActionsLOWER() is necessary for the project column name as it hasn't a case-insensitive collation in contrast to the project name. kislinsk: LOWER() is necessary for the project column name as it hasn't a case-insensitive collation in… | |||||
$this->datasourceQuery, | |||||
$this->datasourceQuery); | |||||
} | |||||
return $where; | return $where; | ||||
} | } | ||||
public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
return 'PhabricatorProjectApplication'; | return 'PhabricatorProjectApplication'; | ||||
} | } | ||||
} | } |
Joining is a bit tricky here as the project column table and the project table have common table column names like name and phid. Without the alias, LiskDAO::loadFromArray() would mess up the created project column object with the wrong name.