From: gustav_delius Date: Sun, 19 Mar 2006 09:50:43 +0000 (+0000) Subject: Fixed backup and restore for match questions X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c0749a1605d669164db238d993e6d3a7a49e15dc;p=moodle.git Fixed backup and restore for match questions --- diff --git a/mod/quiz/backuplib.php b/mod/quiz/backuplib.php index 3a286ffe70..b2c9a2c6c9 100644 --- a/mod/quiz/backuplib.php +++ b/mod/quiz/backuplib.php @@ -476,9 +476,9 @@ $status = fwrite ($bf,start_tag("MATCH",7,true)); //Print match contents fwrite ($bf,full_tag("ID",8,false,$match->id)); + fwrite ($bf,full_tag("CODE",8,false,$match->code)); fwrite ($bf,full_tag("QUESTIONTEXT",8,false,$match->questiontext)); fwrite ($bf,full_tag("ANSWERTEXT",8,false,$match->answertext)); - fwrite ($bf,full_tag("SHUFFLEANSWERS",8,false,$randomsamatch->shuffleanswers)); $status = fwrite ($bf,end_tag("MATCH",7,true)); } $status = fwrite ($bf,end_tag("MATCHS",6,true)); diff --git a/question/questiontypes/match/restorelib.php b/question/questiontypes/match/restorelib.php index 382b69df0b..e3d3026cfe 100644 --- a/question/questiontypes/match/restorelib.php +++ b/question/questiontypes/match/restorelib.php @@ -24,6 +24,10 @@ //Now, build the question_match_SUB record structure $match_sub->question = $new_question_id; + $match_sub->code = backup_todb($mat_info['#']['CODE']['0']['#']); + if (!$match_sub->code) { + $match_sub->code = $oldid; + } $match_sub->questiontext = backup_todb($mat_info['#']['QUESTIONTEXT']['0']['#']); $match_sub->answertext = backup_todb($mat_info['#']['ANSWERTEXT']['0']['#']); diff --git a/question/restorelib.php b/question/restorelib.php index d9e7bd62ab..30add46665 100644 --- a/question/restorelib.php +++ b/question/restorelib.php @@ -691,26 +691,16 @@ //Extract the match_sub for the question and the answer $exploded = explode("-",$tok); $match_question_id = $exploded[0]; - $match_answer_id = $exploded[1]; + $match_answer_code = $exploded[1]; //Get the match_sub from backup_ids (for the question) if (!$match_que = backup_getid($restore->backup_unique_code,"question_match_sub",$match_question_id)) { echo 'Could not recode question_match_sub '.$match_question_id.'
'; } - //Get the match_sub from backup_ids (for the answer) - if (!$match_ans = backup_getid($restore->backup_unique_code,"question_match_sub",$match_answer_id)) { - echo 'Could not recode question_match_sub '.$match_answer_id.'
'; - } - if ($match_que) { - //It the question hasn't response, it must be 0 - if (!$match_ans and $match_answer_id == 0) { - $match_ans->new_id = 0; - } - if ($in_first) { - $answer_field .= $match_que->new_id."-".$match_ans->new_id; - $in_first = false; - } else { - $answer_field .= ",".$match_que->new_id."-".$match_ans->new_id; - } + if ($in_first) { + $answer_field .= $match_que->new_id."-".$match_answer_code; + $in_first = false; + } else { + $answer_field .= ",".$match_que->new_id."-".$match_answer_code; } //check for next $tok = strtok(",");