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;
|
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-06 20:12:57 -08:00
|
|
|
public function withCustomPHIDs(array $phids) {
|
|
|
|
|
$this->customPHIDs = $phids;
|
|
|
|
|
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) {
|
|
|
|
|
$where[] = qsprintf(
|
|
|
|
|
$conn,
|
|
|
|
|
'customPHID IN (%Ls)',
|
|
|
|
|
$this->customPHIDs);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
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';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|