From: gustav_delius Date: Thu, 16 Mar 2006 21:17:31 +0000 (+0000) Subject: Some incomplete work on the restore code (committing only because I am moving to... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c6abbe5e39576146a42dd4266157beaa0558c217;p=moodle.git Some incomplete work on the restore code (committing only because I am moving to a different machine) --- diff --git a/mod/quiz/restorelib.php b/mod/quiz/restorelib.php index 4731931e0e..4b7ba3b4b1 100644 --- a/mod/quiz/restorelib.php +++ b/mod/quiz/restorelib.php @@ -325,7 +325,8 @@ 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; } diff --git a/question/questiontypes/multianswer/restorelib.php b/question/questiontypes/multianswer/restorelib.php index c9d9a8e855..9ca22343cc 100644 --- a/question/questiontypes/multianswer/restorelib.php +++ b/question/questiontypes/multianswer/restorelib.php @@ -137,4 +137,39 @@ 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; + } + ?> diff --git a/question/questiontypes/multichoice/restorelib.php b/question/questiontypes/multichoice/restorelib.php index 440e54453a..5c947abc84 100644 --- a/question/questiontypes/multichoice/restorelib.php +++ b/question/questiontypes/multichoice/restorelib.php @@ -65,4 +65,26 @@ 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; + } + ?> diff --git a/question/questiontypes/random/restorelib.php b/question/questiontypes/random/restorelib.php new file mode 100644 index 0000000000..8bcc672498 --- /dev/null +++ b/question/questiontypes/random/restorelib.php @@ -0,0 +1,9 @@ +backup_unique_code,"question_answers",$state->answer); + if ($answer) { + return $answer->new_id; + } + return ''; + } +?> diff --git a/question/questiontypes/truefalse/restorelib.php b/question/questiontypes/truefalse/restorelib.php index 87e7ff949b..70fc4e2e55 100644 --- a/question/questiontypes/truefalse/restorelib.php +++ b/question/questiontypes/truefalse/restorelib.php @@ -53,4 +53,12 @@ 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 ''; + } ?> diff --git a/question/restorelib.php b/question/restorelib.php index 665d8f302a..1c453f89b4 100644 --- a/question/restorelib.php +++ b/question/restorelib.php @@ -85,8 +85,10 @@ // 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'; @@ -104,6 +106,10 @@ if (function_exists($restorestatefn)) { $restorestatefns[$qtype->name] = $restorestatefn; } + $recodeansfn = 'question_'.$qtype->name.'_recode_answer'; + if (function_exists($recodeansfn)) { + $recodeansfns[$qtype->name] = $recodeansfn; + } } } } @@ -566,7 +572,7 @@ //This function restores the question_states function question_states_restore_mods($attempt_id,$info,$restore) { - global $CFG; + global $CFG, $restorestatefns; $status = true;