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 $ancestorPHIDs; | ||||
| private $parentPHIDs; | private $parentPHIDs; | ||||
| private $isMilestone; | private $isMilestone; | ||||
| private $hasSubprojects; | |||||
| private $minDepth; | private $minDepth; | ||||
| private $maxDepth; | 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'; | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | public function withAncestorProjectPHIDs($ancestor_phids) { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withIsMilestone($is_milestone) { | public function withIsMilestone($is_milestone) { | ||||
| $this->isMilestone = $is_milestone; | $this->isMilestone = $is_milestone; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withHasSubprojects($has_subprojects) { | |||||
| $this->hasSubprojects = $has_subprojects; | |||||
| return $this; | |||||
| } | |||||
| public function getProperty() { | |||||
| return $this->property; | |||||
joshuaspence: Hmm, where is this defined? | |||||
epriestleyAuthorUnsubmitted Not Done Inline Actionswhoops epriestley: whoops | |||||
| } | |||||
| public function withDepthBetween($min, $max) { | public function withDepthBetween($min, $max) { | ||||
| $this->minDepth = $min; | $this->minDepth = $min; | ||||
| $this->maxDepth = $max; | $this->maxDepth = $max; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function needMembers($need_members) { | public function needMembers($need_members) { | ||||
| $this->needMembers = $need_members; | $this->needMembers = $need_members; | ||||
| ▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | protected function getPagingValueMap($cursor, array $keys) { | ||||
| ); | ); | ||||
| } | } | ||||
| protected function loadPage() { | protected function loadPage() { | ||||
| return $this->loadStandardPage($this->newResultObject()); | return $this->loadStandardPage($this->newResultObject()); | ||||
| } | } | ||||
| protected function willFilterPage(array $projects) { | protected function willFilterPage(array $projects) { | ||||
| $project_phids = array(); | |||||
| $ancestor_paths = array(); | $ancestor_paths = array(); | ||||
| foreach ($projects as $project) { | foreach ($projects as $project) { | ||||
| $project_phids[] = $project->getPHID(); | |||||
| foreach ($project->getAncestorProjectPaths() as $path) { | foreach ($project->getAncestorProjectPaths() as $path) { | ||||
| $ancestor_paths[$path] = $path; | $ancestor_paths[$path] = $path; | ||||
| } | } | ||||
| } | } | ||||
| if ($ancestor_paths) { | if ($ancestor_paths) { | ||||
| $ancestors = id(new PhabricatorProject())->loadAllWhere( | $ancestors = id(new PhabricatorProject())->loadAllWhere( | ||||
| 'projectPath IN (%Ls)', | 'projectPath IN (%Ls)', | ||||
| $ancestor_paths); | $ancestor_paths); | ||||
| } else { | } else { | ||||
| $ancestors = array(); | $ancestors = array(); | ||||
| } | } | ||||
| $projects = $this->linkProjectGraph($projects, $ancestors); | $projects = $this->linkProjectGraph($projects, $ancestors); | ||||
| $viewer_phid = $this->getViewer()->getPHID(); | $viewer_phid = $this->getViewer()->getPHID(); | ||||
| $project_phids = mpull($projects, 'getPHID'); | |||||
| $member_type = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST; | $member_type = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST; | ||||
| $watcher_type = PhabricatorObjectHasWatcherEdgeType::EDGECONST; | $watcher_type = PhabricatorObjectHasWatcherEdgeType::EDGECONST; | ||||
| $types = array(); | $types = array(); | ||||
| $types[] = $member_type; | $types[] = $member_type; | ||||
| if ($this->needWatchers) { | if ($this->needWatchers) { | ||||
| $types[] = $watcher_type; | $types[] = $watcher_type; | ||||
| } | } | ||||
| $all_sources = array(); | |||||
| foreach ($projects as $project) { | |||||
| if ($project->isMilestone()) { | |||||
| $phid = $project->getParentProjectPHID(); | |||||
| } else { | |||||
| $phid = $project->getPHID(); | |||||
| } | |||||
| $all_sources[$phid] = $phid; | |||||
| } | |||||
| $edge_query = id(new PhabricatorEdgeQuery()) | $edge_query = id(new PhabricatorEdgeQuery()) | ||||
| ->withSourcePHIDs($project_phids) | ->withSourcePHIDs($all_sources) | ||||
| ->withEdgeTypes($types); | ->withEdgeTypes($types); | ||||
| // If we only need to know if the viewer is a member, we can restrict | // If we only need to know if the viewer is a member, we can restrict | ||||
| // the query to just their PHID. | // the query to just their PHID. | ||||
| if (!$this->needMembers && !$this->needWatchers) { | if (!$this->needMembers && !$this->needWatchers) { | ||||
| $edge_query->withDestinationPHIDs(array($viewer_phid)); | $edge_query->withDestinationPHIDs(array($viewer_phid)); | ||||
| } | } | ||||
| $edge_query->execute(); | $edge_query->execute(); | ||||
| $membership_projects = array(); | $membership_projects = array(); | ||||
| foreach ($projects as $project) { | foreach ($projects as $project) { | ||||
| $project_phid = $project->getPHID(); | $project_phid = $project->getPHID(); | ||||
| if ($project->isMilestone()) { | |||||
| $source_phids = array($project->getParentProjectPHID()); | |||||
| } else { | |||||
| $source_phids = array($project_phid); | |||||
| } | |||||
| $member_phids = $edge_query->getDestinationPHIDs( | $member_phids = $edge_query->getDestinationPHIDs( | ||||
| array($project_phid), | $source_phids, | ||||
| array($member_type)); | array($member_type)); | ||||
| if (in_array($viewer_phid, $member_phids)) { | if (in_array($viewer_phid, $member_phids)) { | ||||
| $membership_projects[$project_phid] = $project; | $membership_projects[$project_phid] = $project; | ||||
| } | } | ||||
| if ($this->needMembers) { | if ($this->needMembers) { | ||||
| $project->attachMemberPHIDs($member_phids); | $project->attachMemberPHIDs($member_phids); | ||||
| } | } | ||||
| if ($this->needWatchers) { | if ($this->needWatchers) { | ||||
| $watcher_phids = $edge_query->getDestinationPHIDs( | $watcher_phids = $edge_query->getDestinationPHIDs( | ||||
| array($project_phid), | $source_phids, | ||||
| array($watcher_type)); | array($watcher_type)); | ||||
| $project->attachWatcherPHIDs($watcher_phids); | $project->attachWatcherPHIDs($watcher_phids); | ||||
| $project->setIsUserWatcher( | $project->setIsUserWatcher( | ||||
| $viewer_phid, | $viewer_phid, | ||||
| in_array($viewer_phid, $watcher_phids)); | in_array($viewer_phid, $watcher_phids)); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | if ($this->isMilestone !== null) { | ||||
| 'milestoneNumber IS NOT NULL'); | 'milestoneNumber IS NOT NULL'); | ||||
| } else { | } else { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'milestoneNumber IS NULL'); | 'milestoneNumber IS NULL'); | ||||
| } | } | ||||
| } | } | ||||
| if ($this->hasSubprojects !== null) { | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'hasSubprojects = %d', | |||||
| (int)$this->hasSubprojects); | |||||
| } | |||||
| if ($this->minDepth !== null) { | if ($this->minDepth !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'projectDepth >= %d', | 'projectDepth >= %d', | ||||
| $this->minDepth); | $this->minDepth); | ||||
| } | } | ||||
| if ($this->maxDepth !== null) { | if ($this->maxDepth !== null) { | ||||
| ▲ Show 20 Lines • Show All 144 Lines • Show Last 20 Lines | |||||
Hmm, where is this defined?