]> git.mjollnir.org Git - moodle.git/commitdiff
Now numerical questions are included in backup and restore too !!
authorstronk7 <stronk7>
Sat, 19 Jul 2003 18:01:11 +0000 (18:01 +0000)
committerstronk7 <stronk7>
Sat, 19 Jul 2003 18:01:11 +0000 (18:01 +0000)
mod/quiz/backuplib.php
mod/quiz/restorelib.php

index 2c70452c7e92d5a1293c35e688dd149f0274511f..d684399d8f96fb61df8c37cb2cbfd77a133a3c77 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 132cc
 
     //This is the "graphical" structure of the quiz mod:
     //
     //                                                                                           |
     //                                                                                           |
     //                                                                                           |
-    //             ------------------------------------------------------------------------------------------------------
-    //             |                         |                        |                |    
-    //             |                         |                        |                |
-    //             |                         |                        |                |           quiz_randomsamatch
-    //       quiz_truefalse           quiz_shortanswer         quiz_multichoice        |---------(CL,pl->id,fk->question)
-    //  (CL,pl->id,fk->question)  (CL,pl->id,fk->question)  (CL,pl->id,fk->question)   |
-    //             .                         .                        .                |
-    //             .                         .                        .                |
-    //             .                         .                        .                |               quiz_match
-    //             ....................................................                |---------(CL,pl->id,fk->question)
-    //                                       .                                         |                    .
-    //                                       .                                         |                    .
-    //                                       .                                         |                    .
-    //                                    quiz_answers                                 |              quiz_match_sub
-    //                             (CL,pk->id,fk->question)----------------------------|---------(CL,pl->id,fk->question) 
+    //             --------------------------------------------------------------------------------------
+    //             |                         |                        |                                 |    
+    //             |                         |                        |                                 |
+    //             |                         |                        |                                 |    quiz_randomsamatch
+    //      quiz_truefalse         quiz_shortanswer       quiz_multichoice         quiz_numerical       |--(CL,pl->id,fk->question)
+    // (CL,pl->id,fk->question)(CL,pl->id,fk->question)(CL,pl->id,fk->question)(CL,pl->id,fk->question) |
+    //             .                         .                        .                 .               |
+    //             .                         .                        .                 .               |
+    //             .                         .                        .                 .               |         quiz_match
+    //             ......................................................................               |--(CL,pl->id,fk->question)
+    //                                                   .                                              |             .
+    //                                                   .                                              |             .
+    //                                                   .                                              |             .
+    //                                                quiz_answers                                      |      quiz_match_sub
+    //                                         (CL,pk->id,fk->question)---------------------------------|--(CL,pl->id,fk->question) 
     // 
     // Meaning: pk->primary key field of the table
     //          fk->foreign key to link with parent
@@ -57,6 +57,7 @@
     //     - quiz_truefalse
     //     - quiz_shortanswer
     //     - quiz_multichoice
+    //     - quiz_numerical
     //     - quiz_randomsamatch
     //     - quiz_match
     //     - quiz_match_sub
                     $status = quiz_backup_randomsamatch($bf,$preferences,$question->id);
                 } else if ($question->qtype == "7") {
                     //Description question. Nothing to write.
+                } else if ($question->qtype == "8") {
+                    $status = quiz_backup_numerical($bf,$preferences,$question->id);
                 }
                 //End question
                 $status =fwrite ($bf,end_tag("QUESTION",5,true));
         return $status;
     }
 
+    //This function backups the data in a numerical question (qtype=8) and its
+    //asociated data
+    function quiz_backup_numerical($bf,$preferences,$question) {
+
+        global $CFG;
+
+        $status = true;
+
+        $numericals = get_records("quiz_numerical","question",$question,"id");
+        //If there are numericals
+        if ($numericals) {
+            //Iterate over each numerical
+            foreach ($numericals as $numerical) {
+                $status =fwrite ($bf,start_tag("NUMERICAL",6,true));
+                //Print numerical contents
+                fwrite ($bf,full_tag("ANSWER",7,false,$numerical->answer));
+                fwrite ($bf,full_tag("MIN",7,false,$numerical->min));
+                fwrite ($bf,full_tag("MAX",7,false,$numerical->max));
+                $status =fwrite ($bf,end_tag("NUMERICAL",6,true));
+            }
+            //Now print quiz_answers
+            $status = quiz_backup_answers($bf,$preferences,$question);
+        }
+        return $status;
+    }
+
     //This function backups the answers data in some question types
-    //(truefalse, shortanswer,multichoice)
+    //(truefalse, shortanswer,multichoice,numerical)
     function quiz_backup_answers($bf,$preferences,$question) {
 
         global $CFG;
index f1fd51baa80c720da3156dd0c331da6e53179f81..e038cd2aeb610b8d23609f428d52dec4b1659a5d 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 132cc
 
     //This is the "graphical" structure of the quiz mod:
     //
     //             |                                              |                              |
     //             |                                              |                              |
     //             |                                              |                              |
-    //       quiz_responses                                       |                        quiz_questions     
+    //       quiz_responses                                       |                        quiz_questions
     //  (UL,pk->id, fk->attempt)----------------------------------------------------(CL,pk->id,fk->category,files)
     //                                                                                           |
     //                                                                                           |
     //                                                                                           |
-    //             ------------------------------------------------------------------------------------------------------
-    //             |                         |                        |                |    
-    //             |                         |                        |                |
-    //             |                         |                        |                |           quiz_randomsamatch
-    //       quiz_truefalse           quiz_shortanswer         quiz_multichoice        |---------(CL,pl->id,fk->question)
-    //  (CL,pl->id,fk->question)  (CL,pl->id,fk->question)  (CL,pl->id,fk->question)   |
-    //             .                         .                        .                |
-    //             .                         .                        .                |
-    //             .                         .                        .                |               quiz_match
-    //             ....................................................                |---------(CL,pl->id,fk->question)
-    //                                       .                                         |                    .
-    //                                       .                                         |                    .
-    //                                       .                                         |                    .
-    //                                    quiz_answers                                 |              quiz_match_sub
-    //                             (CL,pk->id,fk->question)----------------------------|---------(CL,pl->id,fk->question) 
-    // 
+    //             --------------------------------------------------------------------------------------                
+    //             |                         |                        |                                 |
+    //             |                         |                        |                                 |
+    //             |                         |                        |                                 |    quiz_randomsamatch
+    //      quiz_truefalse         quiz_shortanswer       quiz_multichoice         quiz_numerical       |--(CL,pl->id,fk->question)
+    // (CL,pl->id,fk->question)(CL,pl->id,fk->question)(CL,pl->id,fk->question)(CL,pl->id,fk->question) |
+    //             .                         .                        .                 .               |
+    //             .                         .                        .                 .               |
+    //             .                         .                        .                 .               |         quiz_match
+    //             ......................................................................               |--(CL,pl->id,fk->question)
+    //                                                   .                                              |             .
+    //                                                   .                                              |             .
+    //                                                   .                                              |             .
+    //                                                quiz_answers                                      |      quiz_match_sub
+    //                                         (CL,pk->id,fk->question)---------------------------------|--(CL,pl->id,fk->question)
+    //    //This is the "graphical" structure of the quiz mod:
+    //
+    //                           quiz                                                      quiz_categories
+    //                        (CL,pk->id)                                                   (CL,pk->id)
+    //                            |                                                              |
+    //             -----------------------------------------------                               |
+    //             |                        |                    |                               |
+    //             |                        |                    |                               |
+    //             |                        |                    |                               |
+    //        quiz_attempts          quiz_grades         quiz_question_grades                    |
+    //   (UL,pk->id, fk->quiz)   (UL,pk->id,fk->quiz)    (CL,pk->id,fk->quiz)                    |
+    //             |                                              |                              |
+    //             |                                              |                              |
+    //             |                                              |                              |
+    //       quiz_responses                                       |                        quiz_questions
+    //  (UL,pk->id, fk->attempt)----------------------------------------------------(CL,pk->id,fk->category,files)
+    //                                                                                           |
+    //                                                                                           |
+    //                                                                                           |
+    //             --------------------------------------------------------------------------------------                
+    //             |                         |                        |                                 |
+    //             |                         |                        |                                 |
+    //             |                         |                        |                                 |    quiz_randomsamatch
+    //      quiz_truefalse         quiz_shortanswer       quiz_multichoice         quiz_numerical       |--(CL,pl->id,fk->question)
+    // (CL,pl->id,fk->question)(CL,pl->id,fk->question)(CL,pl->id,fk->question)(CL,pl->id,fk->question) |
+    //             .                         .                        .                 .               |
+    //             .                         .                        .                 .               |
+    //             .                         .                        .                 .               |         quiz_match
+    //             ......................................................................               |--(CL,pl->id,fk->question)
+    //                                                   .                                              |             .
+    //                                                   .                                              |             .
+    //                                                   .                                              |             .
+    //                                                quiz_answers                                      |      quiz_match_sub
+    //                                         (CL,pk->id,fk->question)---------------------------------|--(CL,pl->id,fk->question)
+    //
     // Meaning: pk->primary key field of the table
     //          fk->foreign key to link with parent
     //          nt->nested field (recursive data)
@@ -55,6 +89,7 @@
     //     - quiz_truefalse
     //     - quiz_shortanswer
     //     - quiz_multichoice
+    //     - quiz_numerical
     //     - quiz_randomsamatch
     //     - quiz_match
     //     - quiz_match_sub
                     $status = quiz_restore_randomsamatch($oldid,$newid,$que_info,$restore);
                 } else if ($question->qtype == "7") {
                     //Description question. Nothing to do.
+                } else if ($question->qtype == "8") {
+                    $status = quiz_restore_numerical($oldid,$newid,$que_info,$restore);
                 }
             } else {
                 $status = false;
         return $status;
     }
 
+    function quiz_restore_numerical ($old_question_id,$new_question_id,$info,$restore) {
+
+        global $CFG;
+
+        $status = true;
 
+        //Get the numerical array
+        $numericals = $info['#']['NUMERICAL'];
+
+        //Iterate over numericals
+        for($i = 0; $i < sizeof($numericals); $i++) {
+            $num_info = $numericals[$i];
+            //traverse_xmlize($num_info);                                                                 //Debug
+            //print_object ($GLOBALS['traverse_array']);                                                  //Debug
+            //$GLOBALS['traverse_array']="";                                                              //Debug
+
+            //Now, build the QUIZ_NUMERICAL record structure
+            $numerical->question = $new_question_id;
+            $numerical->answer = backup_todb($num_info['#']['ANSWER']['0']['#']);
+            $numerical->min = backup_todb($num_info['#']['MIN']['0']['#']);
+            $numerical->max = backup_todb($num_info['#']['MAX']['0']['#']);
+
+            ////We have to recode the answer field
+            $answer = backup_getid($restore->backup_unique_code,"quiz_answers",$numerical->answer);
+            if ($answer) {
+                $numerical->answer = $answer->new_id;
+            }
+
+            //The structure is equal to the db, so insert the quiz_numerical
+            $newid = insert_record ("quiz_numerical",$numerical);
+
+            //Do some output
+            if (($i+1) % 50 == 0) {
+                echo ".";
+                if (($i+1) % 1000 == 0) {
+                    echo "<br>";
+                }
+                backup_flush(300);
+            }
+
+            if (!$newid) {
+                $status = false;
+            }
+        }
+
+        return $status;
+    }
 
 
     //STEP 2. Restore quizzes and associated structures
                         //Nothing to do (there is no awser to this qtype)
                         //But this case must exist !!
                         break;
+                    case 8:    //NUMERICAL QTYPE
+                        //Nothing to do. The response is a text.
+                        break;
                     default:   //UNMATCHED QTYPE.
                         //This is an error (unimplemented qtype)
                         $status = false;