]> git.mjollnir.org Git - moodle.git/commitdiff
match qtype: MDL-17326 backup and restore problems
authortjhunt <tjhunt>
Fri, 12 Dec 2008 06:45:07 +0000 (06:45 +0000)
committertjhunt <tjhunt>
Fri, 12 Dec 2008 06:45:07 +0000 (06:45 +0000)
* The shuffleanswers options was not backed up or restored.

* Responses were not properly recoded on restore.

question/type/match/questiontype.php

index 7169f6b8db59b339874a139477e8008654618aac..12c47b456f0d2df09e6c8b93e647154bba63ea0b 100644 (file)
@@ -485,9 +485,18 @@ class question_match_qtype extends default_questiontype {
         global $DB;
         $status = true;
 
+        // Output the shuffleanswers setting.
+        $matchoptions = $DB->get_record('question_match', array('question' => $question));
+        if ($matchoptions) {
+            $status = fwrite ($bf,start_tag("MATCHOPTIONS",6,true));
+            fwrite ($bf,full_tag("SHUFFLEANSWERS",7,false,$matchoptions->shuffleanswers));
+            $status = fwrite ($bf,end_tag("MATCHOPTIONS",6,true));
+        }
+
         $matchs = $DB->get_records('question_match_sub', array('question' =>  $question), 'id ASC');
         //If there are matchs
         if ($matchs) {
+            //Print match contents
             $status = fwrite ($bf,start_tag("MATCHS",6,true));
             //Iterate over each match
             foreach ($matchs as $match) {
@@ -513,7 +522,6 @@ class question_match_qtype extends default_questiontype {
      */
     function restore($old_question_id,$new_question_id,$info,$restore) {
         global $DB;
-
         $status = true;
 
         //Get the matchs array
@@ -575,6 +583,13 @@ class question_match_qtype extends default_questiontype {
         $match->question = $new_question_id;
         $match->subquestions = $subquestions_field;
 
+        // Get the shuffleanswers option, if it is there.
+        if (!empty($info['#']['MATCHOPTIONS']['0']['#']['SHUFFLEANSWERS'])) {
+            $match->shuffleanswers = backup_todb($info['#']['MATCHOPTIONS']['0']['#']['SHUFFLEANSWERS']['0']['#']);
+        } else {
+            $match->shuffleanswers = 1;
+        }
+
         //The structure is equal to the db, so insert the question_match_sub
         $newid = $DB->insert_record ("question_match",$match);
 
@@ -655,26 +670,13 @@ class question_match_qtype extends default_questiontype {
             //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 in question_match_sub '.$match_question_id.'<br />';
-            }
-            //Get the match_sub from backup_ids (for the answer)
-            if ($match_answer_id) { // only recode answer if not 0, not answered yet
-              if (!$match_ans = backup_getid($restore->backup_unique_code,"question_match_sub",$match_answer_id)) {
-                  echo 'Could not recode answer in question_match_sub '.$match_answer_id.'<br />';
-              }
-            }
-
-            if ($match_que) {
-                //If the question hasn't response, it must be 0
-                if (!$match_ans and $match_answer_id == 0) {
-                    $match_ans->new_id = 0;
-                }
-
+            } else {
                 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;
+                    $answer_field .= ',';
                 }
+                $answer_field .= $match_que->new_id.'-'.$match_answer_id;
             }
             //check for next
             $tok = strtok(",");