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 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 app/php/components/TimezoneSelect.php (limited to 'app/php/components/TimezoneSelect.php') 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; + } + +} + +?> -- cgit v1.2.3