Permalink
Browse files

MDL-43169 core_calendar: introduced calendar type system setting (Bac…

…kport of MDL-42932)
  • Loading branch information...
1 parent 27ebbdd commit ce7c5de2e9b7f42e86c007c30fb63596ecdb0792 @markn86 markn86 committed Nov 16, 2013
Showing with 41 additions and 4 deletions.
  1. +4 −1 admin/settings/appearance.php
  2. +3 −0 auth/db/auth.php
  3. +3 −0 auth/email/auth.php
  4. +3 −0 auth/ldap/auth.php
  5. +2 −0 lang/en/admin.php
  6. +1 −0 user/editlib.php
  7. +25 −3 user/lib.php
@@ -41,8 +41,11 @@
}
- // calendar
+ // Calendar settings.
$temp = new admin_settingpage('calendar', new lang_string('calendarsettings','admin'));
+
+ $temp->add(new admin_setting_configselect('calendartype', new lang_string('calendartype', 'admin'),
+ new lang_string('calendartype_desc', 'admin'), 'gregorian', \core_calendar\type_factory::get_list_of_calendar_types()));
$temp->add(new admin_setting_special_adminseesall());
//this is hacky because we do not want to include the stuff from calendar/lib.php
$temp->add(new admin_setting_configselect('calendar_site_timeformat', new lang_string('pref_timeformat', 'calendar'),
View
@@ -399,6 +399,9 @@ function sync_users(progress_trace $trace, $do_updates=false) {
if (empty($user->lang)) {
$user->lang = $CFG->lang;
}
+ if (empty($user->calendartype)) {
+ $user->calendartype = $CFG->calendartype;
+ }
$user->timecreated = time();
$user->timemodified = $user->timecreated;
if ($collision = $DB->get_record_select('user', "username = :username AND mnethostid = :mnethostid AND auth <> :auth", array('username'=>$user->username, 'mnethostid'=>$CFG->mnet_localhost_id, 'auth'=>$this->authtype), 'id,username,auth')) {
View
@@ -90,6 +90,9 @@ function user_signup($user, $notify=true) {
require_once($CFG->dirroot.'/user/lib.php');
$user->password = hash_internal_user_password($user->password);
+ if (empty($user->calendartype)) {
+ $user->calendartype = $CFG->calendartype;
+ }
$user->id = user_create_user($user, false);
View
@@ -944,6 +944,9 @@ function sync_users($do_updates=true) {
if (empty($user->lang)) {
$user->lang = $CFG->lang;
}
+ if (empty($user->calendartype)) {
+ $user->calendartype = $CFG->calendartype;
+ }
$id = user_create_user($user, false);
echo "\t"; print_string('auth_dbinsertuser', 'auth_db', array('name'=>$user->username, 'id'=>$id)); echo "\n";
View
@@ -95,6 +95,8 @@
$string['cachetext'] = 'Text cache lifetime';
$string['calendarexportsalt'] = 'Calendar export salt';
$string['calendarsettings'] = 'Calendar';
+$string['calendartype'] = 'Calendar type';
+$string['calendartype_desc'] = 'Choose a default calendar type for the whole site. This setting can be overridden in the course settings or by users in their personal profile.';
$string['calendar_weekend'] = 'Weekend days';
$string['cannotdeletemodfilter'] = 'You cannot uninstall the \'{$a->filter}\' because it is part of the \'{$a->module}\' module.';
$string['cannotuninstall'] = '{$a} can not be uninstalled.';
View
@@ -251,6 +251,7 @@ function useredit_shared_definition(&$mform, $editoroptions = null, $filemanager
// We do not want to show this option unless there is more than one calendar type to display.
if (count($calendartypes) > 1) {
$mform->addElement('select', 'calendartype', get_string('preferredcalendar', 'calendar'), $calendartypes);
+ $mform->setDefault('calendartype', $CFG->calendartype);
}
if (!empty($CFG->allowuserthemes)) {
View
@@ -33,11 +33,11 @@
* @return int id of the newly created user
*/
function user_create_user($user, $updatepassword = true) {
- global $DB;
+ global $CFG, $DB;
// Set the timecreate field to the current time.
if (!is_object($user)) {
- $user = (object)$user;
+ $user = (object) $user;
}
// Check username.
@@ -61,6 +61,16 @@ function user_create_user($user, $updatepassword = true) {
unset($user->password);
}
+ // Make sure calendartype, if set, is valid.
+ if (!empty($user->calendartype)) {
+ $availablecalendartypes = \core_calendar\type_factory::get_list_of_calendar_types();
+ if (empty($availablecalendartypes[$user->calendartype])) {
+ $user->calendartype = $CFG->calendartype;
+ }
+ } else {
+ $user->calendartype = $CFG->calendartype;
+ }
+
$user->timecreated = time();
$user->timemodified = $user->timecreated;
@@ -101,7 +111,7 @@ function user_update_user($user, $updatepassword = true) {
// set the timecreate field to the current time
if (!is_object($user)) {
- $user = (object)$user;
+ $user = (object) $user;
}
//check username
@@ -127,6 +137,18 @@ function user_update_user($user, $updatepassword = true) {
unset($user->password);
}
+ // Make sure calendartype, if set, is valid.
+ if (!empty($user->calendartype)) {
+ $availablecalendartypes = \core_calendar\type_factory::get_list_of_calendar_types();
+ // If it doesn't exist, then unset this value, we do not want to update the user's value.
+ if (empty($availablecalendartypes[$user->calendartype])) {
+ unset($user->calendartype);
+ }
+ } else {
+ // Unset this variable, must be an empty string, which we do not want to update the calendartype to.
+ unset($user->calendartype);
+ }
+
$user->timemodified = time();
$DB->update_record('user', $user);

0 comments on commit ce7c5de

Please sign in to comment.