Added backup/restore code for essay question type. In the process of testing, fixed several other bugs
in the quiz restore code regarding state restoration.
This commit is contained in:
@@ -297,6 +297,8 @@
|
||||
$status = quiz_backup_calculated($bf,$preferences,$question->id);
|
||||
} else if ($question->qtype == "11") {
|
||||
$status = quiz_backup_rqp($bf,$preferences,$question->id);
|
||||
} else if ($question->qtype == "12") {
|
||||
$status = quiz_backup_essay($bf,$preferences,$question->id);
|
||||
}
|
||||
//End question
|
||||
$status =fwrite ($bf,end_tag("QUESTION",5,true));
|
||||
@@ -563,6 +565,30 @@
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
//This function backups the data in an essay question (qtype=12) and its
|
||||
//asociated data
|
||||
function quiz_backup_essay($bf,$preferences,$question) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$status = true;
|
||||
|
||||
$essays = get_records('quiz_essay', 'question', $question, "id");
|
||||
//If there are essays
|
||||
if ($essays) {
|
||||
//Iterate over each essay
|
||||
foreach ($essays as $essay) {
|
||||
$status = fwrite ($bf,start_tag("ESSAY",6,true));
|
||||
//Print essay contents
|
||||
fwrite ($bf,full_tag("ANSWER",7,false,$essay->answer));
|
||||
$status = fwrite ($bf,end_tag("ESSAY",6,true));
|
||||
}
|
||||
//Now print quiz_answers
|
||||
$status = quiz_backup_answers($bf,$preferences,$question);
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
//This function backups the answers data in some question types
|
||||
//(truefalse, shortanswer,multichoice,numerical,calculated)
|
||||
@@ -901,6 +927,7 @@
|
||||
fwrite ($bf,full_tag("PENALTY",8,false,$state->penalty));
|
||||
// now back up question type specific state information
|
||||
$status = backup_quiz_rqp_state ($bf,$preferences,$state->id);
|
||||
$status = backup_quiz_essay_state ($bf,$preferences,$state->id);
|
||||
//End state
|
||||
$status =fwrite ($bf,end_tag("STATE",7,true));
|
||||
}
|
||||
@@ -953,9 +980,29 @@
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
//Backup quiz_essay_state contents (executed from backup_quiz_states)
|
||||
function backup_quiz_essay_state ($bf,$preferences,$state) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$status = true;
|
||||
|
||||
$essay_state = get_record("quiz_essay_states", "stateid", $state);
|
||||
//If there is a state
|
||||
if ($essay_state) {
|
||||
//Write start tag
|
||||
$status =fwrite ($bf,start_tag("ESSAY_STATE",8,true));
|
||||
//Print state contents
|
||||
fwrite ($bf,full_tag("GRADED",9,false,$essay_state->graded));
|
||||
fwrite ($bf,full_tag("FRACTION",9,false,$essay_state->fraction));
|
||||
fwrite ($bf,full_tag("RESPONSE",9,false,$essay_state->response));
|
||||
//Write end tag
|
||||
$status =fwrite ($bf,end_tag("ESSAY_STATE",8,true));
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
////Return an array of info (name,value)
|
||||
function quiz_check_backup_mods($course,$user_data=false,$backup_unique_code) {
|
||||
//Deletes data from mdl_backup_ids (categories section)
|
||||
|
||||
+78
-4
@@ -279,6 +279,8 @@
|
||||
$status = quiz_restore_calculated($oldid,$newid,$que_info,$restore);
|
||||
} else if ($question->qtype == "11") {
|
||||
$status = quiz_restore_rqp($oldid,$newid,$que_info,$restore);
|
||||
} else if ($question->qtype == "12") {
|
||||
$status = quiz_restore_essay($oldid,$newid,$que_info,$restore);
|
||||
}
|
||||
} else {
|
||||
//We are NOT creating the question, but we need to know every quiz_answers
|
||||
@@ -1068,7 +1070,52 @@
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
function quiz_restore_essay ($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 QUIZ_TRUEFALSE 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,"quiz_answers",$essay->answer);
|
||||
if ($answer) {
|
||||
$essay->answer = $answer->new_id;
|
||||
}
|
||||
|
||||
//The structure is equal to the db, so insert the quiz_truefalse
|
||||
$newid = insert_record ("quiz_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;
|
||||
}
|
||||
|
||||
function quiz_restore_numerical_units ($old_question_id,$new_question_id,$info,$restore) {
|
||||
|
||||
@@ -1440,6 +1487,8 @@
|
||||
return true;
|
||||
|
||||
global $CFG;
|
||||
|
||||
include($CFG->dirroot.'/mod/quiz/questionlib.php');
|
||||
|
||||
$status = true;
|
||||
|
||||
@@ -1736,6 +1785,7 @@
|
||||
$newid);
|
||||
//Now process question type specific state information
|
||||
$status = quiz_rqp_states_restore_mods($newid,$res_info,$restore);
|
||||
$status = quiz_essay_states_restore_mods($newid,$res_info,$restore);
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
@@ -1758,20 +1808,20 @@
|
||||
$newest_state->sumpenalty = backup_todb($res_info['#']['SUMPENALTY']['0']['#']);
|
||||
|
||||
//We have to recode the question field
|
||||
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$newest_state->question);
|
||||
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$newest_state->questionid);
|
||||
if ($question) {
|
||||
$newest_state->question = $question->new_id;
|
||||
$newest_state->questionid = $question->new_id;
|
||||
}
|
||||
|
||||
//We have to recode the newest field
|
||||
$state = backup_getid($restore->backup_unique_code,"quiz_states",$newest_state->newest);
|
||||
if ($staten) {
|
||||
if ($state) {
|
||||
$newest_state->newest = $state->new_id;
|
||||
}
|
||||
|
||||
//We have to recode the newgraded field
|
||||
$state = backup_getid($restore->backup_unique_code,"quiz_states",$newest_state->newgraded);
|
||||
if ($staten) {
|
||||
if ($state) {
|
||||
$newest_state->newgraded = $state->new_id;
|
||||
}
|
||||
|
||||
@@ -1806,6 +1856,30 @@
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
//This function restores the quiz_essay_states
|
||||
function quiz_essay_states_restore_mods($state_id,$info,$restore) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$status = true;
|
||||
|
||||
//Get the quiz_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 quiz_states
|
||||
$newid = insert_record ("quiz_essay_states",$state);
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
//This function restores the quiz_grades
|
||||
function quiz_grades_restore_mods($quiz_id,$info,$restore) {
|
||||
|
||||
Reference in New Issue
Block a user