forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-49828 timezones: improve settings performance
- Loading branch information
Petr Skoda
committed
Apr 12, 2015
1 parent
75a1e85
commit 91bafd7
Showing
2 changed files
with
82 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8997,3 +8997,83 @@ public function output_html($data, $query='') { | |
return $o; | ||
} | ||
} | ||
|
||
/** | ||
* Server timezone setting. | ||
* | ||
* @copyright 2015 Totara Learning Solutions Ltd {@link http://www.totaralms.com/} | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @author Petr Skoda <[email protected]> | ||
*/ | ||
class admin_setting_servertimezone extends admin_setting_configselect { | ||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() { | ||
$default = core_date::get_default_php_timezone(); | ||
if ($default === 'UTC') { | ||
// Nobody really wants UTC, so instead default selection to the country that is confused by the UTC the most. | ||
$default = 'Europe/London'; | ||
} | ||
|
||
parent::__construct('timezone', | ||
new lang_string('timezone', 'core_admin'), | ||
new lang_string('configtimezone', 'core_admin'), $default, null); | ||
} | ||
|
||
/** | ||
* Lazy load timezone options. | ||
* @return bool true if loaded, false if error | ||
*/ | ||
public function load_choices() { | ||
global $CFG; | ||
if (is_array($this->choices)) { | ||
return true; | ||
} | ||
|
||
$current = isset($CFG->timezone) ? $CFG->timezone : null; | ||
$this->choices = core_date::get_list_of_timezones($current, false); | ||
if ($current == 99) { | ||
// Do not show 99 unless it is current value, we want to get rid of it over time. | ||
$this->choices['99'] = new lang_string('timezonephpdefault', 'core_admin', | ||
core_date::get_default_php_timezone()); | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
/** | ||
* Forced user timezone setting. | ||
* | ||
* @copyright 2015 Totara Learning Solutions Ltd {@link http://www.totaralms.com/} | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @author Petr Skoda <[email protected]> | ||
*/ | ||
class admin_setting_forcetimezone extends admin_setting_configselect { | ||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() { | ||
parent::__construct('forcetimezone', | ||
new lang_string('forcetimezone', 'core_admin'), | ||
new lang_string('helpforcetimezone', 'core_admin'), '99', null); | ||
} | ||
|
||
/** | ||
* Lazy load timezone options. | ||
* @return bool true if loaded, false if error | ||
*/ | ||
public function load_choices() { | ||
global $CFG; | ||
if (is_array($this->choices)) { | ||
return true; | ||
} | ||
|
||
$current = isset($CFG->forcetimezone) ? $CFG->forcetimezone : null; | ||
$this->choices = core_date::get_list_of_timezones($current, true); | ||
$this->choices['99'] = new lang_string('timezonenotforced', 'core_admin'); | ||
|
||
return true; | ||
} | ||
} |