diff options
author | emkael <emkael@tlen.pl> | 2016-03-16 01:11:37 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2016-03-16 01:11:37 +0100 |
commit | c5058d68713fc710c68488db726b05453e18d85d (patch) | |
tree | b7da9ff24d550d2e3e8172ee6f7a4f7ef2e5c5b8 | |
parent | 81890fab8952f6ee9dcb1f3c0a577472cf7c4fd6 (diff) |
* timezone selection on profile page
-rw-r--r-- | app/php/components/TimezoneSelect.php | 52 | ||||
-rw-r--r-- | app/php/components/TimezoneSelect.tpl | 4 | ||||
-rw-r--r-- | app/php/pages/Profile.page | 4 |
3 files changed, 60 insertions, 0 deletions
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 @@ +<?php + +Prado::using('Application.user.DbUser'); +Prado::using('Application.dto.TimezoneDTO'); + +class TimezoneSelect extends TTemplateControl { + + public function getUserToChange() { + return $this->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 @@ +<com:TDropDownList ID="Timezones" /> +<com:TButton + Text="Save timezone" + OnCommand="saveTimezone" /> 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 @@ <prop:UserToChange><%= $this->User %></prop:UserToChange> </com:PasswordChange> <br /> + <com:TimezoneSelect> + <prop:UserToChange><%= $this->User %></prop:UserToChange> + </com:TimezoneSelect> + <br /> <com:UserSelection> <prop:UserToDisplay><%= $this->User %></prop:UserToDisplay> </com:UserSelection> |