mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
quiz: MDL-16478 Allow different open/close dates, etc. for individual students or groups.
This was implemented by Matt Petro of the University of Wisconsin - Madison Engineering School and Math Department. Many thanks. Reviewed by and committed by Tim Hunt. This adds a new Overrides tab to the UI, with sub-tabs Group overrides and User overrides. Each of those lists all the overrides that currently exist, and lets you manage them and create more. When a quiz is being attempted, the override that applies to the current user is combined with the current quiz settings loaded from the quiz table (normally called $quiz). If there are both user and group overrides, then just the specific user override is used (more specific). If the user is in several groups, then the overrides are combined to give the most permissive set of options. There is one new database table quiz_overrides, to store the overrides.
This commit is contained in:
parent
cdede6fbfe
commit
990650f94c
25 changed files with 1309 additions and 127 deletions
|
@ -113,6 +113,8 @@
|
|||
$status = quiz_question_instances_restore_mods($newid,$info,$restore);
|
||||
//We have to restore the feedback now (course level table)
|
||||
$status = quiz_feedback_restore_mods($newid, $info, $restore, $quiz);
|
||||
//We have to restore the overrides now (course level table)
|
||||
$status = quiz_overrides_restore_mods($newid, $info, $restore, $quiz);
|
||||
//Now check if want to restore user data and do it.
|
||||
if (restore_userdata_selected($restore,'quiz',$mod->id)) {
|
||||
//Restore quiz_attempts
|
||||
|
@ -241,6 +243,78 @@
|
|||
return $status;
|
||||
}
|
||||
|
||||
//This function restores the quiz_overrides
|
||||
function quiz_overrides_restore_mods($quiz_id, $info, $restore, $quiz) {
|
||||
global $DB;
|
||||
|
||||
$douserdata = restore_userdata_selected($restore,'quiz',$quiz_id);
|
||||
|
||||
$status = true;
|
||||
|
||||
//Get the quiz_feedback array
|
||||
if (array_key_exists('OVERRIDES', $info['MOD']['#'])) {
|
||||
$overrides = $info['MOD']['#']['OVERRIDES']['0']['#']['OVERRIDE'];
|
||||
|
||||
//Iterate over the feedbacks
|
||||
foreach ($overrides as $override_info) {
|
||||
//traverse_xmlize($override_info); //Debug
|
||||
//print_object ($GLOBALS['traverse_array']); //Debug
|
||||
//$GLOBALS['traverse_array']=""; //Debug
|
||||
|
||||
//We'll need this later!!
|
||||
$oldid = backup_todb($override_info['#']['ID']['0']['#']);
|
||||
|
||||
//Now, build the quiz_overrides record structure
|
||||
$override = new stdClass();
|
||||
$override->quiz = $quiz_id;
|
||||
$override->groupid = backup_todb($override_info['#']['GROUPID']['0']['#']);
|
||||
$override->userid = backup_todb($override_info['#']['USERID']['0']['#']);
|
||||
$override->timeopen = backup_todb($override_info['#']['TIMEOPEN']['0']['#']);
|
||||
$override->timeclose = backup_todb($override_info['#']['TIMECLOSE']['0']['#']);
|
||||
$override->timelimit = backup_todb($override_info['#']['TIMELIMIT']['0']['#']);
|
||||
$override->attempts = backup_todb($override_info['#']['ATTEMPTS']['0']['#']);
|
||||
$override->password = backup_todb($override_info['#']['PASSWORD']['0']['#']);
|
||||
|
||||
// Only restore user overrides if we are restoring user data
|
||||
if ($douserdata || $override->userid == 0) {
|
||||
|
||||
//We have to recode the userid field
|
||||
if ($override->userid) {
|
||||
if (!$user = backup_getid($restore->backup_unique_code,"user",$override->userid)) {
|
||||
debugging("override can not be restored, user id $override->userid not present in backup");
|
||||
// do not not block the restore
|
||||
continue;
|
||||
}
|
||||
$override->userid = $user->new_id;
|
||||
|
||||
}
|
||||
|
||||
//We have to recode the groupid field
|
||||
if ($override->groupid) {
|
||||
if (!$group = backup_getid($restore->backup_unique_code,"groups",$override->groupid)) {
|
||||
debugging("override can not be restored, group id $override->groupid not present in backup");
|
||||
// do not not block the restore
|
||||
continue;
|
||||
}
|
||||
$override->groupid = $group->new_id;
|
||||
}
|
||||
|
||||
//The structure is equal to the db, so insert the quiz_question_instances
|
||||
$newid = $DB->insert_record('quiz_overrides', $override);
|
||||
|
||||
if ($newid) {
|
||||
//We have the newid, update backup_ids
|
||||
backup_putid($restore->backup_unique_code, 'quiz_overrides', $oldid, $newid);
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
//This function restores the quiz_attempts
|
||||
function quiz_attempts_restore_mods($quiz_id,$info,$restore) {
|
||||
global $CFG, $DB;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue