backup_putid($restore->backup_unique_code,"quiz_attempts",$oldid,
$newid);
//Now process question_states
- $status = question_states_restore_mods($newid,$att_info,$restore);
+ // This function is defined in question/restorelib.php
+ $status = question_states_restore_mods($attempt->uniqueid,$att_info,$restore);
} else {
$status = false;
}
return $status;
}
+
+ function question_multianswer_recode_answer($state, $restore) {
+ global $recodeansfns;
+ //The answer is a comma separated list of hypen separated multianswer_id and answers. We must recode them.
+ $answer_field = "";
+ $in_first = true;
+ $tok = strtok($state->answer,",");
+ while ($tok) {
+ //Extract the multianswer_id and the answer
+ $exploded = explode("-",$tok);
+ $multianswer_id = $exploded[0];
+ $answer = $exploded[1];
+ //Get the multianswer from backup_ids
+ $mul = backup_getid($restore->backup_unique_code,"question_multianswer",$multianswer_id);
+ if ($mul) {
+ //Now, depending of the answertype field in question_multianswer
+ //we do diferent things
+ $mul_db = get_record ("question_multianswer","id",$mul->new_id);
+ if (isset($recodeansfns[$question->type])) {
+ }
+
+ //Finaly, build the new answer field for each pair
+ if ($in_first) {
+ $answer_field .= $mul->new_id."-".$answer;
+ $in_first = false;
+ } else {
+ $answer_field .= ",".$mul->new_id."-".$answer;
+ }
+ }
+ //check for next
+ $tok = strtok(",");
+ }
+ return $answer_field;
+ }
+
?>
return $status;
}
+
+ function question_multichoice_recode_answer($state, $restore) {
+ $answer_field = "";
+ $in_first = true;
+ $tok = strtok($state->answer,",");
+ while ($tok) {
+ //Get the answer from backup_ids
+ $answer = backup_getid($restore->backup_unique_code,"question_answers",$tok);
+ if ($answer) {
+ if ($in_first) {
+ $answer_field .= $answer->new_id;
+ $in_first = false;
+ } else {
+ $answer_field .= ",".$answer->new_id;
+ }
+ }
+ //check for next
+ $tok = strtok(",");
+ }
+ return $answer_field;
+ }
+
?>
--- /dev/null
+<?php
+ function question_random_recode_answer($state, $restore) {
+ $answer = backup_getid($restore->backup_unique_code,"question_answers",$state->answer);
+ if ($answer) {
+ return $answer->new_id;
+ }
+ return '';
+ }
+?>
return $status;
}
+
+ function question_truefalse_recode_answer($state, $restore) {
+ $answer = backup_getid($restore->backup_unique_code,"question_answers",$state->answer);
+ if ($answer) {
+ return $answer->new_id;
+ }
+ return '';
+ }
?>
// load questiontype-specific functions
unset($restorefns);
unset($restoremapfns);
+ unset($restorestatefns);
+ unset($recodeansfns);
//if ($qtypes = get_records('question_types')) {
- if ($qtypes = get_list_of_plugins('question/questiontypes')) {
+ if ($qtypes = get_list_of_plugins('question/questiontypes')) {
foreach ($qtypes as $name) {
$qtype->name = $name;
$restorelib = $CFG->dirroot.'/question/questiontypes/'.$qtype->name.'/restorelib.php';
if (function_exists($restorestatefn)) {
$restorestatefns[$qtype->name] = $restorestatefn;
}
+ $recodeansfn = 'question_'.$qtype->name.'_recode_answer';
+ if (function_exists($recodeansfn)) {
+ $recodeansfns[$qtype->name] = $recodeansfn;
+ }
}
}
}
//This function restores the question_states
function question_states_restore_mods($attempt_id,$info,$restore) {
- global $CFG;
+ global $CFG, $restorestatefns;
$status = true;