diff --git a/mod/quiz/backuplib.php b/mod/quiz/backuplib.php index 25fb9cd2a5e..157c49c0d4b 100644 --- a/mod/quiz/backuplib.php +++ b/mod/quiz/backuplib.php @@ -394,6 +394,7 @@ fwrite ($bf,full_tag("LAYOUT",$level+1,false,$multichoice->layout)); fwrite ($bf,full_tag("ANSWERS",$level+1,false,$multichoice->answers)); fwrite ($bf,full_tag("SINGLE",$level+1,false,$multichoice->single)); + fwrite ($bf,full_tag("SHUFFLEANSWERS",$level+1,false,$randomsamatch->shuffleanswers)); $status =fwrite ($bf,end_tag("MULTICHOICE",$level,true)); } //Now print quiz_answers @@ -420,6 +421,7 @@ $status =fwrite ($bf,start_tag("RANDOMSAMATCH",6,true)); //Print randomsamatch contents fwrite ($bf,full_tag("CHOOSE",7,false,$randomsamatch->choose)); + fwrite ($bf,full_tag("SHUFFLEANSWERS",7,false,$randomsamatch->shuffleanswers)); $status =fwrite ($bf,end_tag("RANDOMSAMATCH",6,true)); } } @@ -445,6 +447,7 @@ fwrite ($bf,full_tag("ID",8,false,$match->id)); fwrite ($bf,full_tag("QUESTIONTEXT",8,false,$match->questiontext)); fwrite ($bf,full_tag("ANSWERTEXT",8,false,$match->answertext)); + fwrite ($bf,full_tag("SHUFFLEANSWERS",8,false,$randomsamatch->shuffleanswers)); $status =fwrite ($bf,end_tag("MATCH",7,true)); } $status =fwrite ($bf,end_tag("MATCHS",6,true)); diff --git a/mod/quiz/db/mysql.php b/mod/quiz/db/mysql.php index 30b92530a36..5fcdf263708 100644 --- a/mod/quiz/db/mysql.php +++ b/mod/quiz/db/mysql.php @@ -883,6 +883,13 @@ function quiz_upgrade($oldversion) { execute_sql("UPDATE {$CFG->prefix}quiz_questions SET defaultgrade = '0' WHERE qtype = '".DESCRIPTION."'", false); } + if ($oldversion < 2006021103) { + // add new field to store the question-level shuffleanswers option + table_column('quiz_match', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'subquestions'); + table_column('quiz_multichoice', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'single'); + table_column('quiz_randomsamatch', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'choose'); + } + return true; } diff --git a/mod/quiz/db/mysql.sql b/mod/quiz/db/mysql.sql index 3d723dbbcb7..2dbd35bab64 100644 --- a/mod/quiz/db/mysql.sql +++ b/mod/quiz/db/mysql.sql @@ -228,6 +228,7 @@ CREATE TABLE prefix_quiz_match ( id int(10) unsigned NOT NULL auto_increment, question int(10) unsigned NOT NULL default '0', subquestions varchar(255) NOT NULL default '', + shuffleanswers tinyint(4) NOT NULL default '1', PRIMARY KEY (id), KEY question (question) ) TYPE=MyISAM COMMENT='Defines fixed matching questions'; @@ -273,6 +274,7 @@ CREATE TABLE prefix_quiz_multichoice ( layout tinyint(4) NOT NULL default '0', answers varchar(255) NOT NULL default '', single tinyint(4) NOT NULL default '0', + shuffleanswers tinyint(4) NOT NULL default '1', PRIMARY KEY (id), KEY question (question) ) TYPE=MyISAM COMMENT='Options for multiple choice questions'; @@ -406,6 +408,7 @@ CREATE TABLE prefix_quiz_randomsamatch ( id int(10) unsigned NOT NULL auto_increment, question int(10) unsigned NOT NULL default '0', choose int(10) unsigned NOT NULL default '4', + shuffleanswers tinyint(4) NOT NULL default '1', PRIMARY KEY (id), KEY question (question) ) TYPE=MyISAM COMMENT='Info about a random short-answer matching question'; diff --git a/mod/quiz/db/postgres7.php b/mod/quiz/db/postgres7.php index 026a677dc27..4463bc6be50 100644 --- a/mod/quiz/db/postgres7.php +++ b/mod/quiz/db/postgres7.php @@ -979,6 +979,13 @@ function quiz_upgrade($oldversion) { execute_sql("UPDATE {$CFG->prefix}quiz_questions SET defaultgrade = '0' WHERE qtype = '".DESCRIPTION."'", false); } + if ($oldversion < 2006021103) { + // add new field to store the question-level shuffleanswers option + table_column('quiz_match', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'subquestions'); + table_column('quiz_multichoice', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'single'); + table_column('quiz_randomsamatch', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'choose'); + } + return true; } diff --git a/mod/quiz/db/postgres7.sql b/mod/quiz/db/postgres7.sql index 8ca9caddfbb..9dd8b60707b 100644 --- a/mod/quiz/db/postgres7.sql +++ b/mod/quiz/db/postgres7.sql @@ -194,7 +194,8 @@ CREATE INDEX prefix_quiz_grades_userid_idx ON prefix_quiz_grades (userid); CREATE TABLE prefix_quiz_match ( id SERIAL PRIMARY KEY, question integer NOT NULL default '0', - subquestions varchar(255) NOT NULL default '' + subquestions varchar(255) NOT NULL default '', + shuffleanswers integer NOT NULL default '1' ); CREATE INDEX prefix_quiz_match_question_idx ON prefix_quiz_match (question); @@ -238,7 +239,8 @@ CREATE TABLE prefix_quiz_multichoice ( question integer NOT NULL default '0', layout integer NOT NULL default '0', answers varchar(255) NOT NULL default '', - single integer NOT NULL default '0' + single integer NOT NULL default '0', + shuffleanswers integer NOT NULL default '1' ); CREATE INDEX prefix_quiz_multichoice_question_idx ON prefix_quiz_multichoice (question); @@ -370,7 +372,8 @@ CREATE INDEX prefix_quiz_questions_category_idx ON prefix_quiz_questions (catego CREATE TABLE prefix_quiz_randomsamatch ( id SERIAL PRIMARY KEY, question integer NOT NULL default '0', - choose integer NOT NULL default '4' + choose integer NOT NULL default '4', + shuffleanswers integer NOT NULL default '1' ); CREATE INDEX prefix_quiz_randomsamatch_question_idx ON prefix_quiz_randomsamatch (question); diff --git a/mod/quiz/questiontypes/match/editquestion.php b/mod/quiz/questiontypes/match/editquestion.php index bd9884b7cd8..38769615c2e 100644 --- a/mod/quiz/questiontypes/match/editquestion.php +++ b/mod/quiz/questiontypes/match/editquestion.php @@ -5,6 +5,8 @@ if (!empty($options->subquestions)) { $oldsubquestions = get_records_list("quiz_match_sub", "id", $options->subquestions); } + } else { + $options->shuffleanswers = 0; } $subquestions = array(); @@ -25,6 +27,10 @@ $subanswers[] = ""; // Make answer slots, default as blank } + $yesnooptions = array(); + $yesnooptions[0] = get_string("no"); + $yesnooptions[1] = get_string("yes"); + print_heading_with_help(get_string("editingmatch", "quiz"), "match", "quiz"); require("$CFG->dirroot/mod/quiz/questiontypes/match/match.html"); diff --git a/mod/quiz/questiontypes/match/match.html b/mod/quiz/questiontypes/match/match.html index 749b03619b4..bbe525a61f4 100644 --- a/mod/quiz/questiontypes/match/match.html +++ b/mod/quiz/questiontypes/match/match.html @@ -83,6 +83,15 @@ + + : + + shuffleanswers", ""); + helpbutton("shuffleanswers", get_string("shuffleanswers","quiz"), "quiz"); + ?> + + diff --git a/mod/quiz/questiontypes/match/questiontype.php b/mod/quiz/questiontypes/match/questiontype.php index 9ba58ade2da..f67cf2c884a 100644 --- a/mod/quiz/questiontypes/match/questiontype.php +++ b/mod/quiz/questiontypes/match/questiontype.php @@ -12,8 +12,8 @@ class quiz_match_qtype extends quiz_default_questiontype { } function get_question_options(&$question) { - $subquestions = get_records("quiz_match_sub", "question", $question->id, "id ASC" ); - $question->options->subquestions = $subquestions; + $question->options = get_record('quiz_match', 'question', $question->id); + $question->options->subquestions = get_records("quiz_match_sub", "question", $question->id, "id ASC" ); return true; } @@ -78,6 +78,7 @@ class quiz_match_qtype extends quiz_default_questiontype { if ($options = get_record("quiz_match", "question", $question->id)) { $options->subquestions = implode(",",$subquestions); + $options->shuffleanswers = $question->shuffleanswers; if (!update_record("quiz_match", $options)) { $result->error = "Could not update quiz match options! (id=$options->id)"; return $result; @@ -86,6 +87,7 @@ class quiz_match_qtype extends quiz_default_questiontype { unset($options); $options->question = $question->id; $options->subquestions = implode(",",$subquestions); + $options->shuffleanswers = $question->shuffleanswers; if (!insert_record("quiz_match", $options)) { $result->error = "Could not insert quiz match options!"; return $result; @@ -129,7 +131,7 @@ class quiz_match_qtype extends quiz_default_questiontype { } // Shuffle the answers if required - if ($cmoptions->shuffleanswers) { + if ($cmoptions->shuffleanswers and $question->options->shuffleanswers) { $state->options->subquestions = swapshuffle_assoc($state->options->subquestions); } diff --git a/mod/quiz/questiontypes/multichoice/editquestion.php b/mod/quiz/questiontypes/multichoice/editquestion.php index f13984f2d13..11884d13f1c 100644 --- a/mod/quiz/questiontypes/multichoice/editquestion.php +++ b/mod/quiz/questiontypes/multichoice/editquestion.php @@ -4,6 +4,7 @@ $options = get_record("quiz_multichoice", "question", $question->id); } else { $options->single = 1; + $options->shuffleanswers = 0; } if (!empty($options->answers)) { $answersraw = get_records_list("quiz_answers", "id", $options->answers); @@ -23,6 +24,11 @@ for (; $i < $limit; $i++) { $answers[] = ""; // Make answer slots, default as blank } + + $yesnooptions = array(); + $yesnooptions[0] = get_string("no"); + $yesnooptions[1] = get_string("yes"); + print_heading_with_help(get_string("editingmultichoice", "quiz"), "multichoice", "quiz"); require("$CFG->dirroot/mod/quiz/questiontypes/multichoice/multichoice.html"); diff --git a/mod/quiz/questiontypes/multichoice/multichoice.html b/mod/quiz/questiontypes/multichoice/multichoice.html index dd692b9c3f6..7c7dae862a8 100644 --- a/mod/quiz/questiontypes/multichoice/multichoice.html +++ b/mod/quiz/questiontypes/multichoice/multichoice.html @@ -1,8 +1,3 @@ -single)) { - $options->single = 1; - } -?>
@@ -97,7 +92,15 @@ ?> - + + + + diff --git a/mod/quiz/questiontypes/multichoice/questiontype.php b/mod/quiz/questiontypes/multichoice/questiontype.php index 081b6496534..a3bab41bbea 100644 --- a/mod/quiz/questiontypes/multichoice/questiontype.php +++ b/mod/quiz/questiontypes/multichoice/questiontype.php @@ -54,8 +54,6 @@ class quiz_multichoice_qtype extends quiz_default_questiontype { return $result; } - - // Insert all the new answers $totalfraction = 0; @@ -98,6 +96,7 @@ class quiz_multichoice_qtype extends quiz_default_questiontype { if ($options = get_record("quiz_multichoice", "question", $question->id)) { $options->answers = implode(",",$answers); $options->single = $question->single; + $options->shuffleanswers = $question->shuffleanswers; if (!update_record("quiz_multichoice", $options)) { $result->error = "Could not update quiz multichoice options! (id=$options->id)"; return $result; @@ -107,6 +106,7 @@ class quiz_multichoice_qtype extends quiz_default_questiontype { $options->question = $question->id; $options->answers = implode(",",$answers); $options->single = $question->single; + $options->shuffleanswers = $question->shuffleanswers; if (!insert_record("quiz_multichoice", $options)) { $result->error = "Could not insert quiz multichoice options!"; return $result; @@ -154,7 +154,7 @@ class quiz_multichoice_qtype extends quiz_default_questiontype { $answerids = array_values(array_map(create_function('$val', 'return $val->id;'), $question->options->answers)); // Shuffle the answers if required - if ($cmoptions->shuffleanswers) { + if ($cmoptions->shuffleanswers and $question->options->shuffleanswers) { $answerids = swapshuffle($answerids); } $state->options->order = $answerids; diff --git a/mod/quiz/questiontypes/randomsamatch/editquestion.php b/mod/quiz/questiontypes/randomsamatch/editquestion.php index 10c71c2ba2e..1df70792efe 100644 --- a/mod/quiz/questiontypes/randomsamatch/editquestion.php +++ b/mod/quiz/questiontypes/randomsamatch/editquestion.php @@ -3,10 +3,16 @@ $options = get_record("quiz_randomsamatch", "question", $question->id); } else { $options->choose = ""; + $options->shuffleanswers = 0; } $saquestions = $QUIZ_QTYPES[RANDOMSAMATCH]->get_sa_candidates($category->id); $numberavailable = count($saquestions); unset($saquestions); + + $yesnooptions = array(); + $yesnooptions[0] = get_string("no"); + $yesnooptions[1] = get_string("yes"); + print_heading_with_help(get_string("editingrandomsamatch", "quiz"), "randomsamatch", "quiz"); require("$CFG->dirroot/mod/quiz/questiontypes/randomsamatch/randomsamatch.html"); diff --git a/mod/quiz/questiontypes/randomsamatch/questiontype.php b/mod/quiz/questiontypes/randomsamatch/questiontype.php index 83c9a059888..c7e1d5143ff 100644 --- a/mod/quiz/questiontypes/randomsamatch/questiontype.php +++ b/mod/quiz/questiontypes/randomsamatch/questiontype.php @@ -16,8 +16,7 @@ class quiz_randomsamatch_qtype extends quiz_match_qtype { } function get_question_options(&$question) { - if (!$question->options->choose = get_field('quiz_randomsamatch', - 'choose', 'question', $question->id)) { + if (!$question->options = get_record('quiz_randomsamatch', 'question', $question->id)) { notify('Error: Missing question options!'); return false; } @@ -33,6 +32,7 @@ class quiz_randomsamatch_qtype extends quiz_match_qtype { function save_question_options($question) { $options->question = $question->id; $options->choose = $question->choose; + $options->shuffleanswers = $question->shuffleanswers; if (2 > $question->choose) { $result->error = "At least two shortanswer questions need to be chosen!"; @@ -153,7 +153,7 @@ class quiz_randomsamatch_qtype extends quiz_match_qtype { // Shuffle the answers if required $subquestionids = array_values(array_map(create_function('$val', 'return $val->id;'), $state->options->subquestions)); - if ($cmoptions->shuffleanswers) { + if ($cmoptions->shuffleanswers and $question->options->shuffleanswers) { $subquestionids = swapshuffle($subquestionids); } diff --git a/mod/quiz/questiontypes/randomsamatch/randomsamatch.html b/mod/quiz/questiontypes/randomsamatch/randomsamatch.html index 9b62df17507..589ddcb2c6d 100644 --- a/mod/quiz/questiontypes/randomsamatch/randomsamatch.html +++ b/mod/quiz/questiontypes/randomsamatch/randomsamatch.html @@ -94,6 +94,15 @@ ?> + + + +qtype]->print_replacement_options($question, $course, $contextquiz); $QUIZ_QTYPES[$question->qtype]->print_question_form_end($question); diff --git a/mod/quiz/restorelib.php b/mod/quiz/restorelib.php index c20dee0edcc..1fe903b1955 100644 --- a/mod/quiz/restorelib.php +++ b/mod/quiz/restorelib.php @@ -588,6 +588,7 @@ $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 @@ -842,6 +843,7 @@ //Now, build the QUIZ_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 quiz_randomsamatch $newid = insert_record ("quiz_randomsamatch",$randomsamatch); diff --git a/mod/quiz/version.php b/mod/quiz/version.php index 952ae2cd0fe..792070887a2 100644 --- a/mod/quiz/version.php +++ b/mod/quiz/version.php @@ -5,7 +5,7 @@ // This fragment is called by moodle_needs_upgrading() and /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2006021102; // The (date) version of this module +$module->version = 2006021103; // The (date) version of this module $module->requires = 2005021600; // Requires this Moodle version $module->cron = 0; // How often should cron check this module (seconds)?
: + shuffleanswers", ""); + helpbutton("shuffleanswers", get_string("shuffleanswers","quiz"), "quiz"); + ?> +
:
: + shuffleanswers", ""); + helpbutton("shuffleanswers", get_string("shuffleanswers","quiz"), "quiz"); + ?> +