[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorSettingsPanelAccount 4 extends PhabricatorSettingsPanel { 5 6 public function getPanelKey() { 7 return 'account'; 8 } 9 10 public function getPanelName() { 11 return pht('Account'); 12 } 13 14 public function getPanelGroup() { 15 return pht('Account Information'); 16 } 17 18 public function processRequest(AphrontRequest $request) { 19 $user = $request->getUser(); 20 $username = $user->getUsername(); 21 22 $pref_time = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT; 23 $preferences = $user->loadPreferences(); 24 25 $errors = array(); 26 if ($request->isFormPost()) { 27 $new_timezone = $request->getStr('timezone'); 28 if (in_array($new_timezone, DateTimeZone::listIdentifiers(), true)) { 29 $user->setTimezoneIdentifier($new_timezone); 30 } else { 31 $errors[] = pht('The selected timezone is not a valid timezone.'); 32 } 33 34 $sex = $request->getStr('sex'); 35 $sexes = array(PhutilPerson::SEX_MALE, PhutilPerson::SEX_FEMALE); 36 if (in_array($sex, $sexes)) { 37 $user->setSex($sex); 38 } else { 39 $user->setSex(null); 40 } 41 42 // Checked in runtime. 43 $user->setTranslation($request->getStr('translation')); 44 45 $preferences->setPreference($pref_time, $request->getStr($pref_time)); 46 47 if (!$errors) { 48 $preferences->save(); 49 $user->save(); 50 return id(new AphrontRedirectResponse()) 51 ->setURI($this->getPanelURI('?saved=true')); 52 } 53 } 54 55 $timezone_ids = DateTimeZone::listIdentifiers(); 56 $timezone_id_map = array_fuse($timezone_ids); 57 58 $label_unknown = pht('%s updated their profile', $username); 59 $label_her = pht('%s updated her profile', $username); 60 $label_his = pht('%s updated his profile', $username); 61 62 $sexes = array( 63 PhutilPerson::SEX_UNKNOWN => $label_unknown, 64 PhutilPerson::SEX_MALE => $label_his, 65 PhutilPerson::SEX_FEMALE => $label_her, 66 ); 67 68 $translations = array(); 69 $symbols = id(new PhutilSymbolLoader()) 70 ->setType('class') 71 ->setAncestorClass('PhabricatorTranslation') 72 ->setConcreteOnly(true) 73 ->selectAndLoadSymbols(); 74 foreach ($symbols as $symbol) { 75 $class = $symbol['name']; 76 $translations[$class] = newv($class, array())->getName(); 77 } 78 asort($translations); 79 $default = PhabricatorEnv::newObjectFromConfig('translation.provider'); 80 $translations = array( 81 '' => pht('Server Default (%s)', $default->getName()), 82 ) + $translations; 83 84 $form = new AphrontFormView(); 85 $form 86 ->setUser($user) 87 ->appendChild( 88 id(new AphrontFormSelectControl()) 89 ->setLabel(pht('Timezone')) 90 ->setName('timezone') 91 ->setOptions($timezone_id_map) 92 ->setValue($user->getTimezoneIdentifier())) 93 ->appendRemarkupInstructions(pht('**Choose the pronoun you prefer:**')) 94 ->appendChild( 95 id(new AphrontFormSelectControl()) 96 ->setOptions($sexes) 97 ->setLabel(pht('Pronoun')) 98 ->setName('sex') 99 ->setValue($user->getSex())) 100 ->appendChild( 101 id(new AphrontFormSelectControl()) 102 ->setOptions($translations) 103 ->setLabel(pht('Translation')) 104 ->setName('translation') 105 ->setValue($user->getTranslation())) 106 ->appendRemarkupInstructions( 107 pht( 108 "**Custom Date and Time Formats**\n\n". 109 "You can specify custom formats which will be used when ". 110 "rendering dates and times of day. Examples:\n\n". 111 "| Format | Example | Notes |\n". 112 "| ------ | -------- | ----- |\n". 113 "| `g:i A` | 2:34 PM | Default 12-hour time. |\n". 114 "| `G.i a` | 02.34 pm | Alternate 12-hour time. |\n". 115 "| `H:i` | 14:34 | 24-hour time. |\n". 116 "\n\n". 117 "You can find a [[%s | full reference in the PHP manual]].", 118 'http://www.php.net/manual/en/function.date.php')) 119 ->appendChild( 120 id(new AphrontFormTextControl()) 121 ->setLabel(pht('Time-of-Day Format')) 122 ->setName($pref_time) 123 ->setCaption( 124 pht('Format used when rendering a time of day.')) 125 ->setValue($preferences->getPreference($pref_time))) 126 ->appendChild( 127 id(new AphrontFormSubmitControl()) 128 ->setValue(pht('Save Account Settings'))); 129 130 $form_box = id(new PHUIObjectBoxView()) 131 ->setHeaderText(pht('Account Settings')) 132 ->setFormSaved($request->getStr('saved')) 133 ->setFormErrors($errors) 134 ->setForm($form); 135 136 return array( 137 $form_box, 138 ); 139 } 140 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |