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 @@