summaryrefslogtreecommitdiff
path: root/app/php/components/TimezoneSelect.php
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-03-16 01:11:37 +0100
committeremkael <emkael@tlen.pl>2016-03-16 01:11:37 +0100
commitc5058d68713fc710c68488db726b05453e18d85d (patch)
treeb7da9ff24d550d2e3e8172ee6f7a4f7ef2e5c5b8 /app/php/components/TimezoneSelect.php
parent81890fab8952f6ee9dcb1f3c0a577472cf7c4fd6 (diff)
* timezone selection on profile page
Diffstat (limited to 'app/php/components/TimezoneSelect.php')
-rw-r--r--app/php/components/TimezoneSelect.php52
1 files changed, 52 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;
+ }
+
+}
+
+?>