2016-01-12 10:27:39 -08:00
|
|
|
<?php
|
|
|
|
|
|
2016-12-11 09:38:06 -08:00
|
|
|
final class PhabricatorProfileMenuItemConfigurationQuery
|
2016-01-12 10:27:39 -08:00
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
|
|
|
|
|
|
private $ids;
|
|
|
|
|
private $phids;
|
2016-01-12 15:06:43 -08:00
|
|
|
private $profilePHIDs;
|
2017-01-06 20:12:57 -08:00
|
|
|
private $customPHIDs;
|
2017-01-17 12:46:05 -08:00
|
|
|
private $includeGlobal;
|
2016-01-12 10:27:39 -08:00
|
|
|
|
|
|
|
|
public function withIDs(array $ids) {
|
|
|
|
|
$this->ids = $ids;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
|
$this->phids = $phids;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-12 15:06:43 -08:00
|
|
|
public function withProfilePHIDs(array $phids) {
|
|
|
|
|
$this->profilePHIDs = $phids;
|
2016-01-12 10:27:39 -08:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-17 12:46:05 -08:00
|
|
|
public function withCustomPHIDs(array $phids, $include_global = false) {
|
2017-01-06 20:12:57 -08:00
|
|
|
$this->customPHIDs = $phids;
|
2017-01-17 12:46:05 -08:00
|
|
|
$this->includeGlobal = $include_global;
|
2017-01-17 12:04:28 -08:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-12 10:27:39 -08:00
|
|
|
public function newResultObject() {
|
2016-12-11 09:38:06 -08:00
|
|
|
return new PhabricatorProfileMenuItemConfiguration();
|
2016-01-12 10:27:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function loadPage() {
|
|
|
|
|
return $this->loadStandardPage($this->newResultObject());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
|
|
|
|
$where = parent::buildWhereClauseParts($conn);
|
|
|
|
|
|
|
|
|
|
if ($this->ids !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'id IN (%Ld)',
|
|
|
|
|
$this->ids);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($this->phids !== null) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'phid IN (%Ls)',
|
|
|
|
|
$this->phids);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-12 15:06:43 -08:00
|
|
|
if ($this->profilePHIDs !== null) {
|
2016-01-12 10:27:39 -08:00
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
2016-01-12 15:06:43 -08:00
|
|
|
'profilePHID IN (%Ls)',
|
|
|
|
|
$this->profilePHIDs);
|
2016-01-12 10:27:39 -08:00
|
|
|
}
|
|
|
|
|
|
2017-01-06 20:12:57 -08:00
|
|
|
if ($this->customPHIDs !== null) {
|
2017-01-17 12:46:05 -08:00
|
|
|
if ($this->customPHIDs && $this->includeGlobal) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'customPHID IN (%Ls) OR customPHID IS NULL',
|
|
|
|
|
$this->customPHIDs);
|
|
|
|
|
} else if ($this->customPHIDs) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'customPHID IN (%Ls)',
|
|
|
|
|
$this->customPHIDs);
|
|
|
|
|
} else {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'customPHID IS NULL');
|
|
|
|
|
}
|
2017-01-06 20:12:57 -08:00
|
|
|
}
|
|
|
|
|
|
2016-01-12 10:27:39 -08:00
|
|
|
return $where;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-12 15:06:43 -08:00
|
|
|
protected function willFilterPage(array $page) {
|
2016-12-11 10:08:26 -08:00
|
|
|
$items = PhabricatorProfileMenuItem::getAllMenuItems();
|
|
|
|
|
foreach ($page as $key => $item) {
|
|
|
|
|
$item_type = idx($items, $item->getMenuItemKey());
|
|
|
|
|
if (!$item_type) {
|
|
|
|
|
$this->didRejectResult($item);
|
2016-01-12 15:06:43 -08:00
|
|
|
unset($page[$key]);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2016-12-15 14:22:42 -08:00
|
|
|
$item_type = clone $item_type;
|
2017-01-09 11:57:32 -08:00
|
|
|
$item_type->setViewer($this->getViewer());
|
2016-12-11 10:08:26 -08:00
|
|
|
$item->attachMenuItem($item_type);
|
2016-01-12 15:06:43 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$page) {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$profile_phids = mpull($page, 'getProfilePHID');
|
|
|
|
|
|
|
|
|
|
$profiles = id(new PhabricatorObjectQuery())
|
|
|
|
|
->setViewer($this->getViewer())
|
|
|
|
|
->setParentQuery($this)
|
|
|
|
|
->withPHIDs($profile_phids)
|
|
|
|
|
->execute();
|
|
|
|
|
$profiles = mpull($profiles, null, 'getPHID');
|
|
|
|
|
|
2016-12-11 10:08:26 -08:00
|
|
|
foreach ($page as $key => $item) {
|
|
|
|
|
$profile = idx($profiles, $item->getProfilePHID());
|
2016-01-12 15:06:43 -08:00
|
|
|
if (!$profile) {
|
2016-12-11 10:08:26 -08:00
|
|
|
$this->didRejectResult($item);
|
2016-01-12 15:06:43 -08:00
|
|
|
unset($page[$key]);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
Replace ProfileMenu bugs with different bugs
Summary:
Ref T12174. This fixes more bugs than it creates, I think:
- Dashboards now show the whole menu.
- Project and home items now show selected state correctly.
- The "choose global vs personal" thing is now part of MenuEngine, and the same code builds it for Home and Favorites.
- Home now handles defaults correctly, I think.
Maybe regression/bad/still buggy?:
- Mobile home is now whatever the default thing was, not the menu?
- Title for dashboard content or other items that render their own content is incorrectly always "Configure Menu" (this was preexisting).
Test Plan:
- Created, edited, reordered, disabled, deleted and pinned personal and global items on home, favorites, and projects.
- Also checked User profiles.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12174
Differential Revision: https://secure.phabricator.com/D17273
2017-01-31 10:48:03 -08:00
|
|
|
|
2016-12-11 10:08:26 -08:00
|
|
|
$item->attachProfileObject($profile);
|
2016-01-12 15:06:43 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $page;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-12 10:27:39 -08:00
|
|
|
public function getQueryApplicationClass() {
|
|
|
|
|
return 'PhabricatorSearchApplication';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|