Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/query/PhabricatorProjectQuery.php
| <?php | <?php | ||||
| final class PhabricatorProjectQuery | final class PhabricatorProjectQuery | ||||
| extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
| private $ids; | private $ids; | ||||
| private $phids; | private $phids; | ||||
| private $memberPHIDs; | private $memberPHIDs; | ||||
| private $slugs; | private $slugs; | ||||
| private $names; | private $names; | ||||
| private $nameTokens; | private $nameTokens; | ||||
| private $icons; | private $icons; | ||||
| private $colors; | private $colors; | ||||
| private $ancestorPHIDs; | |||||
| private $parentPHIDs; | |||||
| private $isMilestone; | |||||
| private $minDepth; | |||||
| private $maxDepth; | |||||
| private $status = 'status-any'; | private $status = 'status-any'; | ||||
| const STATUS_ANY = 'status-any'; | const STATUS_ANY = 'status-any'; | ||||
| const STATUS_OPEN = 'status-open'; | const STATUS_OPEN = 'status-open'; | ||||
| const STATUS_CLOSED = 'status-closed'; | const STATUS_CLOSED = 'status-closed'; | ||||
| const STATUS_ACTIVE = 'status-active'; | const STATUS_ACTIVE = 'status-active'; | ||||
| const STATUS_ARCHIVED = 'status-archived'; | const STATUS_ARCHIVED = 'status-archived'; | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | public function withIcons(array $icons) { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withColors(array $colors) { | public function withColors(array $colors) { | ||||
| $this->colors = $colors; | $this->colors = $colors; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withParentProjectPHIDs($parent_phids) { | |||||
| $this->parentPHIDs = $parent_phids; | |||||
| return $this; | |||||
| } | |||||
| public function withAncestorProjectPHIDs($ancestor_phids) { | |||||
| $this->ancestorPHIDs = $ancestor_phids; | |||||
| return $this; | |||||
| } | |||||
| public function withIsMilestone($is_milestone) { | |||||
| $this->isMilestone = $is_milestone; | |||||
| return $this; | |||||
| } | |||||
| public function withDepthBetween($min, $max) { | |||||
| $this->minDepth = $min; | |||||
| $this->maxDepth = $max; | |||||
| return $this; | |||||
| } | |||||
| public function needMembers($need_members) { | public function needMembers($need_members) { | ||||
| $this->needMembers = $need_members; | $this->needMembers = $need_members; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function needWatchers($need_watchers) { | public function needWatchers($need_watchers) { | ||||
| $this->needWatchers = $need_watchers; | $this->needWatchers = $need_watchers; | ||||
| return $this; | return $this; | ||||
| ▲ Show 20 Lines • Show All 252 Lines • ▼ Show 20 Lines | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
| if ($this->colors !== null) { | if ($this->colors !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'color IN (%Ls)', | 'color IN (%Ls)', | ||||
| $this->colors); | $this->colors); | ||||
| } | } | ||||
| if ($this->parentPHIDs !== null) { | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'parentProjectPHID IN (%Ls)', | |||||
| $this->parentPHIDs); | |||||
| } | |||||
| if ($this->ancestorPHIDs !== null) { | |||||
| $ancestor_paths = queryfx_all( | |||||
| $conn, | |||||
| 'SELECT projectPath, projectDepth FROM %T WHERE phid IN (%Ls)', | |||||
| id(new PhabricatorProject())->getTableName(), | |||||
| $this->ancestorPHIDs); | |||||
| if (!$ancestor_paths) { | |||||
| throw new PhabricatorEmptyQueryException(); | |||||
| } | |||||
| $sql = array(); | |||||
| foreach ($ancestor_paths as $ancestor_path) { | |||||
| $sql[] = qsprintf( | |||||
| $conn, | |||||
| '(projectPath LIKE %> AND projectDepth > %d)', | |||||
| $ancestor_path['projectPath'], | |||||
| $ancestor_path['projectDepth']); | |||||
| } | |||||
| $where[] = '('.implode(' OR ', $sql).')'; | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'parentProjectPHID IS NOT NULL'); | |||||
| } | |||||
| if ($this->isMilestone !== null) { | |||||
| if ($this->isMilestone) { | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'milestoneNumber IS NOT NULL'); | |||||
| } else { | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'milestoneNumber IS NULL'); | |||||
| } | |||||
| } | |||||
| if ($this->minDepth !== null) { | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'projectDepth >= %d', | |||||
| $this->minDepth); | |||||
| } | |||||
| if ($this->maxDepth !== null) { | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'projectDepth <= %d', | |||||
| $this->maxDepth); | |||||
| } | |||||
| return $where; | return $where; | ||||
| } | } | ||||
| protected function shouldGroupQueryResultRows() { | protected function shouldGroupQueryResultRows() { | ||||
| if ($this->memberPHIDs || $this->nameTokens) { | if ($this->memberPHIDs || $this->nameTokens) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| return parent::shouldGroupQueryResultRows(); | return parent::shouldGroupQueryResultRows(); | ||||
| ▲ Show 20 Lines • Show All 130 Lines • Show Last 20 Lines | |||||