summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/php/components/TimezoneSelect.php52
-rw-r--r--app/php/components/TimezoneSelect.tpl4
-rw-r--r--app/php/pages/Profile.page4
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>