Changeset View
Changeset View
Standalone View
Standalone View
src/applications/settings/panel/PhabricatorDateTimeSettingsPanel.php
| Show All 12 Lines | final class PhabricatorDateTimeSettingsPanel extends PhabricatorSettingsPanel { | ||||
| public function getPanelGroup() { | public function getPanelGroup() { | ||||
| return pht('Account Information'); | return pht('Account Information'); | ||||
| } | } | ||||
| public function processRequest(AphrontRequest $request) { | public function processRequest(AphrontRequest $request) { | ||||
| $user = $request->getUser(); | $user = $request->getUser(); | ||||
| $username = $user->getUsername(); | $username = $user->getUsername(); | ||||
| $space_phid = $user->getDefaultSpacePHID(); | |||||
| $pref_event_space = PhabricatorUserPreferences::PREFERENCE_CALENDAR_SPACE; | |||||
| $pref_time = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT; | $pref_time = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT; | ||||
| $pref_date = PhabricatorUserPreferences::PREFERENCE_DATE_FORMAT; | $pref_date = PhabricatorUserPreferences::PREFERENCE_DATE_FORMAT; | ||||
| $pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY; | $pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY; | ||||
| $preferences = $user->loadPreferences(); | $preferences = $user->loadPreferences(); | ||||
| $errors = array(); | $errors = array(); | ||||
| if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
| $new_timezone = $request->getStr('timezone'); | $new_timezone = $request->getStr('timezone'); | ||||
| if (in_array($new_timezone, DateTimeZone::listIdentifiers(), true)) { | if (in_array($new_timezone, DateTimeZone::listIdentifiers(), true)) { | ||||
| $user->setTimezoneIdentifier($new_timezone); | $user->setTimezoneIdentifier($new_timezone); | ||||
| } else { | } else { | ||||
| $errors[] = pht('The selected timezone is not a valid timezone.'); | $errors[] = pht('The selected timezone is not a valid timezone.'); | ||||
| } | } | ||||
| $preferences | $preferences | ||||
| ->setPreference( | ->setPreference( | ||||
| $pref_time, | $pref_time, | ||||
| $request->getStr($pref_time)) | $request->getStr($pref_time)) | ||||
| ->setPreference( | ->setPreference( | ||||
| $pref_date, | $pref_date, | ||||
| $request->getStr($pref_date)) | $request->getStr($pref_date)) | ||||
| ->setPreference( | ->setPreference( | ||||
| $pref_week_start, | $pref_week_start, | ||||
| $request->getStr($pref_week_start)); | $request->getStr($pref_week_start)) | ||||
| ->setPreference( | |||||
| $pref_event_space, | |||||
| $request->getStr($pref_event_space)); | |||||
| if (!$errors) { | if (!$errors) { | ||||
| $preferences->save(); | $preferences->save(); | ||||
| $user->save(); | $user->save(); | ||||
| return id(new AphrontRedirectResponse()) | return id(new AphrontRedirectResponse()) | ||||
| ->setURI($this->getPanelURI('?saved=true')); | ->setURI($this->getPanelURI('?saved=true')); | ||||
| } | } | ||||
| } | } | ||||
| Show All 35 Lines | $form | ||||
| ->setValue($preferences->getPreference($pref_date))) | ->setValue($preferences->getPreference($pref_date))) | ||||
| ->appendChild( | ->appendChild( | ||||
| id(new AphrontFormSelectControl()) | id(new AphrontFormSelectControl()) | ||||
| ->setLabel(pht('Week Starts On')) | ->setLabel(pht('Week Starts On')) | ||||
| ->setOptions($this->getWeekDays()) | ->setOptions($this->getWeekDays()) | ||||
| ->setName($pref_week_start) | ->setName($pref_week_start) | ||||
| ->setCaption( | ->setCaption( | ||||
| pht('Calendar weeks will start with this day.')) | pht('Calendar weeks will start with this day.')) | ||||
| ->setValue($preferences->getPreference($pref_week_start, 0))) | ->setValue($preferences->getPreference($pref_week_start, 0))); | ||||
| ->appendChild( | |||||
| if (PhabricatorSpacesNamespaceQuery::getViewerSpacesExist($user)) { | |||||
| $form->appendChild( | |||||
| id(new AphrontFormSelectControl()) | |||||
| ->setOptions( | |||||
| PhabricatorSpacesNamespaceQuery::getSpaceOptionsForViewer( | |||||
| $user, | |||||
| $space_phid)) | |||||
| ->setLabel(pht('Default Calendar Space')) | |||||
| ->setCaption( | |||||
| pht('Calendar events will default to the visibility of '. | |||||
| 'this space.')) | |||||
| ->setName($pref_event_space) | |||||
| ->setValue($preferences->getPreference($pref_event_space))); | |||||
| } | |||||
| $form->appendChild( | |||||
| id(new AphrontFormSubmitControl()) | id(new AphrontFormSubmitControl()) | ||||
| ->setValue(pht('Save Account Settings'))); | ->setValue(pht('Save Account Settings'))); | ||||
| $form_box = id(new PHUIObjectBoxView()) | $form_box = id(new PHUIObjectBoxView()) | ||||
| ->setHeaderText(pht('Date and Time Settings')) | ->setHeaderText(pht('Date and Time Settings')) | ||||
| ->setFormSaved($request->getStr('saved')) | ->setFormSaved($request->getStr('saved')) | ||||
| ->setFormErrors($errors) | ->setFormErrors($errors) | ||||
| ->setForm($form); | ->setForm($form); | ||||
| return array( | return array( | ||||
| Show All 16 Lines | |||||