//
//-----------------------------------------------------------
- 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) {