+++ /dev/null
-<?php
- function question_calculated_restore($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
-
- $status = true;
-
- //Get the calculated-s array
- $calculateds = $info['#']['CALCULATED'];
-
- //Iterate over calculateds
- for($i = 0; $i < sizeof($calculateds); $i++) {
- $cal_info = $calculateds[$i];
- //traverse_xmlize($cal_info); //Debug
- //print_object ($GLOBALS['traverse_array']); //Debug
- //$GLOBALS['traverse_array']=""; //Debug
-
- //Now, build the question_calculated record structure
- $calculated->question = $new_question_id;
- $calculated->answer = backup_todb($cal_info['#']['ANSWER']['0']['#']);
- $calculated->tolerance = backup_todb($cal_info['#']['TOLERANCE']['0']['#']);
- $calculated->tolerancetype = backup_todb($cal_info['#']['TOLERANCETYPE']['0']['#']);
- $calculated->correctanswerlength = backup_todb($cal_info['#']['CORRECTANSWERLENGTH']['0']['#']);
- $calculated->correctanswerformat = backup_todb($cal_info['#']['CORRECTANSWERFORMAT']['0']['#']);
-
- ////We have to recode the answer field
- $answer = backup_getid($restore->backup_unique_code,"question_answers",$calculated->answer);
- if ($answer) {
- $calculated->answer = $answer->new_id;
- }
-
- //The structure is equal to the db, so insert the question_calculated
- $newid = insert_record ("question_calculated",$calculated);
-
- //Do some output
- if (($i+1) % 50 == 0) {
- if (!defined('RESTORE_SILENTLY')) {
- echo ".";
- if (($i+1) % 1000 == 0) {
- echo "<br />";
- }
- }
- backup_flush(300);
- }
-
- //Now restore numerical_units
- $status = question_restore_numerical_units ($old_question_id,$new_question_id,$cal_info,$restore);
-
- //Now restore dataset_definitions
- if ($status && $newid) {
- $status = question_restore_dataset_definitions ($old_question_id,$new_question_id,$cal_info,$restore);
- }
-
- if (!$newid) {
- $status = false;
- }
- }
-
- return $status;
- }
-?>
+++ /dev/null
-<?php
- function question_essay_restore($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
-
- $status = true;
-
- //Get the truefalse array
- $essays = $info['#']['ESSAY'];
-
- //Iterate over truefalse
- for($i = 0; $i < sizeof($essays); $i++) {
- $essay_info = $essays[$i];
- //traverse_xmlize($tru_info); //Debug
- //print_object ($GLOBALS['traverse_array']); //Debug
- //$GLOBALS['traverse_array']=""; //Debug
-
- //Now, build the question_essay record structure
- $essay->question = $new_question_id;
- $essay->answer = backup_todb($essay_info['#']['ANSWER']['0']['#']);
-
- ////We have to recode the answer field
- $answer = backup_getid($restore->backup_unique_code,"question_answers",$essay->answer);
- if ($answer) {
- $essay->answer = $answer->new_id;
- }
-
- //The structure is equal to the db, so insert the question_essay
- $newid = insert_record ("question_essay",$essay);
-
- //Do some output
- if (($i+1) % 50 == 0) {
- echo ".";
- if (($i+1) % 1000 == 0) {
- echo "<br />";
- }
- backup_flush(300);
- }
-
- if (!$newid) {
- $status = false;
- }
- }
-
- return $status;
- }
-
-
- //This function restores the question_essay_states
- function question_essay_states_restore($state_id,$info,$restore) {
-
- global $CFG;
-
- $status = true;
-
- //Get the question_essay_state
- $essay_state = $info['#']['ESSAY_STATE']['0'];
- if ($essay_state) {
-
- //Now, build the ESSAY_STATES record structure
- $state->stateid = $state_id;
- $state->graded = backup_todb($essay_state['#']['GRADED']['0']['#']);
- $state->fraction = backup_todb($essay_state['#']['FRACTION']['0']['#']);
- $state->response = backup_todb($essay_state['#']['RESPONSE']['0']['#']);
-
- //The structure is equal to the db, so insert the question_states
- $newid = insert_record ("question_essay_states",$state);
- }
-
- return $status;
- }
-
-?>
+++ /dev/null
-<?php
- function question_match_restore($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
-
- $status = true;
-
- //Get the matchs array
- $matchs = $info['#']['MATCHS']['0']['#']['MATCH'];
-
- //We have to build the subquestions field (a list of match_sub id)
- $subquestions_field = "";
- $in_first = true;
-
- //Iterate over matchs
- for($i = 0; $i < sizeof($matchs); $i++) {
- $mat_info = $matchs[$i];
- //traverse_xmlize($mat_info); //Debug
- //print_object ($GLOBALS['traverse_array']); //Debug
- //$GLOBALS['traverse_array']=""; //Debug
-
- //We'll need this later!!
- $oldid = backup_todb($mat_info['#']['ID']['0']['#']);
-
- //Now, build the question_match_SUB record structure
- $match_sub->question = $new_question_id;
- $match_sub->code = backup_todb($mat_info['#']['CODE']['0']['#']);
- if (!$match_sub->code) {
- $match_sub->code = $oldid;
- }
- $match_sub->questiontext = backup_todb($mat_info['#']['QUESTIONTEXT']['0']['#']);
- $match_sub->answertext = backup_todb($mat_info['#']['ANSWERTEXT']['0']['#']);
-
- //The structure is equal to the db, so insert the question_match_sub
- $newid = insert_record ("question_match_sub",$match_sub);
-
- //Do some output
- if (($i+1) % 50 == 0) {
- if (!defined('RESTORE_SILENTLY')) {
- echo ".";
- if (($i+1) % 1000 == 0) {
- echo "<br />";
- }
- }
- backup_flush(300);
- }
-
- if ($newid) {
- //We have the newid, update backup_ids
- backup_putid($restore->backup_unique_code,"question_match_sub",$oldid,
- $newid);
- //We have a new match_sub, append it to subquestions_field
- if ($in_first) {
- $subquestions_field .= $newid;
- $in_first = false;
- } else {
- $subquestions_field .= ",".$newid;
- }
- } else {
- $status = false;
- }
- }
-
- //We have created every match_sub, now create the match
- $match->question = $new_question_id;
- $match->subquestions = $subquestions_field;
-
- //The structure is equal to the db, so insert the question_match_sub
- $newid = insert_record ("question_match",$match);
-
- if (!$newid) {
- $status = false;
- }
-
- return $status;
- }
-
- function question_match_restore_map($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
-
- $status = true;
-
- //Get the matchs array
- $matchs = $info['#']['MATCHS']['0']['#']['MATCH'];
-
- //We have to build the subquestions field (a list of match_sub id)
- $subquestions_field = "";
- $in_first = true;
-
- //Iterate over matchs
- for($i = 0; $i < sizeof($matchs); $i++) {
- $mat_info = $matchs[$i];
- //traverse_xmlize($mat_info); //Debug
- //print_object ($GLOBALS['traverse_array']); //Debug
- //$GLOBALS['traverse_array']=""; //Debug
-
- //We'll need this later!!
- $oldid = backup_todb($mat_info['#']['ID']['0']['#']);
-
- //Now, build the question_match_SUB record structure
- $match_sub->question = $new_question_id;
- $match_sub->questiontext = backup_todb($mat_info['#']['QUESTIONTEXT']['0']['#']);
- $match_sub->answertext = backup_todb($mat_info['#']['ANSWERTEXT']['0']['#']);
-
- //If we are in this method is because the question exists in DB, so its
- //match_sub must exist too.
- //Now, we are going to look for that match_sub in DB and to create the
- //mappings in backup_ids to use them later where restoring states (user level).
-
- //Get the match_sub from DB (by question, questiontext and answertext)
- $db_match_sub = get_record ("question_match_sub","question",$new_question_id,
- "questiontext",$match_sub->questiontext,
- "answertext",$match_sub->answertext);
- //Do some output
- if (($i+1) % 50 == 0) {
- if (!defined('RESTORE_SILENTLY')) {
- echo ".";
- if (($i+1) % 1000 == 0) {
- echo "<br />";
- }
- }
- backup_flush(300);
- }
-
- //We have the database match_sub, so update backup_ids
- if ($db_match_sub) {
- //We have the newid, update backup_ids
- backup_putid($restore->backup_unique_code,"question_match_sub",$oldid,
- $db_match_sub->id);
- } else {
- $status = false;
- }
- }
-
- return $status;
- }
-?>
+++ /dev/null
-<?php
- function question_multianswer_restore($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
-
- $status = true;
-
- //Get the multianswers array
- $multianswers = $info['#']['MULTIANSWERS']['0']['#']['MULTIANSWER'];
- //Iterate over multianswers
- for($i = 0; $i < sizeof($multianswers); $i++) {
- $mul_info = $multianswers[$i];
- //traverse_xmlize($mul_info); //Debug
- //print_object ($GLOBALS['traverse_array']); //Debug
- //$GLOBALS['traverse_array']=""; //Debug
-
- //We need this later
- $oldid = backup_todb($mul_info['#']['ID']['0']['#']);
-
- //Now, build the question_multianswer record structure
- $multianswer->question = $new_question_id;
- $multianswer->sequence = backup_todb($mul_info['#']['SEQUENCE']['0']['#']);
-
- //We have to recode the sequence field (a list of question ids)
- //Extracts question id from sequence
- $sequence_field = "";
- $in_first = true;
- $tok = strtok($multianswer->sequence,",");
- while ($tok) {
- //Get the answer from backup_ids
- $question = backup_getid($restore->backup_unique_code,"question",$tok);
- if ($question) {
- if ($in_first) {
- $sequence_field .= $question->new_id;
- $in_first = false;
- } else {
- $sequence_field .= ",".$question->new_id;
- }
- }
- //check for next
- $tok = strtok(",");
- }
- //We have the answers field recoded to its new ids
- $multianswer->sequence = $sequence_field;
- //The structure is equal to the db, so insert the question_multianswer
- $newid = insert_record ("question_multianswer",$multianswer);
-
- //Save ids in backup_ids
- if ($newid) {
- backup_putid($restore->backup_unique_code,"question_multianswer",
- $oldid, $newid);
- }
-
- //Do some output
- if (($i+1) % 50 == 0) {
- if (!defined('RESTORE_SILENTLY')) {
- echo ".";
- if (($i+1) % 1000 == 0) {
- echo "<br />";
- }
- }
- backup_flush(300);
- }
-/*
- //If we have created the question_multianswer record, now, depending of the
- //answertype, delegate the restore to every qtype function
- if ($newid) {
- if ($multianswer->answertype == "1") {
- $status = quiz_restore_shortanswer ($old_question_id,$new_question_id,$mul_info,$restore);
- } else if ($multianswer->answertype == "3") {
- $status = quiz_restore_multichoice ($old_question_id,$new_question_id,$mul_info,$restore);
- } else if ($multianswer->answertype == "8") {
- $status = quiz_restore_numerical ($old_question_id,$new_question_id,$mul_info,$restore);
- }
- } else {
- $status = false;
- }
-*/
- }
-
- return $status;
- }
-
- function question_multianswer_restore_map($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
-
- $status = true;
-
- //Get the multianswers array
- $multianswers = $info['#']['MULTIANSWERS']['0']['#']['MULTIANSWER'];
- //Iterate over multianswers
- for($i = 0; $i < sizeof($multianswers); $i++) {
- $mul_info = $multianswers[$i];
- //traverse_xmlize($mul_info); //Debug
- //print_object ($GLOBALS['traverse_array']); //Debug
- //$GLOBALS['traverse_array']=""; //Debug
-
- //We need this later
- $oldid = backup_todb($mul_info['#']['ID']['0']['#']);
-
- //Now, build the question_multianswer record structure
- $multianswer->question = $new_question_id;
- $multianswer->answers = backup_todb($mul_info['#']['ANSWERS']['0']['#']);
- $multianswer->positionkey = backup_todb($mul_info['#']['POSITIONKEY']['0']['#']);
- $multianswer->answertype = backup_todb($mul_info['#']['ANSWERTYPE']['0']['#']);
- $multianswer->norm = backup_todb($mul_info['#']['NORM']['0']['#']);
-
- //If we are in this method is because the question exists in DB, so its
- //multianswer must exist too.
- //Now, we are going to look for that multianswer in DB and to create the
- //mappings in backup_ids to use them later where restoring states (user level).
-
- //Get the multianswer from DB (by question and positionkey)
- $db_multianswer = get_record ("question_multianswer","question",$new_question_id,
- "positionkey",$multianswer->positionkey);
- //Do some output
- if (($i+1) % 50 == 0) {
- if (!defined('RESTORE_SILENTLY')) {
- echo ".";
- if (($i+1) % 1000 == 0) {
- echo "<br />";
- }
- }
- backup_flush(300);
- }
-
- //We have the database multianswer, so update backup_ids
- if ($db_multianswer) {
- //We have the newid, update backup_ids
- backup_putid($restore->backup_unique_code,"question_multianswer",$oldid,
- $db_multianswer->id);
- } else {
- $status = false;
- }
- }
-
- return $status;
- }
-
- function question_multianswer_recode_answer($state, $restore) {
- global $recodeansfns;
- //The answer is a comma separated list of hypen separated multianswer_id and answers. We must recode them.
- $answer_field = "";
- $in_first = true;
- $tok = strtok($state->answer,",");
- while ($tok) {
- //Extract the multianswer_id and the answer
- $exploded = explode("-",$tok);
- $multianswer_id = $exploded[0];
- $answer = $exploded[1];
- //Get the multianswer from backup_ids
- $mul = backup_getid($restore->backup_unique_code,"question_multianswer",$multianswer_id);
- if ($mul) {
- //Now, depending of the answertype field in question_multianswer
- //we do diferent things
- $mul_db = get_record ("question_multianswer","id",$mul->new_id);
- if (isset($recodeansfns[$question->type])) {
- }
-
- //Finaly, build the new answer field for each pair
- if ($in_first) {
- $answer_field .= $mul->new_id."-".$answer;
- $in_first = false;
- } else {
- $answer_field .= ",".$mul->new_id."-".$answer;
- }
- }
- //check for next
- $tok = strtok(",");
- }
- return $answer_field;
- }
-
-?>
+++ /dev/null
-<?php
- function question_multichoice_restore($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
-
- $status = true;
-
- //Get the multichoices array
- $multichoices = $info['#']['MULTICHOICE'];
-
- //Iterate over multichoices
- for($i = 0; $i < sizeof($multichoices); $i++) {
- $mul_info = $multichoices[$i];
- //traverse_xmlize($mul_info); //Debug
- //print_object ($GLOBALS['traverse_array']); //Debug
- //$GLOBALS['traverse_array']=""; //Debug
-
- //Now, build the question_multichoice record structure
- $multichoice->question = $new_question_id;
- $multichoice->layout = backup_todb($mul_info['#']['LAYOUT']['0']['#']);
- $multichoice->answers = backup_todb($mul_info['#']['ANSWERS']['0']['#']);
- $multichoice->single = backup_todb($mul_info['#']['SINGLE']['0']['#']);
- $multichoice->shuffleanswers = backup_todb($mul_info['#']['SHUFFLEANSWERS']['0']['#']);
-
- //We have to recode the answers field (a list of answers id)
- //Extracts answer id from sequence
- $answers_field = "";
- $in_first = true;
- $tok = strtok($multichoice->answers,",");
- while ($tok) {
- //Get the answer from backup_ids
- $answer = backup_getid($restore->backup_unique_code,"question_answers",$tok);
- if ($answer) {
- if ($in_first) {
- $answers_field .= $answer->new_id;
- $in_first = false;
- } else {
- $answers_field .= ",".$answer->new_id;
- }
- }
- //check for next
- $tok = strtok(",");
- }
- //We have the answers field recoded to its new ids
- $multichoice->answers = $answers_field;
-
- //The structure is equal to the db, so insert the question_shortanswer
- $newid = insert_record ("question_multichoice",$multichoice);
-
- //Do some output
- if (($i+1) % 50 == 0) {
- if (!defined('RESTORE_SILENTLY')) {
- echo ".";
- if (($i+1) % 1000 == 0) {
- echo "<br />";
- }
- }
- backup_flush(300);
- }
-
- if (!$newid) {
- $status = false;
- }
- }
-
- return $status;
- }
-
- function question_multichoice_recode_answer($state, $restore) {
- $answer_field = "";
- $in_first = true;
- $tok = strtok($state->answer,",");
- while ($tok) {
- //Get the answer from backup_ids
- $answer = backup_getid($restore->backup_unique_code,"question_answers",$tok);
- if ($answer) {
- if ($in_first) {
- $answer_field .= $answer->new_id;
- $in_first = false;
- } else {
- $answer_field .= ",".$answer->new_id;
- }
- }
- //check for next
- $tok = strtok(",");
- }
- return $answer_field;
- }
-
-?>
+++ /dev/null
-<?php
- function question_numerical_restore($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
-
- $status = true;
-
- //Get the numerical array
- $numericals = $info['#']['NUMERICAL'];
-
- //Iterate over numericals
- for($i = 0; $i < sizeof($numericals); $i++) {
- $num_info = $numericals[$i];
- //traverse_xmlize($num_info); //Debug
- //print_object ($GLOBALS['traverse_array']); //Debug
- //$GLOBALS['traverse_array']=""; //Debug
-
- //Now, build the question_numerical record structure
- $numerical->question = $new_question_id;
- $numerical->answer = backup_todb($num_info['#']['ANSWER']['0']['#']);
- $numerical->tolerance = backup_todb($num_info['#']['TOLERANCE']['0']['#']);
-
- ////We have to recode the answer field
- $answer = backup_getid($restore->backup_unique_code,"question_answers",$numerical->answer);
- if ($answer) {
- $numerical->answer = $answer->new_id;
- }
-
- //The structure is equal to the db, so insert the question_numerical
- $newid = insert_record ("question_numerical",$numerical);
-
- //Do some output
- if (($i+1) % 50 == 0) {
- if (!defined('RESTORE_SILENTLY')) {
- echo ".";
- if (($i+1) % 1000 == 0) {
- echo "<br />";
- }
- }
- backup_flush(300);
- }
-
- //Now restore numerical_units
- $status = question_restore_numerical_units ($old_question_id,$new_question_id,$num_info,$restore);
-
- if (!$newid) {
- $status = false;
- }
- }
-
- return $status;
- }
-?>
+++ /dev/null
-<?php
- function question_random_recode_answer($state, $restore) {
- $answer = backup_getid($restore->backup_unique_code,"question_answers",$state->answer);
- if ($answer) {
- return $answer->new_id;
- }
- return '';
- }
-?>
+++ /dev/null
-<?php
- function question_randomsamatch_restore($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
-
- $status = true;
-
- //Get the randomsamatchs array
- $randomsamatchs = $info['#']['RANDOMSAMATCH'];
-
- //Iterate over randomsamatchs
- for($i = 0; $i < sizeof($randomsamatchs); $i++) {
- $ran_info = $randomsamatchs[$i];
- //traverse_xmlize($ran_info); //Debug
- //print_object ($GLOBALS['traverse_array']); //Debug
- //$GLOBALS['traverse_array']=""; //Debug
-
- //Now, build the question_randomsamatch record structure
- $randomsamatch->question = $new_question_id;
- $randomsamatch->choose = backup_todb($ran_info['#']['CHOOSE']['0']['#']);
- $randomsamatch->shuffleanswers = backup_todb($ran_info['#']['SHUFFLEANSWERS']['0']['#']);
-
- //The structure is equal to the db, so insert the question_randomsamatch
- $newid = insert_record ("question_randomsamatch",$randomsamatch);
-
- //Do some output
- if (($i+1) % 50 == 0) {
- if (!defined('RESTORE_SILENTLY')) {
- echo ".";
- if (($i+1) % 1000 == 0) {
- echo "<br />";
- }
- }
- backup_flush(300);
- }
-
- if (!$newid) {
- $status = false;
- }
- }
-
- return $status;
- }
-?>
+++ /dev/null
-<?php
- function question_rqp_restore($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
-
- $status = true;
-
- //Get the truefalse array
- $rqps = $info['#']['RQP'];
-
- //Iterate over rqp
- for($i = 0; $i < sizeof($rqps); $i++) {
- $tru_info = $rqps[$i];
- //traverse_xmlize($tru_info); //Debug
- //print_object ($GLOBALS['traverse_array']); //Debug
- //$GLOBALS['traverse_array']=""; //Debug
-
- //Now, build the question_rqp record structure
- $rqp->question = $new_question_id;
- $rqp->type = backup_todb($tru_info['#']['TYPE']['0']['#']);
- $rqp->source = backup_todb($tru_info['#']['SOURCE']['0']['#']);
- $rqp->format = backup_todb($tru_info['#']['FORMAT']['0']['#']);
- $rqp->flags = backup_todb($tru_info['#']['FLAGS']['0']['#']);
- $rqp->maxscore = backup_todb($tru_info['#']['MAXSCORE']['0']['#']);
-
- //The structure is equal to the db, so insert the question_rqp
- $newid = insert_record ("question_rqp",$rqp);
-
- //Do some output
- if (($i+1) % 50 == 0) {
- if (!defined('RESTORE_SILENTLY')) {
- echo ".";
- if (($i+1) % 1000 == 0) {
- echo "<br />";
- }
- }
- backup_flush(300);
- }
-
- if (!$newid) {
- $status = false;
- }
- }
-
- return $status;
- }
-
-
- //This function restores the question_rqp_states
- function question_rqp_states_restore($state_id,$info,$restore) {
-
- global $CFG;
-
- $status = true;
-
- //Get the question_rqp_state
- $rqp_state = $info['#']['RQP_STATE']['0'];
- if ($rqp_state) {
-
- //Now, build the RQP_STATES record structure
- $state->stateid = $state_id;
- $state->responses = backup_todb($rqp_state['#']['RESPONSES']['0']['#']);
- $state->persistent_data = backup_todb($rqp_state['#']['PERSISTENT_DATA']['0']['#']);
- $state->template_vars = backup_todb($rqp_state['#']['TEMPLATE_VARS']['0']['#']);
-
- //The structure is equal to the db, so insert the question_states
- $newid = insert_record ("question_rqp_states",$state);
- }
-
- return $status;
- }
-
-?>
+++ /dev/null
-<?php
- function question_shortanswer_restore($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
-
- $status = true;
-
- //Get the shortanswers array
- $shortanswers = $info['#']['SHORTANSWER'];
-
- //Iterate over shortanswers
- for($i = 0; $i < sizeof($shortanswers); $i++) {
- $sho_info = $shortanswers[$i];
- //traverse_xmlize($sho_info); //Debug
- //print_object ($GLOBALS['traverse_array']); //Debug
- //$GLOBALS['traverse_array']=""; //Debug
-
- //Now, build the question_shortanswer record structure
- $shortanswer->question = $new_question_id;
- $shortanswer->answers = backup_todb($sho_info['#']['ANSWERS']['0']['#']);
- $shortanswer->usecase = backup_todb($sho_info['#']['USECASE']['0']['#']);
-
- //We have to recode the answers field (a list of answers id)
- //Extracts answer id from sequence
- $answers_field = "";
- $in_first = true;
- $tok = strtok($shortanswer->answers,",");
- while ($tok) {
- //Get the answer from backup_ids
- $answer = backup_getid($restore->backup_unique_code,"question_answers",$tok);
- if ($answer) {
- if ($in_first) {
- $answers_field .= $answer->new_id;
- $in_first = false;
- } else {
- $answers_field .= ",".$answer->new_id;
- }
- }
- //check for next
- $tok = strtok(",");
- }
- //We have the answers field recoded to its new ids
- $shortanswer->answers = $answers_field;
-
- //The structure is equal to the db, so insert the question_shortanswer
- $newid = insert_record ("question_shortanswer",$shortanswer);
-
- //Do some output
- if (($i+1) % 50 == 0) {
- if (!defined('RESTORE_SILENTLY')) {
- echo ".";
- if (($i+1) % 1000 == 0) {
- echo "<br />";
- }
- }
- backup_flush(300);
- }
-
- if (!$newid) {
- $status = false;
- }
- }
-
- return $status;
- }
-?>
+++ /dev/null
-<?php
- function question_truefalse_restore($old_question_id,$new_question_id,$info,$restore) {
-
- global $CFG;
-
- $status = true;
-
- //Get the truefalse array
- $truefalses = $info['#']['TRUEFALSE'];
-
- //Iterate over truefalse
- for($i = 0; $i < sizeof($truefalses); $i++) {
- $tru_info = $truefalses[$i];
- //traverse_xmlize($tru_info); //Debug
- //print_object ($GLOBALS['traverse_array']); //Debug
- //$GLOBALS['traverse_array']=""; //Debug
-
- //Now, build the question_truefalse record structure
- $truefalse->question = $new_question_id;
- $truefalse->trueanswer = backup_todb($tru_info['#']['TRUEANSWER']['0']['#']);
- $truefalse->falseanswer = backup_todb($tru_info['#']['FALSEANSWER']['0']['#']);
-
- ////We have to recode the trueanswer field
- $answer = backup_getid($restore->backup_unique_code,"question_answers",$truefalse->trueanswer);
- if ($answer) {
- $truefalse->trueanswer = $answer->new_id;
- }
-
- ////We have to recode the falseanswer field
- $answer = backup_getid($restore->backup_unique_code,"question_answers",$truefalse->falseanswer);
- if ($answer) {
- $truefalse->falseanswer = $answer->new_id;
- }
-
- //The structure is equal to the db, so insert the question_truefalse
- $newid = insert_record ("question_truefalse",$truefalse);
-
- //Do some output
- if (($i+1) % 50 == 0) {
- if (!defined('RESTORE_SILENTLY')) {
- echo ".";
- if (($i+1) % 1000 == 0) {
- echo "<br />";
- }
- }
- backup_flush(300);
- }
-
- if (!$newid) {
- $status = false;
- }
- }
-
- return $status;
- }
-
- function question_truefalse_recode_answer($state, $restore) {
- $answer = backup_getid($restore->backup_unique_code,"question_answers",$state->answer);
- if ($answer) {
- return $answer->new_id;
- }
- return '';
- }
-?>