public function newValueForUsers($key, array $users) { $viewer = $this->getViewer(); $users = mpull($users, null, 'getPHID'); $user_phids = array_keys($users); $preferences = id(new PhabricatorUserPreferencesQuery())->setViewer($viewer)->withUsers($users)->needSyntheticPreferences(true)->execute(); $preferences = mpull($preferences, null, 'getUserPHID'); $all_settings = PhabricatorSetting::getAllSettings(); $settings = array(); foreach ($users as $user_phid => $user) { $preference = idx($preferences, $user_phid); if (!$preference) { continue; } foreach ($all_settings as $key => $setting) { $value = $preference->getSettingValue($key); // As an optimization, we omit the value from the cache if it is // exactly the same as the hardcoded default. $default_value = id(clone $setting)->setViewer($user)->getSettingDefaultValue(); if ($value === $default_value) { continue; } $settings[$user_phid][$key] = $value; } } $results = array(); foreach ($user_phids as $user_phid) { $value = idx($settings, $user_phid, array()); $results[$user_phid] = phutil_json_encode($value); } return $results; }
public final function getPanelSettingsKeys() { $viewer = $this->getViewer(); $settings = PhabricatorSetting::getAllEnabledSettings($viewer); $this_key = $this->getPanelKey(); $panel_settings = array(); foreach ($settings as $setting) { if ($setting->getSettingPanelKey() == $this_key) { $panel_settings[] = $setting; } } return mpull($panel_settings, 'getSettingKey'); }
public function getUserSetting($key) { // NOTE: We store available keys and cached values separately to make it // faster to check for `null` in the cache, which is common. if (isset($this->settingCacheKeys[$key])) { return $this->settingCache[$key]; } $settings_key = PhabricatorUserPreferencesCacheType::KEY_PREFERENCES; if ($this->getPHID()) { $settings = $this->requireCacheData($settings_key); } else { $settings = array(); } // NOTE: To slightly improve performance, we're using all settings here, // not just settings that are enabled for the current viewer. It's fine to // get the value of a setting that we wouldn't let the user edit in the UI. $defaults = PhabricatorSetting::getAllSettings(); if (array_key_exists($key, $settings)) { $value = $settings[$key]; // Make sure the value is valid before we return it. This makes things // more robust when options are changed or removed. if (isset($defaults[$key])) { try { id(clone $defaults[$key])->setViewer($this)->assertValidValue($value); return $this->writeUserSettingCache($key, $value); } catch (Exception $ex) { // Fall through below and return the default value. } } else { // This is an ad-hoc setting with no controlling object. return $this->writeUserSettingCache($key, $value); } } if (isset($defaults[$key])) { $value = id(clone $defaults[$key])->setViewer($this)->getSettingDefaultValue(); } else { $value = null; } return $this->writeUserSettingCache($key, $value); }
private static function getSettingObject($key) { $settings = PhabricatorSetting::getAllSettings(); return idx($settings, $key); }
protected function buildCustomEditFields($object) { $viewer = $this->getViewer(); $settings = PhabricatorSetting::getAllEnabledSettings($viewer); foreach ($settings as $key => $setting) { $setting = clone $setting; $setting->setViewer($viewer); $settings[$key] = $setting; } $settings = msortv($settings, 'getSettingOrderVector'); $fields = array(); foreach ($settings as $setting) { foreach ($setting->newCustomEditFields($object) as $field) { $fields[] = $field; } } return $fields; }
private function getSettings() { $actor = $this->getActor(); $settings = PhabricatorSetting::getAllEnabledSettings($actor); foreach ($settings as $key => $setting) { $setting = clone $setting; $setting->setViewer($actor); $settings[$key] = $setting; } return $settings; }