From: stronk7 Date: Thu, 5 Aug 2004 23:11:31 +0000 (+0000) Subject: Now numerical_units support has been added to backup and restore. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=04bc8ed1c1cd6ff0d029d4213e532d94605dcc4c;p=moodle.git Now numerical_units support has been added to backup and restore. Currently only working with numerical questions... --- diff --git a/mod/quiz/backuplib.php b/mod/quiz/backuplib.php index 3f3e97af5e..92afbea150 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 160cc //This is the "graphical" structure of the quiz mod: // @@ -23,27 +23,27 @@ // | // | // | - // -------------------------------------------------------------------------------------- - // | | | | | | - // | | | | | | - // | | | | | | quiz_randomsamatch - // quiz_truefalse | quiz_multichoice | quiz_multianswer |--(CL,pl->id,fk->question) - // (CL,pl->id,fk->question) | (CL,pl->id,fk->question) | (CL,pl->id,fk->question) | - // . | . | . | - // . quiz_shortanswer . quiz_numerical . | - // . (CL,pl->id,fk->question) . (CL,pl->id,fk->question) . | quiz_match - // . . . . . |--(CL,pl->id,fk->question) - // . . . . . | . - // . . . . . | . - // . . . . . | . - // . . . . . | quiz_match_sub - // . . . . . |--(CL,pl->id,fk->question) - // ............................................................. | - // . | - // . | - // . | - // quiz_answers | - // (CL,pk->id,fk->question)---------------------------------- + // -------------------------------------------------------------------------------------------------------------- + // | | | | | | | + // | | | | | | | + // | | | | 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,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,pl->id,fk->question) + // ........................................................................................ | + // . | + // . | + // . | quiz_numerical_units + // 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 @@ -69,6 +69,7 @@ // - quiz_match // - quiz_match_sub // - quiz_answers + // - quiz_numerical_units // All this backup info have its own section in moodle.xml (QUESTION_CATEGORIES) and it's generated // before every module backup standard invocation. And only if to backup quizzes has been selected !! // It's invoked with quiz_backup_question_categories. (course independent). @@ -332,6 +333,8 @@ fwrite ($bf,full_tag("ANSWER",$level+1,false,$numerical->answer)); fwrite ($bf,full_tag("MIN",$level+1,false,$numerical->min)); fwrite ($bf,full_tag("MAX",$level+1,false,$numerical->max)); + //Now backup numerical_units + $status = quiz_backup_numerical_units($bf,$preferences,$question,7); $status =fwrite ($bf,end_tag("NUMERICAL",$level,true)); } //Now print quiz_answers @@ -412,8 +415,32 @@ return $status; } + //This function backups quiz_numerical_units from different question types + function quiz_backup_numerical_units($bf,$preferences,$question,$level=7) { + global $CFG; + + $status = true; + $numerical_units = get_records("quiz_numerical_units","question",$question,"id"); + //If there are numericals_units + if ($numerical_units) { + $status =fwrite ($bf,start_tag("NUMERICAL_UNITS",$level,true)); + //Iterate over each numerical_unit + foreach ($numerical_units as $numerical_unit) { + $status =fwrite ($bf,start_tag("NUMERICAL_UNIT",$level+1,true)); + //Print numerical_unit contents + fwrite ($bf,full_tag("MULTIPLIER",$level+2,false,$numerical_unit->multiplier)); + fwrite ($bf,full_tag("UNIT",$level+2,false,$numerical_unit->unit)); + //Now backup numerical_units + $status =fwrite ($bf,end_tag("NUMERICAL_UNIT",$level+1,true)); + } + $status =fwrite ($bf,end_tag("NUMERICAL_UNITS",$level,true)); + } + + return $status; + + } //STEP 2. Backup quizzes and associated structures diff --git a/mod/quiz/restorelib.php b/mod/quiz/restorelib.php index 5483549c12..8128b70e25 100644 --- a/mod/quiz/restorelib.php +++ b/mod/quiz/restorelib.php @@ -5,12 +5,12 @@ //To see, put your terminal to 132cc //This is the "graphical" structure of the quiz mod: - // + // // quiz quiz_categories - // (CL,pk->id) (CL,pk->id) - // | | - // ----------------------------------------------- | - // | | | | + // (CL,pk->id) (CL,pk->id) + // | | + // ----------------------------------------------- | + // | | | | // | | | | // | | | | // quiz_attempts quiz_grades quiz_question_grades | @@ -23,27 +23,27 @@ // | // | // | - // -------------------------------------------------------------------------------------- - // | | | | | | - // | | | | | | - // | | | | | | quiz_randomsamatch - // quiz_truefalse | quiz_multichoice | quiz_multianswer |--(CL,pl->id,fk->question) - // (CL,pl->id,fk->question) | (CL,pl->id,fk->question) | (CL,pl->id,fk->question) | - // . | . | . | - // . quiz_shortanswer . quiz_numerical . | - // . (CL,pl->id,fk->question) . (CL,pl->id,fk->question) . | quiz_match - // . . . . . |--(CL,pl->id,fk->question) - // . . . . . | . - // . . . . . | . - // . . . . . | . - // . . . . . | quiz_match_sub - // . . . . . |--(CL,pl->id,fk->question) - // ............................................................. | - // . | - // . | - // . | - // quiz_answers | - // (CL,pk->id,fk->question)---------------------------------- + // -------------------------------------------------------------------------------------------------------------- + // | | | | | | | + // | | | | | | | + // | | | | 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,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,pl->id,fk->question) + // ........................................................................................ | + // . | + // . | + // . | quiz_numerical_units + // 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 @@ -67,6 +67,7 @@ // - quiz_match // - quiz_match_sub // - quiz_answers + // - quiz_numerical_units // All this backup info have its own section in moodle.xml (QUESTION_CATEGORIES) and it's generated // before every module backup standard invocation. And only if to restore quizzes has been selected !! // It's invoked with quiz_restore_question_categories. (course independent). @@ -960,6 +961,9 @@ backup_flush(300); } + //Now restore numerical_units + $status = quiz_restore_numerical_units ($old_question_id,$new_question_id,$num_info,$restore); + if (!$newid) { $status = false; } @@ -1051,6 +1055,38 @@ return $status; } + function quiz_restore_numerical_units ($old_question_id,$new_question_id,$info,$restore) { + + global $CFG; + + $status = true; + + //Get the numerical array + $numerical_units = $info['#']['NUMERICAL_UNITS']['0']['#']['NUMERICAL_UNIT']; + + //Iterate over numerical_units + for($i = 0; $i < sizeof($numerical_units); $i++) { + $nu_info = $numerical_units[$i]; + traverse_xmlize($nu_info); //Debug + print_object ($GLOBALS['traverse_array']); //Debug + $GLOBALS['traverse_array']=""; //Debug + + //Now, build the QUIZ_NUMERICAL_UNITS record structure + $numerical_unit->question = $new_question_id; + $numerical_unit->multiplier = backup_todb($nu_info['#']['MULTIPLIER']['0']['#']); + $numerical_unit->unit = backup_todb($nu_info['#']['UNIT']['0']['#']); + + //The structure is equal to the db, so insert the quiz_numerical_units + $newid = insert_record ("quiz_numerical_units",$numerical_unit); + + if (!$newid) { + $status = false; + } + } + + return $status; + } + //STEP 2. Restore quizzes and associated structures // (course dependent)