2011-07-18 17:02:00 +02:00
|
|
|
<?php
|
|
|
|
|
2012-08-13 21:37:26 +02:00
|
|
|
final class PhabricatorSettingsPanelAccount
|
|
|
|
extends PhabricatorSettingsPanel {
|
2011-07-18 17:02:00 +02:00
|
|
|
|
2012-08-13 21:37:26 +02:00
|
|
|
public function getPanelKey() {
|
|
|
|
return 'account';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPanelName() {
|
|
|
|
return pht('Account');
|
|
|
|
}
|
2011-07-18 17:02:00 +02:00
|
|
|
|
2012-08-13 21:37:26 +02:00
|
|
|
public function getPanelGroup() {
|
|
|
|
return pht('Account Information');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest(AphrontRequest $request) {
|
2011-07-18 17:02:00 +02:00
|
|
|
$user = $request->getUser();
|
|
|
|
$errors = array();
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$new_timezone = $request->getStr('timezone');
|
|
|
|
if (in_array($new_timezone, DateTimeZone::listIdentifiers(), true)) {
|
|
|
|
$user->setTimezoneIdentifier($new_timezone);
|
|
|
|
} else {
|
2013-03-03 15:52:42 +01:00
|
|
|
$errors[] = pht('The selected timezone is not a valid timezone.');
|
2011-07-18 17:02:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$errors) {
|
|
|
|
$user->save();
|
|
|
|
return id(new AphrontRedirectResponse())
|
2012-08-13 21:37:26 +02:00
|
|
|
->setURI($this->getPanelURI('?saved=true'));
|
2011-07-18 17:02:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$notice = null;
|
|
|
|
if (!$errors) {
|
|
|
|
if ($request->getStr('saved')) {
|
|
|
|
$notice = new AphrontErrorView();
|
|
|
|
$notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
|
2013-03-03 15:52:42 +01:00
|
|
|
$notice->setTitle(pht('Changes Saved'));
|
2013-02-07 01:53:49 +01:00
|
|
|
$notice->appendChild(
|
2013-03-03 15:52:42 +01:00
|
|
|
phutil_tag('p', array(), pht('Your changes have been saved.')));
|
2011-07-18 17:02:00 +02:00
|
|
|
$notice = $notice->render();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$notice = new AphrontErrorView();
|
2013-03-03 15:52:42 +01:00
|
|
|
$notice->setTitle(pht('Form Errors'));
|
2011-07-18 17:02:00 +02:00
|
|
|
$notice->setErrors($errors);
|
|
|
|
$notice = $notice->render();
|
|
|
|
}
|
|
|
|
|
2011-07-25 00:03:59 +02:00
|
|
|
$timezone_ids = DateTimeZone::listIdentifiers();
|
2013-01-26 02:06:55 +01:00
|
|
|
$timezone_id_map = array_fuse($timezone_ids);
|
2011-07-25 00:03:59 +02:00
|
|
|
|
2011-07-18 17:02:00 +02:00
|
|
|
$form = new AphrontFormView();
|
|
|
|
$form
|
|
|
|
->setUser($user)
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormStaticControl())
|
2013-03-03 15:52:42 +01:00
|
|
|
->setLabel(pht('Username'))
|
2011-07-18 17:02:00 +02:00
|
|
|
->setValue($user->getUsername()))
|
|
|
|
->appendChild(
|
2011-07-25 00:03:59 +02:00
|
|
|
id(new AphrontFormSelectControl())
|
2013-03-03 15:52:42 +01:00
|
|
|
->setLabel(pht('Timezone'))
|
2011-07-25 00:03:59 +02:00
|
|
|
->setName('timezone')
|
|
|
|
->setOptions($timezone_id_map)
|
|
|
|
->setValue($user->getTimezoneIdentifier()))
|
2011-07-18 17:02:00 +02:00
|
|
|
->appendChild(
|
2011-07-25 00:03:59 +02:00
|
|
|
id(new AphrontFormSubmitControl())
|
2013-03-03 15:52:42 +01:00
|
|
|
->setValue(pht('Save')));
|
2011-07-18 17:02:00 +02:00
|
|
|
|
2013-05-08 03:08:12 +02:00
|
|
|
$header = new PhabricatorHeaderView();
|
|
|
|
$header->setHeader(pht('Account Settings'));
|
2011-07-18 17:02:00 +02:00
|
|
|
|
2012-08-13 21:37:26 +02:00
|
|
|
return array(
|
|
|
|
$notice,
|
2013-05-08 03:08:12 +02:00
|
|
|
$header,
|
|
|
|
$form,
|
2012-08-13 21:37:26 +02:00
|
|
|
);
|
2011-07-18 17:02:00 +02:00
|
|
|
}
|
|
|
|
}
|