]> git.mjollnir.org Git - moodle.git/commitdiff
Now numerical_units support has been added to backup and restore.
authorstronk7 <stronk7>
Thu, 5 Aug 2004 23:11:31 +0000 (23:11 +0000)
committerstronk7 <stronk7>
Thu, 5 Aug 2004 23:11:31 +0000 (23:11 +0000)
Currently only working with numerical questions...

mod/quiz/backuplib.php
mod/quiz/restorelib.php

index 3f3e97af5e03ec2cb40175726d638e7e3458ec9e..92afbea150d01c79fd162a14fbfa7b3f7378b15f 100644 (file)
@@ -2,7 +2,7 @@
     //This php script contains all the stuff to backup/restore
     //quiz mods
 
-    //To see, put your terminal to 132cc
+    //To see, put your terminal to 160cc
 
     //This is the "graphical" structure of the quiz mod:
     //
     //                                                                                           |
     //                                                                                           |
     //                                                                                           |
-    //             --------------------------------------------------------------------------------------
-    //             |             |              |              |                |                       |    
-    //             |             |              |              |                |                       |
-    //             |             |              |              |                |                       |    quiz_randomsamatch
-    //      quiz_truefalse       |       quiz_multichoice      |         quiz_multianswer               |--(CL,pl->id,fk->question)
-    // (CL,pl->id,fk->question)  |   (CL,pl->id,fk->question)  |    (CL,pl->id,fk->question)            |
-    //             .             |              .              |               .                        |
-    //             .      quiz_shortanswer      .       quiz_numerical         .                        |
-    //             .  (CL,pl->id,fk->question)  .  (CL,pl->id,fk->question)    .                        |         quiz_match 
-    //             .             .              .              .               .                        |--(CL,pl->id,fk->question)
-    //             .             .              .              .               .                        |             .
-    //             .             .              .              .               .                        |             .
-    //             .             .              .              .               .                        |             .
-    //             .             .              .              .               .                        |       quiz_match_sub
-    //             .             .              .              .               .                        |--(CL,pl->id,fk->question)
-    //             .............................................................                        |
-    //                                                   .                                              |
-    //                                                   .                                              |
-    //                                                   .                                              |
-    //                                                quiz_answers                                      |
-    //                                         (CL,pk->id,fk->question)----------------------------------
+    //             --------------------------------------------------------------------------------------------------------------
+    //             |             |              |              |                       |                  |                     |    
+    //             |             |              |              |                       |                  |                     |
+    //             |             |              |              |                 quiz_calculated          |                     |    quiz_randomsamatch
+    //      quiz_truefalse       |       quiz_multichoice      |             (CL,pl->id,fk->question)     |                     |--(CL,pl->id,fk->question)
+    // (CL,pl->id,fk->question)  |   (CL,pl->id,fk->question)  |                       .                  |                     |
+    //             .             |              .              |                       .                  |                     |
+    //             .      quiz_shortanswer      .       quiz_numerical                 .            quiz_multianswer.           |
+    //             .  (CL,pl->id,fk->question)  .  (CL,pl->id,fk->question)            .        (CL,pl->id,fk->question)        |         quiz_match 
+    //             .             .              .              .                       .                  .                     |--(CL,pl->id,fk->question)
+    //             .             .              .              .                       .                  .                     |             .
+    //             .             .              .              .                       .                  .                     |             .
+    //             .             .              .              .                       .                  .                     |             .
+    //             .             .              .              .                       .                  .                     |       quiz_match_sub
+    //             .             .              .              .                       .                  .                     |--(CL,pl->id,fk->question)
+    //             ........................................................................................                     |
+    //                                                   .                                                                      |
+    //                                                   .                                                                      |
+    //                                                   .                                                                      |    quiz_numerical_units
+    //                                                quiz_answers                                                              |--(CL,pl->id,fk->question)
+    //                                         (CL,pk->id,fk->question)----------------------------------------------------------
     // 
     // Meaning: pk->primary key field of the table
     //          fk->foreign key to link with parent
@@ -69,6 +69,7 @@
     //     - quiz_match
     //     - quiz_match_sub
     //     - quiz_answers
+    //     - quiz_numerical_units
     //    All this backup info have its own section in moodle.xml (QUESTION_CATEGORIES) and it's generated
     //    before every module backup standard invocation. And only if to backup quizzes has been selected !!
     //    It's invoked with quiz_backup_question_categories. (course independent).
                 fwrite ($bf,full_tag("ANSWER",$level+1,false,$numerical->answer));
                 fwrite ($bf,full_tag("MIN",$level+1,false,$numerical->min));
                 fwrite ($bf,full_tag("MAX",$level+1,false,$numerical->max));
+                //Now backup numerical_units
+                $status = quiz_backup_numerical_units($bf,$preferences,$question,7);
                 $status =fwrite ($bf,end_tag("NUMERICAL",$level,true));
             }
             //Now print quiz_answers
         return $status;
     }
 
+    //This function backups quiz_numerical_units from different question types
+    function quiz_backup_numerical_units($bf,$preferences,$question,$level=7) {
 
+        global $CFG;
+
+        $status = true;
 
+        $numerical_units = get_records("quiz_numerical_units","question",$question,"id");
+        //If there are numericals_units
+        if ($numerical_units) {
+            $status =fwrite ($bf,start_tag("NUMERICAL_UNITS",$level,true));
+            //Iterate over each numerical_unit
+            foreach ($numerical_units as $numerical_unit) {
+                $status =fwrite ($bf,start_tag("NUMERICAL_UNIT",$level+1,true));
+                //Print numerical_unit contents
+                fwrite ($bf,full_tag("MULTIPLIER",$level+2,false,$numerical_unit->multiplier));
+                fwrite ($bf,full_tag("UNIT",$level+2,false,$numerical_unit->unit));
+                //Now backup numerical_units
+                $status =fwrite ($bf,end_tag("NUMERICAL_UNIT",$level+1,true));
+            }
+            $status =fwrite ($bf,end_tag("NUMERICAL_UNITS",$level,true));
+        }
+
+        return $status;
+
+    }
 
 
     //STEP 2. Backup quizzes and associated structures
index 5483549c12734e86425efa54bc0d4f4b5ef54793..8128b70e25be6293577c5b7171a98e57acbf833a 100644 (file)
@@ -5,12 +5,12 @@
     //To see, put your terminal to 132cc
 
     //This is the "graphical" structure of the quiz mod:
-    //             
+    //
     //                           quiz                                                      quiz_categories
-    //                        (CL,pk->id)                                                   (CL,pk->id)  
-    //                            |                                                              |       
-    //             -----------------------------------------------                               |       
-    //             |                        |                    |                               |       
+    //                        (CL,pk->id)                                                   (CL,pk->id)
+    //                            |                                                              |
+    //             -----------------------------------------------                               |
+    //             |                        |                    |                               |
     //             |                        |                    |                               |
     //             |                        |                    |                               |
     //        quiz_attempts          quiz_grades         quiz_question_grades                    |
     //                                                                                           |
     //                                                                                           |
     //                                                                                           |
-    //             --------------------------------------------------------------------------------------
-    //             |             |              |              |                |                       |
-    //             |             |              |              |                |                       |
-    //             |             |              |              |                |                       |    quiz_randomsamatch
-    //      quiz_truefalse       |       quiz_multichoice      |         quiz_multianswer               |--(CL,pl->id,fk->question)
-    // (CL,pl->id,fk->question)  |   (CL,pl->id,fk->question)  |    (CL,pl->id,fk->question)            |
-    //             .             |              .              |               .                        |
-    //             .      quiz_shortanswer      .       quiz_numerical         .                        |
-    //             .  (CL,pl->id,fk->question)  .  (CL,pl->id,fk->question)    .                        |         quiz_match
-    //             .             .              .              .               .                        |--(CL,pl->id,fk->question)
-    //             .             .              .              .               .                        |             .
-    //             .             .              .              .               .                        |             .
-    //             .             .              .              .               .                        |             .
-    //             .             .              .              .               .                        |       quiz_match_sub
-    //             .             .              .              .               .                        |--(CL,pl->id,fk->question)
-    //             .............................................................                        |
-    //                                                   .                                              |
-    //                                                   .                                              |
-    //                                                   .                                              |
-    //                                                quiz_answers                                      |
-    //                                         (CL,pk->id,fk->question)----------------------------------
+    //             --------------------------------------------------------------------------------------------------------------
+    //             |             |              |              |                       |                  |                     |
+    //             |             |              |              |                       |                  |                     |
+    //             |             |              |              |                 quiz_calculated          |                     |    quiz_randomsamatch
+    //      quiz_truefalse       |       quiz_multichoice      |             (CL,pl->id,fk->question)     |                     |--(CL,pl->id,fk->question)
+    // (CL,pl->id,fk->question)  |   (CL,pl->id,fk->question)  |                       .                  |                     |
+    //             .             |              .              |                       .                  |                     |
+    //             .      quiz_shortanswer      .       quiz_numerical                 .            quiz_multianswer.           |
+    //             .  (CL,pl->id,fk->question)  .  (CL,pl->id,fk->question)            .        (CL,pl->id,fk->question)        |         quiz_match
+    //             .             .              .              .                       .                  .                     |--(CL,pl->id,fk->question)
+    //             .             .              .              .                       .                  .                     |             .
+    //             .             .              .              .                       .                  .                     |             .
+    //             .             .              .              .                       .                  .                     |             .
+    //             .             .              .              .                       .                  .                     |       quiz_match_sub
+    //             .             .              .              .                       .                  .                     |--(CL,pl->id,fk->question)
+    //             ........................................................................................                     |
+    //                                                   .                                                                      |
+    //                                                   .                                                                      |
+    //                                                   .                                                                      |    quiz_numerical_units
+    //                                                quiz_answers                                                              |--(CL,pl->id,fk->question)
+    //                                         (CL,pk->id,fk->question)----------------------------------------------------------
     //
     // Meaning: pk->primary key field of the table
     //          fk->foreign key to link with parent
@@ -67,6 +67,7 @@
     //     - quiz_match
     //     - quiz_match_sub
     //     - quiz_answers
+    //     - quiz_numerical_units
     //    All this backup info have its own section in moodle.xml (QUESTION_CATEGORIES) and it's generated
     //    before every module backup standard invocation. And only if to restore quizzes has been selected !!
     //    It's invoked with quiz_restore_question_categories. (course independent).
                 backup_flush(300);
             }
 
+            //Now restore numerical_units
+            $status = quiz_restore_numerical_units ($old_question_id,$new_question_id,$num_info,$restore);
+
             if (!$newid) {
                 $status = false;
             }
         return $status;
     }
 
+    function quiz_restore_numerical_units ($old_question_id,$new_question_id,$info,$restore) {
+
+        global $CFG;
+
+        $status = true;
+
+        //Get the numerical array
+        $numerical_units = $info['#']['NUMERICAL_UNITS']['0']['#']['NUMERICAL_UNIT'];
+
+        //Iterate over numerical_units
+        for($i = 0; $i < sizeof($numerical_units); $i++) {
+            $nu_info = $numerical_units[$i];
+            traverse_xmlize($nu_info);                                                                  //Debug
+            print_object ($GLOBALS['traverse_array']);                                                  //Debug
+            $GLOBALS['traverse_array']="";                                                              //Debug
+
+            //Now, build the QUIZ_NUMERICAL_UNITS record structure
+            $numerical_unit->question = $new_question_id;
+            $numerical_unit->multiplier = backup_todb($nu_info['#']['MULTIPLIER']['0']['#']);
+            $numerical_unit->unit = backup_todb($nu_info['#']['UNIT']['0']['#']);
+
+            //The structure is equal to the db, so insert the quiz_numerical_units
+            $newid = insert_record ("quiz_numerical_units",$numerical_unit);
+
+            if (!$newid) {
+                $status = false;
+            }
+        }
+
+        return $status;
+    }
+
 
     //STEP 2. Restore quizzes and associated structures
     //    (course dependent)