]> git.mjollnir.org Git - moodle.git/commitdiff
Solved one important bug in RANDOM(4) and RANDOMSAMATCH(6)
authorstronk7 <stronk7>
Fri, 15 Aug 2003 11:08:51 +0000 (11:08 +0000)
committerstronk7 <stronk7>
Fri, 15 Aug 2003 11:08:51 +0000 (11:08 +0000)
question types.
And modified some of the quiz_answers restore system to
allow remapping answers with existing questions.
//Detected by scott dot elliott at mchsi dot com in Bug 84

backup/version.php
mod/quiz/restorelib.php

index 78d0be9150512a9d9c6adc2851da0d4579f6d8f7..d6178431490521a648d121661fe9942410bdd26c 100644 (file)
@@ -5,6 +5,6 @@
 // database (backup_version) to determine whether upgrades should
 // be performed (see db/backup_*.php)
 
-$backup_version = 2003080400;   // The current version is a date (YYYYMMDDXX)
+$backup_version = 2003081500;   // The current version is a date (YYYYMMDDXX)
 
-$backup_release = "0.8.6 alpha";  // User-friendly version number
+$backup_release = "0.8.7 alpha";  // User-friendly version number
index 2aeb2d9cab93a0f47f0b851ac6bd1d3b911e96d1..19ab2bb1c58f7e2fe80ae349ca0691836651d514 100644 (file)
 
             //Check if the question exists
             //by category,questiontext and qtype
-            $question_exists = get_record ("quiz_questions","category",$question->category,
-                                                            "questiontext",$question->questiontext,
-                                                            "qtype",$question->qtype);
+            //But do it only if the question type isn't RANDOM (4) or RANDOMSAMATCH (6), because this
+            //types can have duplicates in the fields I'm searching !!
+            //I think that some modifications should be done here !!
+            //Detected by scott dot elliott at mchsi dot com in Bug 84 
+            if ($question->qtype != 4 and $question->qtype != 6) {
+                $question_exists = get_record ("quiz_questions","category",$question->category,
+                                                                "questiontext",$question->questiontext,
+                                                                "qtype",$question->qtype);
+            } else {
+                $question_exists = false;
+            }
             //If the question exists, only record its id
             if ($question_exists) {
                 $newid = $question_exists->id;
                 } else if ($question->qtype == "8") {
                     $status = quiz_restore_numerical($oldid,$newid,$que_info,$restore);
                 }
+            } else {
+                //We are NOT creating the question, but we need to know every quiz_answers
+                //map between the XML file and the database to be able to restore the responses
+                //in each attempt.
+                $status = quiz_restore_map_answers($oldid,$newid,$que_info,$restore);
             }
         }
         return $status;
 
         return $status;
     }
+
+    function quiz_restore_map_answers ($old_question_id,$new_question_id,$info,$restore) {
+
+        global $CFG;
+
+        $status = true;
+
+        //Get the answers array
+        $answers = $info['#']['ANSWERS']['0']['#']['ANSWER'];
+
+        //Iterate over answers
+        for($i = 0; $i < sizeof($answers); $i++) {
+            $ans_info = $answers[$i];
+            //traverse_xmlize($ans_info);                                                                 //Debug
+            //print_object ($GLOBALS['traverse_array']);                                                  //Debug
+            //$GLOBALS['traverse_array']="";                                                              //Debug
+
+            //We'll need this later!!
+            $oldid = backup_todb($ans_info['#']['ID']['0']['#']);
+
+            //Now, build the QUIZ_ANSWERS record structure
+            $answer->question = $new_question_id;
+            $answer->answer = backup_todb($ans_info['#']['ANSWER_TEXT']['0']['#']);
+            $answer->fraction = backup_todb($ans_info['#']['FRACTION']['0']['#']);
+            $answer->feedback = backup_todb($ans_info['#']['FEEDBACK']['0']['#']);
+
+            //If we are in this method is because the question exists in DB, so its
+            //answers must exist too.
+            //Now, we are going to look for that answer in DB and to create the 
+            //mappings in backup_ids to use them later where restoring responses (user level).
+
+            //Get the answer from DB (by question and answer)
+            $db_answer = get_record ("quiz_answers","question",$new_question_id,
+                                                    "answer",$answer->answer);
+
+            //Do some output
+            if (($i+1) % 50 == 0) {
+                echo ".";
+                if (($i+1) % 1000 == 0) {
+                    echo "<br>";
+                }
+                backup_flush(300);
+            }
+
+            if ($db_answer) {
+                //We have the database answer, update backup_ids
+                backup_putid($restore->backup_unique_code,"quiz_answers",$oldid,
+                             $db_answer->id);
+            } else {
+                $status = false;
+            }
+        }
+
+        return $status;
+    }
    
     function quiz_restore_shortanswer ($old_question_id,$new_question_id,$info,$restore) {