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
132 lines
3.0 KiB
PHP
132 lines
3.0 KiB
PHP
<?php
|
|
|
|
final class PhabricatorProfileMenuItemConfigurationQuery
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
private $ids;
|
|
private $phids;
|
|
private $profilePHIDs;
|
|
private $customPHIDs;
|
|
private $includeGlobal;
|
|
|
|
public function withIDs(array $ids) {
|
|
$this->ids = $ids;
|
|
return $this;
|
|
}
|
|
|
|
public function withPHIDs(array $phids) {
|
|
$this->phids = $phids;
|
|
return $this;
|
|
}
|
|
|
|
public function withProfilePHIDs(array $phids) {
|
|
$this->profilePHIDs = $phids;
|
|
return $this;
|
|
}
|
|
|
|
public function withCustomPHIDs(array $phids, $include_global = false) {
|
|
$this->customPHIDs = $phids;
|
|
$this->includeGlobal = $include_global;
|
|
return $this;
|
|
}
|
|
|
|
public function newResultObject() {
|
|
return new PhabricatorProfileMenuItemConfiguration();
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
if ($this->profilePHIDs !== null) {
|
|
$where[] = qsprintf(
|
|
$conn,
|
|
'profilePHID IN (%Ls)',
|
|
$this->profilePHIDs);
|
|
}
|
|
|
|
if ($this->customPHIDs !== null) {
|
|
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');
|
|
}
|
|
}
|
|
|
|
return $where;
|
|
}
|
|
|
|
protected function willFilterPage(array $page) {
|
|
$items = PhabricatorProfileMenuItem::getAllMenuItems();
|
|
foreach ($page as $key => $item) {
|
|
$item_type = idx($items, $item->getMenuItemKey());
|
|
if (!$item_type) {
|
|
$this->didRejectResult($item);
|
|
unset($page[$key]);
|
|
continue;
|
|
}
|
|
$item_type = clone $item_type;
|
|
$item_type->setViewer($this->getViewer());
|
|
$item->attachMenuItem($item_type);
|
|
}
|
|
|
|
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');
|
|
|
|
foreach ($page as $key => $item) {
|
|
$profile = idx($profiles, $item->getProfilePHID());
|
|
if (!$profile) {
|
|
$this->didRejectResult($item);
|
|
unset($page[$key]);
|
|
continue;
|
|
}
|
|
|
|
$item->attachProfileObject($profile);
|
|
}
|
|
|
|
return $page;
|
|
}
|
|
|
|
public function getQueryApplicationClass() {
|
|
return 'PhabricatorSearchApplication';
|
|
}
|
|
|
|
}
|