From c5058d68713fc710c68488db726b05453e18d85d Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 16 Mar 2016 01:11:37 +0100 Subject: * timezone selection on profile page --- app/php/components/TimezoneSelect.php | 52 +++++++++++++++++++++++++++++++++++ app/php/components/TimezoneSelect.tpl | 4 +++ app/php/pages/Profile.page | 4 +++ 3 files changed, 60 insertions(+) create mode 100644 app/php/components/TimezoneSelect.php create mode 100644 app/php/components/TimezoneSelect.tpl diff --git a/app/php/components/TimezoneSelect.php b/app/php/components/TimezoneSelect.php new file mode 100644 index 0000000..d97514f --- /dev/null +++ b/app/php/components/TimezoneSelect.php @@ -0,0 +1,52 @@ +getControlState('user'); + } + + public function setUserToChange(DbUser $user) { + if ($user->IsGuest) { + throw new TInvalidDataValueException('Password change impossible for guest user'); + } + $this->setControlState('user', $user); + } + + public function onPreRender($param) { + parent::onPreRender($param); + $this->Timezones->DataSource = $this->_getTimezones(); + $this->Timezones->DataValueField = 'Name'; + $this->Timezones->DataTextField = 'Label'; + $this->Timezones->dataBind(); + $this->Timezones->setSelectedValue($this->UserToChange->getTimezonePreference()->Name); + } + + public function saveTimezone($sender, $param) { + $this->UserToChange->DbRecord->Timezone = $this->Timezones->SelectedValue; + $this->UserToChange->DbRecord->save(); + } + + private function _getTimezones() { + $timezones = array_map( + function($tz) { + return new TimezoneDTO($tz); + }, + DateTimeZone::listIdentifiers() + ); + usort( + $timezones, + function($tz1, $tz2) { + $diff = $tz1->Offset - $tz2->Offset; + return ($diff == 0) ? strcmp($tz1->Name, $tz2->Name) : $diff; + } + ); + return $timezones; + } + +} + +?> diff --git a/app/php/components/TimezoneSelect.tpl b/app/php/components/TimezoneSelect.tpl new file mode 100644 index 0000000..38d6bad --- /dev/null +++ b/app/php/components/TimezoneSelect.tpl @@ -0,0 +1,4 @@ + + diff --git a/app/php/pages/Profile.page b/app/php/pages/Profile.page index 0cd3dd3..1b11977 100644 --- a/app/php/pages/Profile.page +++ b/app/php/pages/Profile.page @@ -3,6 +3,10 @@ <%= $this->User %>
+ + <%= $this->User %> + +
<%= $this->User %> -- cgit v1.2.3