reverted back to restorelib from before the merge. Removes the duplicate function definitions reported on the forums. Also I think this is the best version to start with.

This commit is contained in:
gustav_delius 2005-05-09 05:34:20 +00:00
parent 202a6406ad
commit 90c7675076

View File

@ -11,52 +11,49 @@
// | |
// ------------------------------------------------------------------- |
// | | | | |.......................................
// | quiz_grades | quiz_question_versions | .
// | (UL,pk->id,fk->quiz) | (CL,pk->id,fk->quiz) | .
// | | . | ----quiz_question_datasets---- .
// quiz_attempts quiz_question_instances . | | (CL,pk->id,fk->question, | .
// (UL,pk->id,fk->quiz) (CL,pk->id,fk->quiz,question) . | | fk->dataset_definition) | .
// | | | | | .
// | | | | | .
// quiz_attempts quiz_grades quiz_question_grades quiz_question_versions | ----quiz_question_datasets---- .
// (UL,pk->id, fk->quiz) (UL,pk->id,fk->quiz) (CL,pk->id,fk->quiz) (CL,pk->id,fk->quiz) | | (CL,pk->id,fk->question, | .
// | | . | | fk->dataset_definition) | .
// | | . | | | .
// | quiz_newest_states | . | | | .
// |---------(UL,pk->id,fk->attempt,question)-----| . | | | .
// | . | . | | quiz_dataset_definitions
// | . | . | | (CL,pk->id,fk->category)
// | quiz_states | quiz_questions |
// ----------(UL,pk->id,fk->attempt,question)--------------------------(CL,pk->id,fk->category,files) |
// | | quiz_dataset_items
// | | (CL,pk->id,fk->definition)
// --------- |
// | |
// quiz_rqp_states |
// (UL,pk->id,fk->stateid) | quiz_rqp_type
// | (SL,pk->id)
// | |
// -------------------------------------------------------------------------------------------------------------- |
// | | | | | | | quiz_rqp
// | | | | | | |--(CL,pk->id,fk->question)
// | | | | quiz_calculated | |
// quiz_truefalse | quiz_multichoice | (CL,pl->id,fk->question) | |
// (CL,pk->id,fk->question) | (CL,pk->id,fk->question) | . | | quiz_randomsamatch
// . | . | . | |--(CL,pk->id,fk->question)
// | | . | | | .
// | | . | | | .
// quiz_responses | quiz_questions quiz_dataset_definitions
// (UL,pk->id, fk->attempt)----------------------------------------------------(CL,pk->id,fk->category,files) (CL,pk->id,fk->category)
// | |
// | |
// | |
// | quiz_dataset_items
// | (CL,pk->id,fk->definition)
// |
// |
// |
// --------------------------------------------------------------------------------------------------------------
// | | | | | | |
// | | | | | | |
// | | | | quiz_calculated | | quiz_randomsamatch
// quiz_truefalse | quiz_multichoice | (CL,pl->id,fk->question) | |--(CL,pl->id,fk->question)
// (CL,pl->id,fk->question) | (CL,pl->id,fk->question) | . | |
// . | . | . | |
// . quiz_shortanswer . quiz_numerical . quiz_multianswer. |
// . (CL,pk->id,fk->question) . (CL,pk->id,fk->question) . (CL,pk->id,fk->question) |
// . . . . . . | quiz_match
// . . . . . . |--(CL,pk->id,fk->question)
// . (CL,pl->id,fk->question) . (CL,pl->id,fk->question) . (CL,pl->id,fk->question) | quiz_match
// . . . . . . |--(CL,pl->id,fk->question)
// . . . . . . | .
// . . . . . . | .
// . . . . . . | .
// . . . . . . | quiz_match_sub
// ........................................................................................ |--(CL,pk->id,fk->question)
// . . . . . . |--(CL,pl->id,fk->question)
// ........................................................................................ |
// . |
// . |
// . | quiz_numerical_units
// quiz_answers |--(CL,pk->id,fk->question)
// quiz_answers |--(CL,pl->id,fk->question)
// (CL,pk->id,fk->question)----------------------------------------------------------
//
// Meaning: pk->primary key field of the table
// fk->foreign key to link with parent
// nt->nested field (recursive data)
// SL->site level info
// CL->course level info
// UL->user level info
// files->table may have files
@ -91,7 +88,7 @@
// - quiz_question_grades
// - quiz_attempts
// - quiz_grades
// - quiz_states
// - quiz_responses
// This step is the standard mod backup. (course dependent).
//STEP 1. Restore categories/questions and associated structures
@ -330,7 +327,7 @@
$question->hidden = backup_todb($que_info['#']['HIDDEN']['0']['#']);
// If it is a random question then hide it
if ($question->qtype = RANDOM) {
if ($question->qtype == 4) {
$question->hidden = 1;
}
@ -1397,39 +1394,39 @@
return $status;
}
//This function restores the quiz_question_instances
function quiz_question_instances_restore_mods($quiz_id,$info,$restore) {
//This function restores the quiz_question_grades
function quiz_question_grades_restore_mods($quiz_id,$info,$restore) {
global $CFG;
$status = true;
//Get the quiz_question_instances array
$instances = $info['MOD']['#']['QUESTION_INSTANCES']['0']['#']['QUESTION_INSTANCE'];
//Get the quiz_question_grades array
$grades = $info['MOD']['#']['QUESTION_GRADES']['0']['#']['QUESTION_GRADE'];
//Iterate over question_instances
for($i = 0; $i < sizeof($instances); $i++) {
$ins_info = $instances[$i];
//traverse_xmlize($ins_info); //Debug
//Iterate over question_grades
for($i = 0; $i < sizeof($grades); $i++) {
$gra_info = $grades[$i];
//traverse_xmlize($gra_info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//We'll need this later!!
$oldid = backup_todb($ins_info['#']['ID']['0']['#']);
$oldid = backup_todb($gra_info['#']['ID']['0']['#']);
//Now, build the QUESTION_INSTANCES record structure
$instance->quiz = $quiz_id;
$instance->question = backup_todb($ins_info['#']['QUESTION']['0']['#']);
$instance->grade = backup_todb($ins_info['#']['GRADE']['0']['#']);
//Now, build the QUESTION_GRADES record structure
$grade->quiz = $quiz_id;
$grade->question = backup_todb($gra_info['#']['QUESTION']['0']['#']);
$grade->grade = backup_todb($gra_info['#']['GRADE']['0']['#']);
//We have to recode the question field
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$instance->question);
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$grade->question);
if ($question) {
$instance->question = $question->new_id;
$grade->question = $question->new_id;
}
//The structure is equal to the db, so insert the quiz_question_instances
$newid = insert_record ("quiz_question_instances",$instance);
//The structure is equal to the db, so insert the quiz_question_grades
$newid = insert_record ("quiz_question_grades",$grade);
//Do some output
if (($i+1) % 10 == 0) {
@ -1442,78 +1439,7 @@
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"quiz_question_instances",$oldid,
$newid);
} else {
$status = false;
}
}
return $status;
}
//This function restores the quiz_question_versions
function quiz_question_versions_restore_mods($quiz_id,$info,$restore) {
global $CFG, $USER;
$status = true;
//Get the quiz_question_versions array
$versions = $info['MOD']['#']['QUESTION_VERSIONS']['0']['#']['QUESTION_VERSION'];
//Iterate over question_versions
for($i = 0; $i < sizeof($versions); $i++) {
$ver_info = $versions[$i];
//traverse_xmlize($ver_info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//We'll need this later!!
$oldid = backup_todb($ver_info['#']['ID']['0']['#']);
//Now, build the QUESTION_VERSIONS record structure
$version->quiz = $quiz_id;
$version->oldquestion = backup_todb($ver_info['#']['OLDQUESTION']['0']['#']);
$version->newquestion = backup_todb($ver_info['#']['NEWQUESTION']['0']['#']);
$version->userid = backup_todb($ver_info['#']['USERID']['0']['#']);
$version->timestamp = backup_todb($ver_info['#']['TIMESTAMP']['0']['#']);
//We have to recode the oldquestion field
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$version->oldquestion);
if ($question) {
$version->oldquestion = $question->new_id;
}
//We have to recode the newquestion field
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$version->newquestion);
if ($question) {
$version->newquestion = $question->new_id;
}
//We have to recode the userid field
$user = backup_getid($restore->backup_unique_code,"user",$version->userid);
if ($user) {
$version->userid = $user->new_id;
} else { //Assign to current user
$version->userid = $USER->id;
}
//The structure is equal to the db, so insert the quiz_question_versions
$newid = insert_record ("quiz_question_versions",$version);
//Do some output
if (($i+1) % 10 == 0) {
echo ".";
if (($i+1) % 200 == 0) {
echo "<br />";
}
backup_flush(300);
}
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"quiz_question_versions",$oldid,
backup_putid($restore->backup_unique_code,"quiz_question_grades",$oldid,
$newid);
} else {
$status = false;
@ -1646,8 +1572,8 @@
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"quiz_attempts",$oldid,
$newid);
//Now process quiz_states
$status = quiz_states_restore_mods($newid,$att_info,$restore);
//Now process quiz_responses
$status = quiz_responses_restore_mods($newid,$att_info,$restore);
} else {
$status = false;
}
@ -1656,18 +1582,18 @@
return $status;
}
//This function restores the quiz_states
function quiz_states_restore_mods($attempt_id,$info,$restore) {
//This function restores the quiz_responses
function quiz_responses_restore_mods($attempt_id,$info,$restore) {
global $CFG;
$status = true;
//Get the quiz_states array
$states = $info['#']['STATES']['0']['#']['STATE'];
//Iterate over states
for($i = 0; $i < sizeof($states); $i++) {
$res_info = $states[$i];
//Get the quiz_responses array
$responses = $info['#']['RESPONSES']['0']['#']['RESPONSE'];
//Iterate over responses
for($i = 0; $i < sizeof($responses); $i++) {
$res_info = $responses[$i];
//traverse_xmlize($res_info); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
@ -1683,15 +1609,9 @@
$response->grade = backup_todb($res_info['#']['GRADE']['0']['#']);
//We have to recode the question field
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$state->question);
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$response->question);
if ($question) {
$state->question = $question->new_id;
}
//We have to recode the originalquestion field
$question = backup_getid($restore->backup_unique_code,"quiz_questions",$response->originalquestion);
if ($question) {
$response->originalquestion = $question->new_id;
$response->question = $question->new_id;
}
//We have to recode the originalquestion field
@ -1703,7 +1623,7 @@
//We have to recode the answer field
//It depends of the question type !!
//We get the question first
$question = get_record("quiz_questions","id",$state->question);
$question = get_record("quiz_questions","id",$response->question);
//It exists
if ($question) {
//Depending of the qtype, we make different recodes
@ -1713,16 +1633,16 @@
break;
case 2: //TRUEFALSE QTYPE
//The answer is one answer id. We must recode it
$answer = backup_getid($restore->backup_unique_code,"quiz_answers",$state->answer);
$answer = backup_getid($restore->backup_unique_code,"quiz_answers",$response->answer);
if ($answer) {
$state->answer = $answer->new_id;
$response->answer = $answer->new_id;
}
break;
case 3: //MULTICHOICE QTYPE
//The answer is a comma separated list of answers. We must recode them
$answer_field = "";
$in_first = true;
$tok = strtok($state->answer,",");
$tok = strtok($response->answer,",");
while ($tok) {
//Get the answer from backup_ids
$answer = backup_getid($restore->backup_unique_code,"quiz_answers",$tok);
@ -1737,20 +1657,20 @@
//check for next
$tok = strtok(",");
}
$state->answer = $answer_field;
$response->answer = $answer_field;
break;
case 4: //RANDOM QTYPE
//The answer links to another question id, we must recode it
$answer_link = backup_getid($restore->backup_unique_code,"quiz_questions",$state->answer);
$answer_link = backup_getid($restore->backup_unique_code,"quiz_questions",$response->answer);
if ($answer_link) {
$state->answer = $answer_link->new_id;
$response->answer = $answer_link->new_id;
}
break;
case 5: //MATCH QTYPE
//The answer is a comma separated list of hypen separated math_subs (for question and answer)
$answer_field = "";
$in_first = true;
$tok = strtok($state->answer,",");
$tok = strtok($response->answer,",");
while ($tok) {
//Extract the match_sub for the question and the answer
$exploded = explode("-",$tok);
@ -1775,13 +1695,13 @@
//check for next
$tok = strtok(",");
}
$state->answer = $answer_field;
$response->answer = $answer_field;
break;
case 6: //RANDOMSAMATCH QTYPE
//The answer is a comma separated list of hypen separated question_id and answer_id. We must recode them
$answer_field = "";
$in_first = true;
$tok = strtok($state->answer,",");
$tok = strtok($response->answer,",");
while ($tok) {
//Extract the question_id and the answer_id
$exploded = explode("-",$tok);
@ -1806,7 +1726,7 @@
//check for next
$tok = strtok(",");
}
$state->answer = $answer_field;
$response->answer = $answer_field;
break;
case 7: //DESCRIPTION QTYPE
//Nothing to do (there is no awser to this qtype)
@ -1819,7 +1739,7 @@
//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,",");
$tok = strtok($response->answer,",");
while ($tok) {
//Extract the multianswer_id and the answer
$exploded = explode("-",$tok);
@ -1855,7 +1775,7 @@
//check for next
$tok = strtok(",");
}
$state->answer = $answer_field;
$response->answer = $answer_field;
break;
case 10: //CALCULATED QTYPE
//Nothing to do. The response is a text.
@ -1870,7 +1790,7 @@
}
//The structure is equal to the db, so insert the quiz_attempts
$newid = insert_record ("quiz_states",$state);
$newid = insert_record ("quiz_responses",$response);
//Do some output
if (($i+1) % 10 == 0) {
@ -1883,7 +1803,7 @@
if ($newid) {
//We have the newid, update backup_ids
backup_putid($restore->backup_unique_code,"quiz_states",$oldid,
backup_putid($restore->backup_unique_code,"quiz_responses",$oldid,
$newid);
} else {
$status = false;