MDL-43169 core_calendar: introduced calendar type system setting (Backport of MDL-42932)

This commit is contained in:
Mark Nelson
2014-02-16 13:52:57 -08:00
parent 27ebbdd703
commit ce7c5de2e9
7 changed files with 41 additions and 4 deletions
+25 -3
View File
@@ -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);