]> git.mjollnir.org Git - moodle.git/commitdiff
Some incomplete work on the restore code (committing only because I am moving to...
authorgustav_delius <gustav_delius>
Thu, 16 Mar 2006 21:17:31 +0000 (21:17 +0000)
committergustav_delius <gustav_delius>
Thu, 16 Mar 2006 21:17:31 +0000 (21:17 +0000)
mod/quiz/restorelib.php
question/questiontypes/multianswer/restorelib.php
question/questiontypes/multichoice/restorelib.php
question/questiontypes/random/restorelib.php [new file with mode: 0644]
question/questiontypes/truefalse/restorelib.php
question/restorelib.php

index 4731931e0e6e3febd901ca27ea4b9a50995a07d9..4b7ba3b4b1906c5dee8990fbb0824dc3e7d00074 100644 (file)
                 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;
             }
index c9d9a8e8557e5ec5d9745a7f2c934f94b3a4f47e..9ca22343cc1b44386ba3392dbc660a192fda8721 100644 (file)
 
         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;
+    }
+
 ?>
index 440e54453aa8785ed03d99afcc6fc98d2dcbb31e..5c947abc840273de3c6f082c78e01030a985971c 100644 (file)
 
         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 (file)
index 0000000..8bcc672
--- /dev/null
@@ -0,0 +1,9 @@
+<?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 '';
+    }
+?>
index 87e7ff949bedcdde51d3aaa366f1f259811c99e3..70fc4e2e55166b8d3c8e6cd72f238aafb2083038 100644 (file)
 
         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 '';
+    }
 ?>
index 665d8f302a68a4021191e84ea25e2c6c9e0de367..1c453f89b4fa12b4c2a3ace1c3866f4dd690fbd7 100644 (file)
     // 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;