Differential D20398 Diff 48689 src/applications/search/query/PhabricatorProfileMenuItemConfigurationQuery.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/search/query/PhabricatorProfileMenuItemConfigurationQuery.php
<?php | <?php | ||||
final class PhabricatorProfileMenuItemConfigurationQuery | final class PhabricatorProfileMenuItemConfigurationQuery | ||||
extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
private $ids; | private $ids; | ||||
private $phids; | private $phids; | ||||
private $profilePHIDs; | private $profilePHIDs; | ||||
private $customPHIDs; | private $customPHIDs; | ||||
private $includeGlobal; | private $includeGlobal; | ||||
private $affectedObjectPHIDs; | |||||
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 withProfilePHIDs(array $phids) { | public function withProfilePHIDs(array $phids) { | ||||
$this->profilePHIDs = $phids; | $this->profilePHIDs = $phids; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withCustomPHIDs(array $phids, $include_global = false) { | public function withCustomPHIDs(array $phids, $include_global = false) { | ||||
$this->customPHIDs = $phids; | $this->customPHIDs = $phids; | ||||
$this->includeGlobal = $include_global; | $this->includeGlobal = $include_global; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function withAffectedObjectPHIDs(array $phids) { | |||||
$this->affectedObjectPHIDs = $phids; | |||||
return $this; | |||||
} | |||||
public function newResultObject() { | public function newResultObject() { | ||||
return new PhabricatorProfileMenuItemConfiguration(); | return new PhabricatorProfileMenuItemConfiguration(); | ||||
} | } | ||||
protected function loadPage() { | protected function loadPage() { | ||||
return $this->loadStandardPage($this->newResultObject()); | return $this->loadStandardPage($this->newResultObject()); | ||||
} | } | ||||
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( | ||||
$conn, | $conn, | ||||
'id IN (%Ld)', | 'config.id IN (%Ld)', | ||||
$this->ids); | $this->ids); | ||||
} | } | ||||
if ($this->phids !== null) { | if ($this->phids !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'phid IN (%Ls)', | 'config.phid IN (%Ls)', | ||||
$this->phids); | $this->phids); | ||||
} | } | ||||
if ($this->profilePHIDs !== null) { | if ($this->profilePHIDs !== null) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'profilePHID IN (%Ls)', | 'config.profilePHID IN (%Ls)', | ||||
$this->profilePHIDs); | $this->profilePHIDs); | ||||
} | } | ||||
if ($this->customPHIDs !== null) { | if ($this->customPHIDs !== null) { | ||||
if ($this->customPHIDs && $this->includeGlobal) { | if ($this->customPHIDs && $this->includeGlobal) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'customPHID IN (%Ls) OR customPHID IS NULL', | 'config.customPHID IN (%Ls) OR config.customPHID IS NULL', | ||||
$this->customPHIDs); | $this->customPHIDs); | ||||
} else if ($this->customPHIDs) { | } else if ($this->customPHIDs) { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'customPHID IN (%Ls)', | 'config.customPHID IN (%Ls)', | ||||
$this->customPHIDs); | $this->customPHIDs); | ||||
} else { | } else { | ||||
$where[] = qsprintf( | $where[] = qsprintf( | ||||
$conn, | $conn, | ||||
'customPHID IS NULL'); | 'config.customPHID IS NULL'); | ||||
} | |||||
} | } | ||||
if ($this->affectedObjectPHIDs !== null) { | |||||
$where[] = qsprintf( | |||||
$conn, | |||||
'affected.dst IN (%Ls)', | |||||
$this->affectedObjectPHIDs); | |||||
} | } | ||||
return $where; | return $where; | ||||
} | } | ||||
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { | |||||
$joins = parent::buildJoinClauseParts($conn); | |||||
if ($this->affectedObjectPHIDs !== null) { | |||||
$joins[] = qsprintf( | |||||
$conn, | |||||
'JOIN %T affected ON affected.src = config.phid | |||||
AND affected.type = %d', | |||||
PhabricatorEdgeConfig::TABLE_NAME_EDGE, | |||||
PhabricatorProfileMenuItemAffectsObjectEdgeType::EDGECONST); | |||||
} | |||||
return $joins; | |||||
} | |||||
protected function willFilterPage(array $page) { | protected function willFilterPage(array $page) { | ||||
$items = PhabricatorProfileMenuItem::getAllMenuItems(); | $items = PhabricatorProfileMenuItem::getAllMenuItems(); | ||||
foreach ($page as $key => $item) { | foreach ($page as $key => $item) { | ||||
$item_type = idx($items, $item->getMenuItemKey()); | $item_type = idx($items, $item->getMenuItemKey()); | ||||
if (!$item_type) { | if (!$item_type) { | ||||
$this->didRejectResult($item); | $this->didRejectResult($item); | ||||
unset($page[$key]); | unset($page[$key]); | ||||
continue; | continue; | ||||
Show All 29 Lines | protected function willFilterPage(array $page) { | ||||
return $page; | return $page; | ||||
} | } | ||||
public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
return 'PhabricatorSearchApplication'; | return 'PhabricatorSearchApplication'; | ||||
} | } | ||||
protected function getPrimaryTableAlias() { | |||||
return 'config'; | |||||
} | |||||
} | } |