blob: 3302e2aa6649dd8a5579b9974eb10cfa238aa8a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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;
}
}
?>
|