Changeset View
Changeset View
Standalone View
Standalone View
src/applications/dashboard/query/PhabricatorDashboardQuery.php
| <?php | <?php | ||||
| final class PhabricatorDashboardQuery | final class PhabricatorDashboardQuery | ||||
| extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
| private $ids; | private $ids; | ||||
| private $phids; | private $phids; | ||||
| private $statuses; | private $statuses; | ||||
| private $authorPHIDs; | private $authorPHIDs; | ||||
| private $canEdit; | private $canEdit; | ||||
| private $needPanels; | |||||
| private $needProjects; | |||||
| 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; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withStatuses(array $statuses) { | public function withStatuses(array $statuses) { | ||||
| $this->statuses = $statuses; | $this->statuses = $statuses; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withAuthorPHIDs(array $authors) { | public function withAuthorPHIDs(array $authors) { | ||||
| $this->authorPHIDs = $authors; | $this->authorPHIDs = $authors; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function needPanels($need_panels) { | |||||
| $this->needPanels = $need_panels; | |||||
| return $this; | |||||
| } | |||||
| public function needProjects($need_projects) { | |||||
| $this->needProjects = $need_projects; | |||||
| return $this; | |||||
| } | |||||
| public function withCanEdit($can_edit) { | public function withCanEdit($can_edit) { | ||||
| $this->canEdit = $can_edit; | $this->canEdit = $can_edit; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withNameNgrams($ngrams) { | public function withNameNgrams($ngrams) { | ||||
| return $this->withNgramsConstraint( | return $this->withNgramsConstraint( | ||||
| id(new PhabricatorDashboardNgrams()), | id(new PhabricatorDashboardNgrams()), | ||||
| Show All 16 Lines | if ($this->canEdit) { | ||||
| $dashboards = id(new PhabricatorPolicyFilter()) | $dashboards = id(new PhabricatorPolicyFilter()) | ||||
| ->setViewer($this->getViewer()) | ->setViewer($this->getViewer()) | ||||
| ->requireCapabilities(array( | ->requireCapabilities(array( | ||||
| PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
| )) | )) | ||||
| ->apply($dashboards); | ->apply($dashboards); | ||||
| } | } | ||||
| if ($this->needPanels) { | |||||
| $edge_query = id(new PhabricatorEdgeQuery()) | |||||
| ->withSourcePHIDs($phids) | |||||
| ->withEdgeTypes( | |||||
| array( | |||||
| PhabricatorDashboardDashboardHasPanelEdgeType::EDGECONST, | |||||
| )); | |||||
| $edge_query->execute(); | |||||
| $panel_phids = $edge_query->getDestinationPHIDs(); | |||||
| if ($panel_phids) { | |||||
| // NOTE: We explicitly disable policy exceptions when loading panels. | |||||
| // If a particular panel is invalid or not visible to the viewer, | |||||
| // we'll still render the dashboard, just not that panel. | |||||
| $panels = id(new PhabricatorDashboardPanelQuery()) | |||||
| ->setParentQuery($this) | |||||
| ->setRaisePolicyExceptions(false) | |||||
| ->setViewer($this->getViewer()) | |||||
| ->withPHIDs($panel_phids) | |||||
| ->execute(); | |||||
| $panels = mpull($panels, null, 'getPHID'); | |||||
| } else { | |||||
| $panels = array(); | |||||
| } | |||||
| foreach ($dashboards as $dashboard) { | |||||
| $dashboard_phids = $edge_query->getDestinationPHIDs( | |||||
| array($dashboard->getPHID())); | |||||
| $dashboard_panels = array_select_keys($panels, $dashboard_phids); | |||||
| $dashboard->attachPanelPHIDs($dashboard_phids); | |||||
| $dashboard->attachPanels($dashboard_panels); | |||||
| } | |||||
| } | |||||
| if ($this->needProjects) { | |||||
| $edge_query = id(new PhabricatorEdgeQuery()) | |||||
| ->withSourcePHIDs($phids) | |||||
| ->withEdgeTypes( | |||||
| array( | |||||
| PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, | |||||
| )); | |||||
| $edge_query->execute(); | |||||
| foreach ($dashboards as $dashboard) { | |||||
| $project_phids = $edge_query->getDestinationPHIDs( | |||||
| array($dashboard->getPHID())); | |||||
| $dashboard->attachProjectPHIDs($project_phids); | |||||
| } | |||||
| } | |||||
| return $dashboards; | return $dashboards; | ||||
| } | } | ||||
| 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( | ||||
| Show All 38 Lines | |||||