summaryrefslogtreecommitdiff
path: root/app/php/controls/TimezoneSelect.php
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-04-06 13:50:31 +0200
committeremkael <emkael@tlen.pl>2016-04-06 13:51:23 +0200
commitdfe234a7aaaacedcc94716f955b44a1b50c4a057 (patch)
tree3c16b945b65a654d6dd63421250fb2bb496cd1f2 /app/php/controls/TimezoneSelect.php
parentfd7b7aa1bade514a87667ff90b94dc3050f68560 (diff)
* components -> controls
Diffstat (limited to 'app/php/controls/TimezoneSelect.php')
-rw-r--r--app/php/controls/TimezoneSelect.php49
1 files changed, 49 insertions, 0 deletions
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 @@
+<?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(
+ '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;
+ }
+
+}
+
+?>