From dfe234a7aaaacedcc94716f955b44a1b50c4a057 Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 6 Apr 2016 13:50:31 +0200 Subject: * components -> controls --- app/php/controls/TimezoneSelect.php | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 app/php/controls/TimezoneSelect.php (limited to 'app/php/controls/TimezoneSelect.php') diff --git a/app/php/controls/TimezoneSelect.php b/app/php/controls/TimezoneSelect.php new file mode 100644 index 0000000..3302e2a --- /dev/null +++ b/app/php/controls/TimezoneSelect.php @@ -0,0 +1,49 @@ +getControlState('user'); + } + + public function setUserToChange(DbUser $user) { + if ($user->IsGuest) { + throw new TInvalidDataValueException( + 'Timezone preference 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->setTimezonePreference($this->Timezones->SelectedValue); + } + + private function _getTimezones() { + $timezones = array_map( + function($tz) { + return new TimezoneDTO($tz); + }, + DateTimeZone::listIdentifiers() + ); + usort($timezones, ['TimezoneDTO', '__compare']); + return $timezones; + } + +} + +?> -- cgit v1.2.3