mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
Moved questiontype specific backup functions into questiontype classes
This commit is contained in:
parent
42431d7a30
commit
c5d94c4150
13 changed files with 319 additions and 302 deletions
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 ////
|
||||
|
||||
|
|
|
@ -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 ////
|
||||
|
|
|
@ -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 ////
|
||||
|
|
|
@ -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 ////
|
||||
|
||||
|
|
|
@ -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 ////
|
||||
|
||||
|
|
|
@ -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 ////
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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 ////
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -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 ////
|
||||
|
|
|
@ -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 ////
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue