Changeset View
Changeset View
Standalone View
Standalone View
src/applications/settings/query/PhabricatorUserPreferencesQuery.php
| <?php | <?php | ||||
| final class PhabricatorUserPreferencesQuery | final class PhabricatorUserPreferencesQuery | ||||
| extends PhabricatorCursorPagedPolicyAwareQuery { | extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
| private $ids; | private $ids; | ||||
| private $phids; | private $phids; | ||||
| private $userPHIDs; | private $userPHIDs; | ||||
| private $builtinKeys; | |||||
| private $hasUserPHID; | |||||
| private $users = array(); | private $users = array(); | ||||
| 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 withHasUserPHID($is_user) { | |||||
| $this->hasUserPHID = $is_user; | |||||
| return $this; | |||||
| } | |||||
| public function withUserPHIDs(array $phids) { | public function withUserPHIDs(array $phids) { | ||||
| $this->userPHIDs = $phids; | $this->userPHIDs = $phids; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withUsers(array $users) { | public function withUsers(array $users) { | ||||
| assert_instances_of($users, 'PhabricatorUser'); | assert_instances_of($users, 'PhabricatorUser'); | ||||
| $this->users = mpull($users, null, 'getPHID'); | $this->users = mpull($users, null, 'getPHID'); | ||||
| $this->withUserPHIDs(array_keys($this->users)); | $this->withUserPHIDs(array_keys($this->users)); | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function withBuiltinKeys(array $keys) { | |||||
| $this->builtinKeys = $keys; | |||||
| return $this; | |||||
| } | |||||
| public function newResultObject() { | public function newResultObject() { | ||||
| return new PhabricatorUserPreferences(); | return new PhabricatorUserPreferences(); | ||||
| } | } | ||||
| protected function loadPage() { | protected function loadPage() { | ||||
| return $this->loadStandardPage($this->newResultObject()); | return $this->loadStandardPage($this->newResultObject()); | ||||
| } | } | ||||
| Show All 18 Lines | if ($user_phids) { | ||||
| ->execute(); | ->execute(); | ||||
| $load_users = mpull($load_users, null, 'getPHID'); | $load_users = mpull($load_users, null, 'getPHID'); | ||||
| $users += $load_users; | $users += $load_users; | ||||
| } | } | ||||
| } else { | } else { | ||||
| $users = array(); | $users = array(); | ||||
| } | } | ||||
| $need_global = array(); | |||||
| foreach ($prefs as $key => $pref) { | foreach ($prefs as $key => $pref) { | ||||
| $user_phid = $pref->getUserPHID(); | $user_phid = $pref->getUserPHID(); | ||||
| if (!$user_phid) { | if (!$user_phid) { | ||||
| $pref->attachUser(null); | $pref->attachUser(null); | ||||
| continue; | continue; | ||||
| } | } | ||||
| $need_global[] = $pref; | |||||
| $user = idx($users, $user_phid); | $user = idx($users, $user_phid); | ||||
| if (!$user) { | if (!$user) { | ||||
| $this->didRejectResult($pref); | $this->didRejectResult($pref); | ||||
| unset($prefs[$key]); | unset($prefs[$key]); | ||||
| continue; | continue; | ||||
| } | } | ||||
| $pref->attachUser($user); | $pref->attachUser($user); | ||||
| } | } | ||||
| // If we loaded any user preferences, load the global defaults and attach | |||||
| // them if they exist. | |||||
| if ($need_global) { | |||||
| $global = id(new self()) | |||||
| ->setViewer($this->getViewer()) | |||||
| ->withBuiltinKeys( | |||||
| array( | |||||
| PhabricatorUserPreferences::BUILTIN_GLOBAL_DEFAULT, | |||||
| )) | |||||
| ->executeOne(); | |||||
| if ($global) { | |||||
| foreach ($need_global as $pref) { | |||||
| $pref->attachDefaultSettings($global); | |||||
| } | |||||
| } | |||||
| } | |||||
| return $prefs; | return $prefs; | ||||
| } | } | ||||
| 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( | ||||
| Show All 11 Lines | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
| if ($this->userPHIDs !== null) { | if ($this->userPHIDs !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'userPHID IN (%Ls)', | 'userPHID IN (%Ls)', | ||||
| $this->userPHIDs); | $this->userPHIDs); | ||||
| } | } | ||||
| if ($this->builtinKeys !== null) { | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'builtinKey IN (%Ls)', | |||||
| $this->builtinKeys); | |||||
| } | |||||
| if ($this->hasUserPHID !== null) { | |||||
| if ($this->hasUserPHID) { | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'userPHID IS NOT NULL'); | |||||
| } else { | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'userPHID IS NULL'); | |||||
| } | |||||
| } | |||||
| return $where; | return $where; | ||||
| } | } | ||||
| public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
| return 'PhabricatorSettingsApplication'; | return 'PhabricatorSettingsApplication'; | ||||
| } | } | ||||
| } | } | ||||