From: stronk7 Date: Sat, 19 Jul 2003 18:01:11 +0000 (+0000) Subject: Now numerical questions are included in backup and restore too !! X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e2bad68d231ce1ae9d1f195016793d1d21304788;p=moodle.git Now numerical questions are included in backup and restore too !! --- diff --git a/mod/quiz/backuplib.php b/mod/quiz/backuplib.php index 2c70452c7e..d684399d8f 100644 --- a/mod/quiz/backuplib.php +++ b/mod/quiz/backuplib.php @@ -2,7 +2,7 @@ //This php script contains all the stuff to backup/restore //quiz mods - //To see, put your terminal to 132cc + //To see, put your terminal to 132cc //This is the "graphical" structure of the quiz mod: // @@ -23,21 +23,21 @@ // | // | // | - // ------------------------------------------------------------------------------------------------------ - // | | | | - // | | | | - // | | | | quiz_randomsamatch - // quiz_truefalse quiz_shortanswer quiz_multichoice |---------(CL,pl->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_answers | quiz_match_sub - // (CL,pk->id,fk->question)----------------------------|---------(CL,pl->id,fk->question) + // -------------------------------------------------------------------------------------- + // | | | | + // | | | | + // | | | | quiz_randomsamatch + // quiz_truefalse quiz_shortanswer quiz_multichoice quiz_numerical |--(CL,pl->id,fk->question) + // (CL,pl->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_answers | quiz_match_sub + // (CL,pk->id,fk->question)---------------------------------|--(CL,pl->id,fk->question) // // Meaning: pk->primary key field of the table // fk->foreign key to link with parent @@ -57,6 +57,7 @@ // - quiz_truefalse // - quiz_shortanswer // - quiz_multichoice + // - quiz_numerical // - quiz_randomsamatch // - quiz_match // - quiz_match_sub @@ -151,6 +152,8 @@ $status = quiz_backup_randomsamatch($bf,$preferences,$question->id); } else if ($question->qtype == "7") { //Description question. Nothing to write. + } else if ($question->qtype == "8") { + $status = quiz_backup_numerical($bf,$preferences,$question->id); } //End question $status =fwrite ($bf,end_tag("QUESTION",5,true)); @@ -294,8 +297,34 @@ return $status; } + //This function backups the data in a numerical question (qtype=8) and its + //asociated data + function quiz_backup_numerical($bf,$preferences,$question) { + + global $CFG; + + $status = true; + + $numericals = get_records("quiz_numerical","question",$question,"id"); + //If there are numericals + if ($numericals) { + //Iterate over each numerical + foreach ($numericals as $numerical) { + $status =fwrite ($bf,start_tag("NUMERICAL",6,true)); + //Print numerical contents + fwrite ($bf,full_tag("ANSWER",7,false,$numerical->answer)); + fwrite ($bf,full_tag("MIN",7,false,$numerical->min)); + fwrite ($bf,full_tag("MAX",7,false,$numerical->max)); + $status =fwrite ($bf,end_tag("NUMERICAL",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) + //(truefalse, shortanswer,multichoice,numerical) function quiz_backup_answers($bf,$preferences,$question) { global $CFG; diff --git a/mod/quiz/restorelib.php b/mod/quiz/restorelib.php index f1fd51baa8..e038cd2aeb 100644 --- a/mod/quiz/restorelib.php +++ b/mod/quiz/restorelib.php @@ -2,7 +2,7 @@ //This php script contains all the stuff to backup/restore //quiz mods - //To see, put your terminal to 132cc + //To see, put your terminal to 132cc //This is the "graphical" structure of the quiz mod: // @@ -18,27 +18,61 @@ // | | | // | | | // | | | - // quiz_responses | quiz_questions + // quiz_responses | quiz_questions // (UL,pk->id, fk->attempt)----------------------------------------------------(CL,pk->id,fk->category,files) // | // | // | - // ------------------------------------------------------------------------------------------------------ - // | | | | - // | | | | - // | | | | quiz_randomsamatch - // quiz_truefalse quiz_shortanswer quiz_multichoice |---------(CL,pl->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_answers | quiz_match_sub - // (CL,pk->id,fk->question)----------------------------|---------(CL,pl->id,fk->question) - // + // -------------------------------------------------------------------------------------- + // | | | | + // | | | | + // | | | | quiz_randomsamatch + // quiz_truefalse quiz_shortanswer quiz_multichoice quiz_numerical |--(CL,pl->id,fk->question) + // (CL,pl->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_answers | quiz_match_sub + // (CL,pk->id,fk->question)---------------------------------|--(CL,pl->id,fk->question) + // //This is the "graphical" structure of the quiz mod: + // + // quiz quiz_categories + // (CL,pk->id) (CL,pk->id) + // | | + // ----------------------------------------------- | + // | | | | + // | | | | + // | | | | + // quiz_attempts quiz_grades quiz_question_grades | + // (UL,pk->id, fk->quiz) (UL,pk->id,fk->quiz) (CL,pk->id,fk->quiz) | + // | | | + // | | | + // | | | + // quiz_responses | quiz_questions + // (UL,pk->id, fk->attempt)----------------------------------------------------(CL,pk->id,fk->category,files) + // | + // | + // | + // -------------------------------------------------------------------------------------- + // | | | | + // | | | | + // | | | | quiz_randomsamatch + // quiz_truefalse quiz_shortanswer quiz_multichoice quiz_numerical |--(CL,pl->id,fk->question) + // (CL,pl->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_answers | quiz_match_sub + // (CL,pk->id,fk->question)---------------------------------|--(CL,pl->id,fk->question) + // // Meaning: pk->primary key field of the table // fk->foreign key to link with parent // nt->nested field (recursive data) @@ -55,6 +89,7 @@ // - quiz_truefalse // - quiz_shortanswer // - quiz_multichoice + // - quiz_numerical // - quiz_randomsamatch // - quiz_match // - quiz_match_sub @@ -188,6 +223,8 @@ $status = quiz_restore_randomsamatch($oldid,$newid,$que_info,$restore); } else if ($question->qtype == "7") { //Description question. Nothing to do. + } else if ($question->qtype == "8") { + $status = quiz_restore_numerical($oldid,$newid,$que_info,$restore); } } else { $status = false; @@ -536,7 +573,53 @@ return $status; } + function quiz_restore_numerical ($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 QUIZ_NUMERICAL record structure + $numerical->question = $new_question_id; + $numerical->answer = backup_todb($num_info['#']['ANSWER']['0']['#']); + $numerical->min = backup_todb($num_info['#']['MIN']['0']['#']); + $numerical->max = backup_todb($num_info['#']['MAX']['0']['#']); + + ////We have to recode the answer field + $answer = backup_getid($restore->backup_unique_code,"quiz_answers",$numerical->answer); + if ($answer) { + $numerical->answer = $answer->new_id; + } + + //The structure is equal to the db, so insert the quiz_numerical + $newid = insert_record ("quiz_numerical",$numerical); + + //Do some output + if (($i+1) % 50 == 0) { + echo "."; + if (($i+1) % 1000 == 0) { + echo "
"; + } + backup_flush(300); + } + + if (!$newid) { + $status = false; + } + } + + return $status; + } //STEP 2. Restore quizzes and associated structures @@ -886,6 +969,9 @@ //Nothing to do (there is no awser to this qtype) //But this case must exist !! break; + case 8: //NUMERICAL QTYPE + //Nothing to do. The response is a text. + break; default: //UNMATCHED QTYPE. //This is an error (unimplemented qtype) $status = false;