MDL-49828 timezones: improve settings performance

This commit is contained in:
Petr Skoda
2015-04-12 12:38:06 +12:00
parent 75a1e85e3a
commit 91bafd76f5
2 changed files with 82 additions and 20 deletions
+2 -20
View File
@@ -4,26 +4,8 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
// "locations" settingpage
$temp = new admin_settingpage('locationsettings', new lang_string('locationsettings', 'admin'));
$current = isset($CFG->timezone) ? $CFG->timezone : null;
$options = core_date::get_list_of_timezones($current, false);
$default = core_date::get_default_php_timezone();
if ($current == 99) {
// Do not show 99 unless it is current value, we want to get rid of it over time.
$options['99'] = new lang_string('timezonephpdefault', 'core_admin', $default);
}
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';
}
$temp->add(new admin_setting_configselect('timezone', new lang_string('timezone', 'admin'),
new lang_string('configtimezone', 'admin'), $default, $options));
$options = core_date::get_list_of_timezones(isset($CFG->forcetimezone) ? $CFG->forcetimezone : null, true);
$options[99] = new lang_string('timezonenotforced', 'admin');
$temp->add(new admin_setting_configselect('forcetimezone', new lang_string('forcetimezone', 'admin'),
new lang_string('helpforcetimezone', 'admin'), 99, $options));
$temp->add(new admin_setting_servertimezone());
$temp->add(new admin_setting_forcetimezone());
$temp->add(new admin_settings_country_select('country', new lang_string('country', 'admin'), new lang_string('configcountry', 'admin'), 0));
$temp->add(new admin_setting_configtext('defaultcity', new lang_string('defaultcity', 'admin'), new lang_string('defaultcity_help', 'admin'), ''));
+80
View File
@@ -8997,3 +8997,83 @@ class admin_setting_php_extension_enabled extends admin_setting {
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 <petr.skoda@totaralms.com>
*/
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 <petr.skoda@totaralms.com>
*/
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;
}
}