]> git.mjollnir.org Git - moodle.git/commitdiff
Moved questiontype specific backup functions into questiontype classes
authorgustav_delius <gustav_delius>
Tue, 21 Mar 2006 18:15:09 +0000 (18:15 +0000)
committergustav_delius <gustav_delius>
Tue, 21 Mar 2006 18:15:09 +0000 (18:15 +0000)
13 files changed:
mod/quiz/backuplib.php
question/backuplib.php
question/questiontypes/calculated/questiontype.php
question/questiontypes/essay/questiontype.php
question/questiontypes/match/questiontype.php
question/questiontypes/multianswer/questiontype.php
question/questiontypes/multichoice/questiontype.php
question/questiontypes/numerical/questiontype.php
question/questiontypes/questiontype.php
question/questiontypes/randomsamatch/questiontype.php
question/questiontypes/rqp/questiontype.php
question/questiontypes/shortanswer/questiontype.php
question/questiontypes/truefalse/questiontype.php

index cd8af11a30e03c7cf3cde1726b35b5c23057d437..5dd69b3267abbf77b41db1fcf35290fe1a7ee93f 100644 (file)
@@ -29,7 +29,8 @@
     // When we backup a quiz we also need to backup the questions and possibly
     // the data about student interaction with the questions. The functions to do
     // that are included with the following library
-    include_once("$CFG->dirroot/question/backuplib.php");
+    require_once("$CFG->libdir/questionlib.php");
+    require_once("$CFG->dirroot/question/backuplib.php");
 
 //STEP 1. Backup categories/questions and associated structures
     //    (course independent)
index 2cedb66d8c3ecc34449734e27453c3bfd87e862d..2d7aba9ed27e8faaec5bf236f8258b939695429e 100644 (file)
@@ -73,7 +73,7 @@
     //
     //-----------------------------------------------------------
 
-    include_once($CFG->libdir.'/questionlib.php');
+    require_once("$CFG->libdir/questionlib.php");
 
     function backup_question_categories($bf,$preferences) {
 
                 fwrite ($bf,full_tag("STAMP",6,false,$question->stamp));
                 fwrite ($bf,full_tag("VERSION",6,false,$question->version));
                 fwrite ($bf,full_tag("HIDDEN",6,false,$question->hidden));
-                //Now, depending of the qtype, call one function or other
-                if ($question->qtype == "1") {
-                    $status = question_backup_shortanswer($bf,$preferences,$question->id);
-                } else if ($question->qtype == "2") {
-                    $status = question_backup_truefalse($bf,$preferences,$question->id);
-                } else if ($question->qtype == "3") {
-                    $status = question_backup_multichoice($bf,$preferences,$question->id);
-                } else if ($question->qtype == "4") {
-                    //Random question. Nothing to write.
-                } else if ($question->qtype == "5") {
-                    $status = question_backup_match($bf,$preferences,$question->id);
-                } else if ($question->qtype == "6") {
-                    $status = question_backup_randomsamatch($bf,$preferences,$question->id);
-                } else if ($question->qtype == "7") {
-                    //Description question. Nothing to write.
-                } else if ($question->qtype == "8") {
-                    $status = question_backup_numerical($bf,$preferences,$question->id);
-                } else if ($question->qtype == "9") {
-                    $status = question_backup_multianswer($bf,$preferences,$question->id);
-                } else if ($question->qtype == "10") {
-                    $status = question_backup_calculated($bf,$preferences,$question->id);
-                } else if ($question->qtype == "11") {
-                    $status = question_backup_rqp($bf,$preferences,$question->id);
-                } else if ($question->qtype == "12") {
-                    $status = question_backup_essay($bf,$preferences,$question->id);
-                }
+                // Backup question type specific data
+                $status = $QTYPES[$question->qtype]->backup($bf,$preferences,$question->id);
                 //End question
                 $status = fwrite ($bf,end_tag("QUESTION",5,true));
                 //Do some output
         return $status;
     }
 
-    //This function backups the data in a truefalse question (qtype=2) and its
-    //asociated data
-    function question_backup_truefalse($bf,$preferences,$question) {
-
-        global $CFG;
-
-        $status = true;
-
-        $truefalses = get_records("question_truefalse","question",$question,"id");
-        //If there are truefalses
-        if ($truefalses) {
-            //Iterate over each truefalse
-            foreach ($truefalses as $truefalse) {
-                $status = fwrite ($bf,start_tag("TRUEFALSE",6,true));
-                //Print truefalse contents
-                fwrite ($bf,full_tag("TRUEANSWER",7,false,$truefalse->trueanswer));
-                fwrite ($bf,full_tag("FALSEANSWER",7,false,$truefalse->falseanswer));
-                $status = fwrite ($bf,end_tag("TRUEFALSE",6,true));
-            }
-            //Now print question_answers
-            $status = question_backup_answers($bf,$preferences,$question);
-        }
-        return $status;
-    }
-
-    //This function backups the data in a shortanswer question (qtype=1) and its
-    //asociated data
-    function question_backup_shortanswer($bf,$preferences,$question,$level=6,$include_answers=true) {
-
-        global $CFG;
-
-        $status = true;
-
-        $shortanswers = get_records("question_shortanswer","question",$question,"id");
-        //If there are shortanswers
-        if ($shortanswers) {
-            //Iterate over each shortanswer
-            foreach ($shortanswers as $shortanswer) {
-                $status = fwrite ($bf,start_tag("SHORTANSWER",$level,true));
-                //Print shortanswer contents
-                fwrite ($bf,full_tag("ANSWERS",$level+1,false,$shortanswer->answers));
-                fwrite ($bf,full_tag("USECASE",$level+1,false,$shortanswer->usecase));
-                $status = fwrite ($bf,end_tag("SHORTANSWER",$level,true));
-            }
-            //Now print question_answers
-            if ($include_answers) {
-                $status = question_backup_answers($bf,$preferences,$question);
-            }
-        }
-        return $status;
-    }
-
-    //This function backups the data in a multichoice question (qtype=3) and its
-    //asociated data
-    function question_backup_multichoice($bf,$preferences,$question,$level=6,$include_answers=true) {
-
-        global $CFG;
-
-        $status = true;
-
-        $multichoices = get_records("question_multichoice","question",$question,"id");
-        //If there are multichoices
-        if ($multichoices) {
-            //Iterate over each multichoice
-            foreach ($multichoices as $multichoice) {
-                $status = fwrite ($bf,start_tag("MULTICHOICE",$level,true));
-                //Print multichoice contents
-                fwrite ($bf,full_tag("LAYOUT",$level+1,false,$multichoice->layout));
-                fwrite ($bf,full_tag("ANSWERS",$level+1,false,$multichoice->answers));
-                fwrite ($bf,full_tag("SINGLE",$level+1,false,$multichoice->single));
-                fwrite ($bf,full_tag("SHUFFLEANSWERS",$level+1,false,$randomsamatch->shuffleanswers));
-                $status = fwrite ($bf,end_tag("MULTICHOICE",$level,true));
-            }
-            //Now print question_answers
-            if ($include_answers) {
-                $status = question_backup_answers($bf,$preferences,$question);
-            }
-        }
-        return $status;
-    }
-
-    //This function backups the data in a randomsamatch question (qtype=6) and its
-    //asociated data
-    function question_backup_randomsamatch($bf,$preferences,$question) {
-
-        global $CFG;
-
-        $status = true;
-
-        $randomsamatchs = get_records("question_randomsamatch","question",$question,"id");
-        //If there are randomsamatchs
-        if ($randomsamatchs) {
-            //Iterate over each randomsamatch
-            foreach ($randomsamatchs as $randomsamatch) {
-                $status = fwrite ($bf,start_tag("RANDOMSAMATCH",6,true));
-                //Print randomsamatch contents
-                fwrite ($bf,full_tag("CHOOSE",7,false,$randomsamatch->choose));
-                fwrite ($bf,full_tag("SHUFFLEANSWERS",7,false,$randomsamatch->shuffleanswers));
-                $status = fwrite ($bf,end_tag("RANDOMSAMATCH",6,true));
-            }
-        }
-        return $status;
-    }
-
-    //This function backups the data in a match question (qtype=5) and its
-    //asociated data
-    function question_backup_match($bf,$preferences,$question) {
-
-        global $CFG;
-
-        $status = true;
-
-        $matchs = get_records("question_match_sub","question",$question,"id");
-        //If there are matchs
-        if ($matchs) {
-            $status = fwrite ($bf,start_tag("MATCHS",6,true));
-            //Iterate over each match
-            foreach ($matchs as $match) {
-                $status = fwrite ($bf,start_tag("MATCH",7,true));
-                //Print match contents
-                fwrite ($bf,full_tag("ID",8,false,$match->id));
-                fwrite ($bf,full_tag("CODE",8,false,$match->code));
-                fwrite ($bf,full_tag("QUESTIONTEXT",8,false,$match->questiontext));
-                fwrite ($bf,full_tag("ANSWERTEXT",8,false,$match->answertext));
-                $status = fwrite ($bf,end_tag("MATCH",7,true));
-            }
-            $status = fwrite ($bf,end_tag("MATCHS",6,true));
-        }
-        return $status;
-    }
-
-    //This function backups the data in a numerical question (qtype=8) and its
-    //asociated data
-    function question_backup_numerical($bf,$preferences,$question,$level=6) {
-
-        global $CFG;
-
-        $status = true;
-
-        $numericals = get_records("question_numerical","question",$question,"id");
-        //If there are numericals
-        if ($numericals) {
-            //Iterate over each numerical
-            foreach ($numericals as $numerical) {
-                $status = fwrite ($bf,start_tag("NUMERICAL",$level,true));
-                //Print numerical contents
-                fwrite ($bf,full_tag("ANSWER",$level+1,false,$numerical->answer));
-                fwrite ($bf,full_tag("TOLERANCE",$level+1,false,$numerical->tolerance));
-                //Now backup numerical_units
-                $status = question_backup_numerical_units($bf,$preferences,$question,7);
-                $status = fwrite ($bf,end_tag("NUMERICAL",$level,true));
-            }
-            //Now print question_answers
-            $status = question_backup_answers($bf,$preferences,$question);
-        }
-        return $status;
-    }
-
-    //This function backups the data in a multianswer question (qtype=9) and its
-    //asociated data
-    function question_backup_multianswer($bf,$preferences,$question) {
-
-        global $CFG;
-
-        $status = true;
-
-        $multianswers = get_records("question_multianswer","question",$question,"id");
-        //If there are multianswers
-        if ($multianswers) {
-            //Print multianswers header
-            $status = fwrite ($bf,start_tag("MULTIANSWERS",6,true));
-            //Iterate over each multianswer
-            foreach ($multianswers as $multianswer) {
-                $status = fwrite ($bf,start_tag("MULTIANSWER",7,true));
-                //Print multianswer contents
-                fwrite ($bf,full_tag("ID",8,false,$multianswer->id));
-                fwrite ($bf,full_tag("QUESTION",8,false,$multianswer->question));
-                fwrite ($bf,full_tag("SEQUENCE",8,false,$multianswer->sequence));
-                $status = fwrite ($bf,end_tag("MULTIANSWER",7,true));
-            }
-            //Print multianswers footer
-            $status = fwrite ($bf,end_tag("MULTIANSWERS",6,true));
-            //Now print question_answers
-            $status = question_backup_answers($bf,$preferences,$question);
-        }
-        return $status;
-    }
-
-    //This function backups the data in a calculated question (qtype=10) and its
-    //asociated data
-    function question_backup_calculated($bf,$preferences,$question,$level=6,$include_answers=true) {
-
-        global $CFG;
-
-        $status = true;
-
-        $calculateds = get_records("question_calculated","question",$question,"id");
-        //If there are calculated-s
-        if ($calculateds) {
-            //Iterate over each calculateds
-            foreach ($calculateds as $calculated) {
-                $status = $status &&fwrite ($bf,start_tag("CALCULATED",$level,true));
-                //Print calculated contents
-                fwrite ($bf,full_tag("ANSWER",$level+1,false,$calculated->answer));
-                fwrite ($bf,full_tag("TOLERANCE",$level+1,false,$calculated->tolerance));
-                fwrite ($bf,full_tag("TOLERANCETYPE",$level+1,false,$calculated->tolerancetype));
-                fwrite ($bf,full_tag("CORRECTANSWERLENGTH",$level+1,false,$calculated->correctanswerlength));
-                fwrite ($bf,full_tag("CORRECTANSWERFORMAT",$level+1,false,$calculated->correctanswerformat));
-                //Now backup numerical_units
-                $status = question_backup_numerical_units($bf,$preferences,$question,7);
-                //Now backup required dataset definitions and items...
-                $status = question_backup_datasets($bf,$preferences,$question,7);
-                //End calculated data
-                $status = $status &&fwrite ($bf,end_tag("CALCULATED",$level,true));
-            }
-            //Now print question_answers
-            if ($include_answers) {
-                $status = question_backup_answers($bf,$preferences,$question);
-            }
-        }
-        return $status;
-    }
-
-    //This function backups the data in an rqp question (qtype=11) and its
-    //asociated data
-    function question_backup_rqp($bf,$preferences,$question) {
-
-        global $CFG;
-
-        $status = true;
-
-        $rqp = get_records("question_rqp","question",$question,"id");
-        //If there are rqps
-        if ($rqps) {
-            //Iterate over each rqp
-            foreach ($rqps as $rqp) {
-                $status = fwrite ($bf,start_tag("RQP",6,true));
-                //Print rqp contents
-                fwrite ($bf,full_tag("TYPE",7,false,$rqp->type));
-                fwrite ($bf,full_tag("SOURCE",7,false,$rqp->source));
-                fwrite ($bf,full_tag("FORMAT",7,false,$rqp->format));
-                fwrite ($bf,full_tag("FLAGS",7,false,$rqp->flags));
-                fwrite ($bf,full_tag("MAXSCORE",7,false,$rqp->maxscore));
-                $status = fwrite ($bf,end_tag("RQP",6,true));
-            }
-        }
-        return $status;
-    }
-    
-    //This function backups the data in an essay question (qtype=12) and its
-    //asociated data
-    function question_backup_essay($bf,$preferences,$question,$level=6) {
-
-        global $CFG;
-
-        $status = true;
-
-        $essays = get_records('question_essay', 'question', $question, "id");
-        //If there are essays
-        if ($essays) {
-            //Iterate over each essay
-            foreach ($essays as $essay) {
-                $status = fwrite ($bf,start_tag("ESSAY",$level,true));
-                //Print essay contents
-                fwrite ($bf,full_tag("ANSWER",$level+1,false,$essay->answer));                
-                $status = fwrite ($bf,end_tag("ESSAY",$level,true));
-            }
-            //Now print question_answers
-            $status = question_backup_answers($bf,$preferences,$question);
-        }
-        return $status;
-    }
-
-
     //This function backups the answers data in some question types
     //(truefalse, shortanswer,multichoice,numerical,calculated)
     function question_backup_answers($bf,$preferences,$question) {
index bc00bd85a3a48fbb9638b87bc30088602d6a2dad..50cd73e695cecaede20edb338fb9603f724e6fcb 100644 (file)
@@ -597,6 +597,42 @@ class question_calculated_qtype extends question_dataset_dependent_questiontype
         }
         return $str;
     }
+    
+/// BACKUP FUNCTIONS ////////////////////////////
+
+    /*
+     * Backup the data in the question
+     *
+     * This is used in question/backuplib.php
+     */
+    function backup($bf,$preferences,$question,$level=6) {
+
+        $status = true;
+
+        $calculateds = get_records("question_calculated","question",$question,"id");
+        //If there are calculated-s
+        if ($calculateds) {
+            //Iterate over each calculateds
+            foreach ($calculateds as $calculated) {
+                $status = $status &&fwrite ($bf,start_tag("CALCULATED",$level,true));
+                //Print calculated contents
+                fwrite ($bf,full_tag("ANSWER",$level+1,false,$calculated->answer));
+                fwrite ($bf,full_tag("TOLERANCE",$level+1,false,$calculated->tolerance));
+                fwrite ($bf,full_tag("TOLERANCETYPE",$level+1,false,$calculated->tolerancetype));
+                fwrite ($bf,full_tag("CORRECTANSWERLENGTH",$level+1,false,$calculated->correctanswerlength));
+                fwrite ($bf,full_tag("CORRECTANSWERFORMAT",$level+1,false,$calculated->correctanswerformat));
+                //Now backup numerical_units
+                $status = question_backup_numerical_units($bf,$preferences,$question,7);
+                //Now backup required dataset definitions and items...
+                $status = question_backup_datasets($bf,$preferences,$question,7);
+                //End calculated data
+                $status = $status &&fwrite ($bf,end_tag("CALCULATED",$level,true));
+            }
+            //Now print question_answers
+            $status = question_backup_answers($bf,$preferences,$question);
+        }
+        return $status;
+    }
 }
 //// END OF CLASS ////
 
index 8b86cfe167b1d93e05b397178a047a23ad1c091a..03bbe2c02cd745a923ec1ac94090d3d7901c400f 100644 (file)
@@ -307,6 +307,33 @@ class question_essay_qtype extends default_questiontype {
     
         return array($ungradedcount, count($usercount));
     }
+    
+/// BACKUP FUNCTIONS ////////////////////////////
+
+    /*
+     * Backup the data in a truefalse question
+     *
+     * This is used in question/backuplib.php
+     */
+    function backup($bf,$preferences,$question,$level=6) {
+
+        $status = true;
+
+        $essays = get_records('question_essay', 'question', $question, "id");
+        //If there are essays
+        if ($essays) {
+            //Iterate over each essay
+            foreach ($essays as $essay) {
+                $status = fwrite ($bf,start_tag("ESSAY",$level,true));
+                //Print essay contents
+                fwrite ($bf,full_tag("ANSWER",$level+1,false,$essay->answer));                
+                $status = fwrite ($bf,end_tag("ESSAY",$level,true));
+            }
+            //Now print question_answers
+            $status = question_backup_answers($bf,$preferences,$question);
+        }
+        return $status;
+    }
 
 }
 //// END OF CLASS ////
index f884b1f8a79f554b76b883fae28136ab791432d2..c27c122df20ab970f0c2512509ab16a6c990b4a4 100644 (file)
@@ -334,7 +334,36 @@ class question_match_qtype extends default_questiontype {
             return null;
         }
     }
-
+    
+/// BACKUP FUNCTIONS ////////////////////////////
+
+    /*
+     * Backup the data in the question
+     *
+     * This is used in question/backuplib.php
+     */
+    function backup($bf,$preferences,$question,$level=6) {
+
+        $status = true;
+
+        $matchs = get_records("question_match_sub","question",$question,"id");
+        //If there are matchs
+        if ($matchs) {
+            $status = fwrite ($bf,start_tag("MATCHS",6,true));
+            //Iterate over each match
+            foreach ($matchs as $match) {
+                $status = fwrite ($bf,start_tag("MATCH",7,true));
+                //Print match contents
+                fwrite ($bf,full_tag("ID",8,false,$match->id));
+                fwrite ($bf,full_tag("CODE",8,false,$match->code));
+                fwrite ($bf,full_tag("QUESTIONTEXT",8,false,$match->questiontext));
+                fwrite ($bf,full_tag("ANSWERTEXT",8,false,$match->answertext));
+                $status = fwrite ($bf,end_tag("MATCH",7,true));
+            }
+            $status = fwrite ($bf,end_tag("MATCHS",6,true));
+        }
+        return $status;
+    }
 
 }
 //// END OF CLASS ////
index be91d5b327a1127b3a25732e2d1c37d6671bbb4d..a29a2b1f2e7b7ac49848f2db523c96f96e7c684e 100644 (file)
@@ -378,6 +378,40 @@ class quiz_embedded_cloze_qtype extends default_questiontype {
         }
         return $responses;
     }
+    
+/// BACKUP FUNCTIONS ////////////////////////////
+
+    /*
+     * Backup the data in the question
+     *
+     * This is used in question/backuplib.php
+     */
+    function backup($bf,$preferences,$question,$level=6) {
+
+        $status = true;
+
+        $multianswers = get_records("question_multianswer","question",$question,"id");
+        //If there are multianswers
+        if ($multianswers) {
+            //Print multianswers header
+            $status = fwrite ($bf,start_tag("MULTIANSWERS",$level,true));
+            //Iterate over each multianswer
+            foreach ($multianswers as $multianswer) {
+                $status = fwrite ($bf,start_tag("MULTIANSWER",$level+1,true));
+                //Print multianswer contents
+                fwrite ($bf,full_tag("ID",$level+2,false,$multianswer->id));
+                fwrite ($bf,full_tag("QUESTION",$level+2,false,$multianswer->question));
+                fwrite ($bf,full_tag("SEQUENCE",$level+2,false,$multianswer->sequence));
+                $status = fwrite ($bf,end_tag("MULTIANSWER",$level+1,true));
+            }
+            //Print multianswers footer
+            $status = fwrite ($bf,end_tag("MULTIANSWERS",$level,true));
+            //Now print question_answers
+            $status = question_backup_answers($bf,$preferences,$question);
+        }
+        return $status;
+    }
+
 }
 //// END OF CLASS ////
 
index 6beed5c123976b60d2a0f45f174c77a8903c38e9..a7602f8fecd57f63dd44290c935b39edd0c92ba3 100644 (file)
@@ -370,6 +370,38 @@ class question_multichoice_qtype extends default_questiontype {
         }
         return $responses;
     }
+    
+/// BACKUP FUNCTIONS ////////////////////////////
+
+    /*
+     * Backup the data in the question
+     *
+     * This is used in question/backuplib.php
+     */
+    function backup($bf,$preferences,$question,$level=6) {
+
+        $status = true;
+
+        $multichoices = get_records("question_multichoice","question",$question,"id");
+        //If there are multichoices
+        if ($multichoices) {
+            //Iterate over each multichoice
+            foreach ($multichoices as $multichoice) {
+                $status = fwrite ($bf,start_tag("MULTICHOICE",$level,true));
+                //Print multichoice contents
+                fwrite ($bf,full_tag("LAYOUT",$level+1,false,$multichoice->layout));
+                fwrite ($bf,full_tag("ANSWERS",$level+1,false,$multichoice->answers));
+                fwrite ($bf,full_tag("SINGLE",$level+1,false,$multichoice->single));
+                fwrite ($bf,full_tag("SHUFFLEANSWERS",$level+1,false,$randomsamatch->shuffleanswers));
+                $status = fwrite ($bf,end_tag("MULTICHOICE",$level,true));
+            }
+
+            //Now print question_answers
+            $status = question_backup_answers($bf,$preferences,$question);
+        }
+        return $status;
+    }
+
 }
 //// END OF CLASS ////
 
index fadd95c3c24ac7420ff0db5e5cc40c995e5bd1cf..a8c3b620f768754d1ce1ef3025761859dda150db 100644 (file)
@@ -406,6 +406,37 @@ class question_numerical_qtype extends question_shortanswer_qtype {
         }
         return $rawresponse;
     }
+    
+/// BACKUP FUNCTIONS ////////////////////////////
+
+    /*
+     * Backup the data in the question
+     *
+     * This is used in question/backuplib.php
+     */
+    function backup($bf,$preferences,$question,$level=6) {
+
+        $status = true;
+
+        $numericals = get_records("question_numerical","question",$question,"id");
+        //If there are numericals
+        if ($numericals) {
+            //Iterate over each numerical
+            foreach ($numericals as $numerical) {
+                $status = fwrite ($bf,start_tag("NUMERICAL",$level,true));
+                //Print numerical contents
+                fwrite ($bf,full_tag("ANSWER",$level+1,false,$numerical->answer));
+                fwrite ($bf,full_tag("TOLERANCE",$level+1,false,$numerical->tolerance));
+                //Now backup numerical_units
+                $status = question_backup_numerical_units($bf,$preferences,$question,7);
+                $status = fwrite ($bf,end_tag("NUMERICAL",$level,true));
+            }
+            //Now print question_answers
+            $status = question_backup_answers($bf,$preferences,$question);
+        }
+        return $status;
+    }
+
 }
 //// END OF CLASS ////
 
index ff68a13a8a94d08aa7e8dede0cfebd5fe4f67e8e..1f9b1e922bcf239eedac86a0fe4a38a84b8256c0 100644 (file)
@@ -942,6 +942,19 @@ class default_questiontype {
         echo '<input type="hidden" name="versioning" value="on" />
               </td></tr>';
     }
+    
+/// BACKUP FUNCTIONS ////////////////////////////
+
+    /*
+     * Backup the data in the question
+     *
+     * This is used in question/backuplib.php
+     */
+    function backup($bf,$preferences,$question,$level=6) {
+        // The default type has nothing to back up
+        return true;
+    }
+
 
 }
 
index 2009d73568d7b0b32bae02cb730c20e44081f14f..a888901a096e1da2ce45b415b9976d246dc5d1bc 100644 (file)
@@ -241,6 +241,32 @@ class question_randomsamatch_qtype extends question_match_qtype {
          "AND hidden = '0'" .
          "AND id NOT IN ($questionsinuse)");
     }
+    
+/// BACKUP FUNCTIONS ////////////////////////////
+
+    /*
+     * Backup the data in the question
+     *
+     * This is used in question/backuplib.php
+     */
+    function backup($bf,$preferences,$question,$level=6) {
+
+        $status = true;
+
+        $randomsamatchs = get_records("question_randomsamatch","question",$question,"id");
+        //If there are randomsamatchs
+        if ($randomsamatchs) {
+            //Iterate over each randomsamatch
+            foreach ($randomsamatchs as $randomsamatch) {
+                $status = fwrite ($bf,start_tag("RANDOMSAMATCH",6,true));
+                //Print randomsamatch contents
+                fwrite ($bf,full_tag("CHOOSE",7,false,$randomsamatch->choose));
+                fwrite ($bf,full_tag("SHUFFLEANSWERS",7,false,$randomsamatch->shuffleanswers));
+                $status = fwrite ($bf,end_tag("RANDOMSAMATCH",6,true));
+            }
+        }
+        return $status;
+    }
 }
 
 //// END OF CLASS ////
index bb55188366b32924d113cc3738ff36e56e09bec0..3546e9e5a49f487fb2f1eb7a19ea7b4c4dcc0278 100644 (file)
@@ -437,6 +437,35 @@ class question_rqp_qtype extends default_questiontype {
         $link->link = 'types.php';
         return array($link);
     }
+    
+/// BACKUP FUNCTIONS ////////////////////////////
+
+    /*
+     * Backup the data in the question
+     *
+     * This is used in question/backuplib.php
+     */
+    function backup($bf,$preferences,$question,$level=6) {
+
+        $status = true;
+
+        $rqps = get_records("question_rqp","question",$question,"id");
+        //If there are rqps
+        if ($rqps) {
+            //Iterate over each rqp
+            foreach ($rqps as $rqp) {
+                $status = fwrite ($bf,start_tag("RQP",$level,true));
+                //Print rqp contents
+                fwrite ($bf,full_tag("TYPE",$level+1,false,$rqp->type));
+                fwrite ($bf,full_tag("SOURCE",$level+1,false,$rqp->source));
+                fwrite ($bf,full_tag("FORMAT",$level+1,false,$rqp->format));
+                fwrite ($bf,full_tag("FLAGS",$level+1,false,$rqp->flags));
+                fwrite ($bf,full_tag("MAXSCORE",$level+1,false,$rqp->maxscore));
+                $status = fwrite ($bf,end_tag("RQP",$level,true));
+            }
+        }
+        return $status;
+    }
 
 }
 //////////////////////////////////////////////////////////////////////////
index 62f39ad03938e70ca52b39272fea005c2e7ca8ce..1392702cd7466af5fa34052dc0c42539a4626be0 100644 (file)
@@ -243,6 +243,34 @@ class question_shortanswer_qtype extends default_questiontype {
 
         return false;
     }
+    
+/// BACKUP FUNCTIONS ////////////////////////////
+
+    /*
+     * Backup the data in the question
+     *
+     * This is used in question/backuplib.php
+     */
+    function backup($bf,$preferences,$question,$level=6) {
+
+        $status = true;
+
+        $shortanswers = get_records("question_shortanswer","question",$question,"id");
+        //If there are shortanswers
+        if ($shortanswers) {
+            //Iterate over each shortanswer
+            foreach ($shortanswers as $shortanswer) {
+                $status = fwrite ($bf,start_tag("SHORTANSWER",$level,true));
+                //Print shortanswer contents
+                fwrite ($bf,full_tag("ANSWERS",$level+1,false,$shortanswer->answers));
+                fwrite ($bf,full_tag("USECASE",$level+1,false,$shortanswer->usecase));
+                $status = fwrite ($bf,end_tag("SHORTANSWER",$level,true));
+            }
+            //Now print question_answers
+            $status = question_backup_answers($bf,$preferences,$question);
+        }
+        return $status;
+    }
 
 }
 //// END OF CLASS ////
index 17725f9c53791dd026e2e095a5f8bb0777a52633..7fd126e77b7c149b706433bae040b60d32776eac 100644 (file)
@@ -210,6 +210,35 @@ class question_truefalse_qtype extends default_questiontype {
         }
         return $responses;
     }
+    
+/// BACKUP FUNCTIONS ////////////////////////////
+
+    /*
+     * Backup the data in a truefalse question
+     *
+     * This is used in question/backuplib.php
+     */
+    function backup($bf,$preferences,$question,$level=6) {
+
+        $status = true;
+
+        $truefalses = get_records("question_truefalse","question",$question,"id");
+        //If there are truefalses
+        if ($truefalses) {
+            //Iterate over each truefalse
+            foreach ($truefalses as $truefalse) {
+                $status = fwrite ($bf,start_tag("TRUEFALSE",$level,true));
+                //Print truefalse contents
+                fwrite ($bf,full_tag("TRUEANSWER",$level+1,false,$truefalse->trueanswer));
+                fwrite ($bf,full_tag("FALSEANSWER",$level+1,false,$truefalse->falseanswer));
+                $status = fwrite ($bf,end_tag("TRUEFALSE",$level,true));
+            }
+            //Now print question_answers
+            $status = question_backup_answers($bf,$preferences,$question);
+        }
+        return $status;
+    }
+
 }
 //// END OF CLASS ////