Generate file attachment transactions for explicit Remarkup attachments on common...
[phabricator.git] / src / applications / search / query / PhabricatorProfileMenuItemConfigurationQuery.php
blob16b5d793a42a695630ae2aac5019ad8551e30b97
1 <?php
3 final class PhabricatorProfileMenuItemConfigurationQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $ids;
7 private $phids;
8 private $profilePHIDs;
9 private $customPHIDs;
10 private $includeGlobal;
11 private $affectedObjectPHIDs;
13 public function withIDs(array $ids) {
14 $this->ids = $ids;
15 return $this;
18 public function withPHIDs(array $phids) {
19 $this->phids = $phids;
20 return $this;
23 public function withProfilePHIDs(array $phids) {
24 $this->profilePHIDs = $phids;
25 return $this;
28 public function withCustomPHIDs(array $phids, $include_global = false) {
29 $this->customPHIDs = $phids;
30 $this->includeGlobal = $include_global;
31 return $this;
34 public function withAffectedObjectPHIDs(array $phids) {
35 $this->affectedObjectPHIDs = $phids;
36 return $this;
39 public function newResultObject() {
40 return new PhabricatorProfileMenuItemConfiguration();
43 protected function loadPage() {
44 return $this->loadStandardPage($this->newResultObject());
47 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
48 $where = parent::buildWhereClauseParts($conn);
50 if ($this->ids !== null) {
51 $where[] = qsprintf(
52 $conn,
53 'config.id IN (%Ld)',
54 $this->ids);
57 if ($this->phids !== null) {
58 $where[] = qsprintf(
59 $conn,
60 'config.phid IN (%Ls)',
61 $this->phids);
64 if ($this->profilePHIDs !== null) {
65 $where[] = qsprintf(
66 $conn,
67 'config.profilePHID IN (%Ls)',
68 $this->profilePHIDs);
71 if ($this->customPHIDs !== null) {
72 if ($this->customPHIDs && $this->includeGlobal) {
73 $where[] = qsprintf(
74 $conn,
75 'config.customPHID IN (%Ls) OR config.customPHID IS NULL',
76 $this->customPHIDs);
77 } else if ($this->customPHIDs) {
78 $where[] = qsprintf(
79 $conn,
80 'config.customPHID IN (%Ls)',
81 $this->customPHIDs);
82 } else {
83 $where[] = qsprintf(
84 $conn,
85 'config.customPHID IS NULL');
89 if ($this->affectedObjectPHIDs !== null) {
90 $where[] = qsprintf(
91 $conn,
92 'affected.dst IN (%Ls)',
93 $this->affectedObjectPHIDs);
96 return $where;
99 protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
100 $joins = parent::buildJoinClauseParts($conn);
102 if ($this->affectedObjectPHIDs !== null) {
103 $joins[] = qsprintf(
104 $conn,
105 'JOIN %T affected ON affected.src = config.phid
106 AND affected.type = %d',
107 PhabricatorEdgeConfig::TABLE_NAME_EDGE,
108 PhabricatorProfileMenuItemAffectsObjectEdgeType::EDGECONST);
111 return $joins;
114 protected function willFilterPage(array $page) {
115 $items = PhabricatorProfileMenuItem::getAllMenuItems();
116 foreach ($page as $key => $item) {
117 $item_type = idx($items, $item->getMenuItemKey());
118 if (!$item_type) {
119 $this->didRejectResult($item);
120 unset($page[$key]);
121 continue;
123 $item_type = clone $item_type;
124 $item_type->setViewer($this->getViewer());
125 $item->attachMenuItem($item_type);
128 if (!$page) {
129 return array();
132 $profile_phids = mpull($page, 'getProfilePHID');
134 $profiles = id(new PhabricatorObjectQuery())
135 ->setViewer($this->getViewer())
136 ->setParentQuery($this)
137 ->withPHIDs($profile_phids)
138 ->execute();
139 $profiles = mpull($profiles, null, 'getPHID');
141 foreach ($page as $key => $item) {
142 $profile = idx($profiles, $item->getProfilePHID());
143 if (!$profile) {
144 $this->didRejectResult($item);
145 unset($page[$key]);
146 continue;
149 $item->attachProfileObject($profile);
152 return $page;
155 public function getQueryApplicationClass() {
156 return 'PhabricatorSearchApplication';
159 protected function getPrimaryTableAlias() {
160 return 'config';