From: gustav_delius Date: Tue, 21 Mar 2006 18:15:09 +0000 (+0000) Subject: Moved questiontype specific backup functions into questiontype classes X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c5d94c41504aeed696ea3c893ba8a5a5a130b5d1;p=moodle.git Moved questiontype specific backup functions into questiontype classes --- diff --git a/mod/quiz/backuplib.php b/mod/quiz/backuplib.php index cd8af11a30..5dd69b3267 100644 --- a/mod/quiz/backuplib.php +++ b/mod/quiz/backuplib.php @@ -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) diff --git a/question/backuplib.php b/question/backuplib.php index 2cedb66d8c..2d7aba9ed2 100644 --- a/question/backuplib.php +++ b/question/backuplib.php @@ -73,7 +73,7 @@ // //----------------------------------------------------------- - include_once($CFG->libdir.'/questionlib.php'); + require_once("$CFG->libdir/questionlib.php"); function backup_question_categories($bf,$preferences) { @@ -149,32 +149,8 @@ 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 @@ -193,280 +169,6 @@ 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) { diff --git a/question/questiontypes/calculated/questiontype.php b/question/questiontypes/calculated/questiontype.php index bc00bd85a3..50cd73e695 100644 --- a/question/questiontypes/calculated/questiontype.php +++ b/question/questiontypes/calculated/questiontype.php @@ -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 //// diff --git a/question/questiontypes/essay/questiontype.php b/question/questiontypes/essay/questiontype.php index 8b86cfe167..03bbe2c02c 100644 --- a/question/questiontypes/essay/questiontype.php +++ b/question/questiontypes/essay/questiontype.php @@ -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 //// diff --git a/question/questiontypes/match/questiontype.php b/question/questiontypes/match/questiontype.php index f884b1f8a7..c27c122df2 100644 --- a/question/questiontypes/match/questiontype.php +++ b/question/questiontypes/match/questiontype.php @@ -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 //// diff --git a/question/questiontypes/multianswer/questiontype.php b/question/questiontypes/multianswer/questiontype.php index be91d5b327..a29a2b1f2e 100644 --- a/question/questiontypes/multianswer/questiontype.php +++ b/question/questiontypes/multianswer/questiontype.php @@ -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 //// diff --git a/question/questiontypes/multichoice/questiontype.php b/question/questiontypes/multichoice/questiontype.php index 6beed5c123..a7602f8fec 100644 --- a/question/questiontypes/multichoice/questiontype.php +++ b/question/questiontypes/multichoice/questiontype.php @@ -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 //// diff --git a/question/questiontypes/numerical/questiontype.php b/question/questiontypes/numerical/questiontype.php index fadd95c3c2..a8c3b620f7 100644 --- a/question/questiontypes/numerical/questiontype.php +++ b/question/questiontypes/numerical/questiontype.php @@ -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 //// diff --git a/question/questiontypes/questiontype.php b/question/questiontypes/questiontype.php index ff68a13a8a..1f9b1e922b 100644 --- a/question/questiontypes/questiontype.php +++ b/question/questiontypes/questiontype.php @@ -942,6 +942,19 @@ class default_questiontype { echo ' '; } + +/// 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; + } + } diff --git a/question/questiontypes/randomsamatch/questiontype.php b/question/questiontypes/randomsamatch/questiontype.php index 2009d73568..a888901a09 100644 --- a/question/questiontypes/randomsamatch/questiontype.php +++ b/question/questiontypes/randomsamatch/questiontype.php @@ -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 //// diff --git a/question/questiontypes/rqp/questiontype.php b/question/questiontypes/rqp/questiontype.php index bb55188366..3546e9e5a4 100644 --- a/question/questiontypes/rqp/questiontype.php +++ b/question/questiontypes/rqp/questiontype.php @@ -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; + } } ////////////////////////////////////////////////////////////////////////// diff --git a/question/questiontypes/shortanswer/questiontype.php b/question/questiontypes/shortanswer/questiontype.php index 62f39ad039..1392702cd7 100644 --- a/question/questiontypes/shortanswer/questiontype.php +++ b/question/questiontypes/shortanswer/questiontype.php @@ -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 //// diff --git a/question/questiontypes/truefalse/questiontype.php b/question/questiontypes/truefalse/questiontype.php index 17725f9c53..7fd126e77b 100644 --- a/question/questiontypes/truefalse/questiontype.php +++ b/question/questiontypes/truefalse/questiontype.php @@ -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 ////