diff --git a/lang/en/help/quiz/shuffleanswers.html b/lang/en/help/quiz/shuffleanswers.html new file mode 100644 index 00000000000..3039cbb3fc5 --- /dev/null +++ b/lang/en/help/quiz/shuffleanswers.html @@ -0,0 +1,13 @@ +

Shuffle answers

+ +

If you enable this option, then the order of answers within + each question will be randinly shuffled each time a student + attempts this quiz.

+ +

Of course, this only applies to questions that have multiple + answers displayed, such as Multiple Choice, or Matching Questions.

+ +

The intention is simply to make it a little harder for students + to copy from each other.

+ +

This option is not related to the use of Random Questions.

diff --git a/lang/en/help/quiz/shufflequestions.html b/lang/en/help/quiz/shufflequestions.html new file mode 100644 index 00000000000..45c8ef5b54f --- /dev/null +++ b/lang/en/help/quiz/shufflequestions.html @@ -0,0 +1,11 @@ +

Shuffle questions

+ +

If you enable this option, then the order of questions in + the quiz will be randomly shuffled each time a student attempts + the quiz.

+ +

This is not related to the use of Random Questions, this is only + about the displayed order of questions.

+ +

The intention is to make it a little harder for students to copy from + each other.

diff --git a/lang/en/quiz.php b/lang/en/quiz.php index 9947ea5d37f..0c3b7859975 100644 --- a/lang/en/quiz.php +++ b/lang/en/quiz.php @@ -118,6 +118,8 @@ $string['shortanswer'] = "Short Answer"; $string['show'] = "Show"; $string['showfeedback'] = "After answering, show feedback?"; $string['showcorrectanswer'] = "In feedback, show correct answers?"; +$string['shuffleanswers'] = "Shuffle answers"; +$string['shufflequestions'] = "Shuffle questions"; $string['time'] = "Time"; $string['timetaken'] = "Time taken"; $string['timecompleted'] = "Completed"; diff --git a/mod/quiz/db/mysql.php b/mod/quiz/db/mysql.php index b73b912de1d..37eeaa6d193 100644 --- a/mod/quiz/db/mysql.php +++ b/mod/quiz/db/mysql.php @@ -53,6 +53,7 @@ function quiz_upgrade($oldversion) { if ($oldversion < 2003030303) { table_column("quiz_questions", "", "defaultgrade", "INTEGER", "6", "UNSIGNED", "1", "NOT NULL", "image"); } + if ($oldversion < 2003032601) { execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_answers` ADD INDEX(question) "); execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_attempts` ADD INDEX(quiz) "); @@ -86,6 +87,11 @@ function quiz_upgrade($oldversion) { );"); } + if ($oldversion < 2003040901) { + table_column("quiz", "", "shufflequestions", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "review"); + table_column("quiz", "", "shuffleanswers", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "shufflequestions"); + } + return true; } diff --git a/mod/quiz/db/mysql.sql b/mod/quiz/db/mysql.sql index 90030d04c04..1ccd6ef9b6a 100644 --- a/mod/quiz/db/mysql.sql +++ b/mod/quiz/db/mysql.sql @@ -25,6 +25,8 @@ CREATE TABLE `prefix_quiz` ( `correctanswers` tinyint(4) NOT NULL default '1', `grademethod` tinyint(4) NOT NULL default '1', `review` tinyint(4) NOT NULL default '0', + `shufflequestions` tinyint(4) NOT NULL default '0', + `shuffleanswers` tinyint(4) NOT NULL default '0', `questions` text NOT NULL, `sumgrades` int(10) NOT NULL default '0', `grade` int(10) NOT NULL default '0', diff --git a/mod/quiz/db/postgres7.php b/mod/quiz/db/postgres7.php index eac41b021bd..dac1dc2ca1f 100644 --- a/mod/quiz/db/postgres7.php +++ b/mod/quiz/db/postgres7.php @@ -47,6 +47,11 @@ function quiz_upgrade($oldversion) { modify_database ("", "CREATE INDEX question_quiz_multichoice_idx ON prefix_quiz_multichoice (question);"); } + if ($oldversion < 2003040901) { + table_column("quiz", "", "shufflequestions", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "review"); + table_column("quiz", "", "shuffleanswers", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "shufflequestions"); + } + return true; } diff --git a/mod/quiz/db/postgres7.sql b/mod/quiz/db/postgres7.sql index 33293c025d6..0dbd67f0cc9 100644 --- a/mod/quiz/db/postgres7.sql +++ b/mod/quiz/db/postgres7.sql @@ -25,6 +25,8 @@ CREATE TABLE prefix_quiz ( correctanswers integer NOT NULL default '1', grademethod integer NOT NULL default '1', review integer NOT NULL default '0', + shufflequestions integer NOT NULL default '0', + shuffleanswers integer NOT NULL default '0', questions text NOT NULL default '', sumgrades integer NOT NULL default '0', grade integer NOT NULL default '0', diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index bde77c2c9a6..8091ad56fb8 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -397,7 +397,7 @@ function quiz_print_question_icon($question, $editlink=true) { function quiz_print_question($number, $question, $grade, $courseid, $feedback=NULL, $response=NULL, $actualgrade=NULL, $correct=NULL, - $realquestion=NULL) { + $realquestion=NULL, $shuffleanswers=false) { /// Prints a quiz question, any format /// $question is provided as an object @@ -417,9 +417,7 @@ function quiz_print_question($number, $question, $grade, $courseid, echo "

$grade $strmarks

"; } print_spacer(1,100); - echo "

"; - quiz_print_question_icon($question, false); - echo "

"; + echo ""; if (empty($realquestion)) { $realquestion->id = $question->id; @@ -522,6 +520,10 @@ function quiz_print_question($number, $question, $grade, $courseid, echo ""; $answerids = explode(",", $options->answers); + if ($shuffleanswers) { + $answerids = swapshuffle($answerids); + } + foreach ($answerids as $key => $answerid) { $answer = $answers[$answerid]; $qnumchar = chr(ord('a') + $key); @@ -563,6 +565,9 @@ function quiz_print_question($number, $question, $grade, $courseid, if (!$subquestions = get_records_list("quiz_match_sub", "id", $options->subquestions)) { notify("Error: Missing subquestions for this question!"); } + if ($shuffleanswers) { + $subquestions = draw_rand_array($subquestions, count($subquestions)); + } echo text_to_html($question->questiontext); if ($question->image) { print_file_picture($question->image, $courseid, QUIZ_PICTURE_DEFAULT_HEIGHT); @@ -721,6 +726,10 @@ function quiz_print_quiz_questions($quiz, $results=NULL, $questions=NULL) { notify("Error when reading questions from the database!"); return false; } + + if (!empty($quiz->shufflequestions)) { + $questions = swapshuffle_assoc($questions); + } } if (!$grades = get_records_list("quiz_question_grades", "question", $quiz->questions, "", "question,grade")) { @@ -802,7 +811,8 @@ function quiz_print_quiz_questions($quiz, $results=NULL, $questions=NULL) { print_simple_box_start("CENTER", "90%"); quiz_print_question($count, $question, $grades[$question->id]->grade, $quiz->course, - $feedback, $response, $actualgrades, $correct, $randomquestion); + $feedback, $response, $actualgrades, $correct, + $randomquestion, $quiz->shuffleanswers); print_simple_box_end(); echo "
"; } diff --git a/mod/quiz/mod.html b/mod/quiz/mod.html index ed70d9b5a9a..5ac9de14a14 100644 --- a/mod/quiz/mod.html +++ b/mod/quiz/mod.html @@ -4,37 +4,43 @@ dirroot/mod/quiz/lib.php"); - if (empty($form->name)) { + if (!isset($form->name)) { $form->name = ""; } - if (empty($form->intro)) { + if (!isset($form->intro)) { $form->intro = ""; } - if (empty($form->timeopen)) { + if (!isset($form->timeopen)) { $form->timeopen = ""; } - if (empty($form->timeclose)) { + if (!isset($form->timeclose)) { $form->timeclose = ""; } - if (empty($form->attempts)) { - $form->attempts = "0"; + if (!isset($form->attempts)) { + $form->attempts = 0; } - if (empty($form->grademethod)) { + if (!isset($form->grademethod)) { $form->grademethod = ""; } - if (empty($form->feedback)) { + if (!isset($form->feedback)) { $form->feedback = ""; } - if (empty($form->correctanswers)) { + if (!isset($form->correctanswers)) { $form->correctanswers = ""; } - if (empty($form->review)) { - $form->review = ""; + if (!isset($form->review)) { + $form->review = 0; } - if (empty($form->grade)) { + if (!isset($form->shufflequestions)) { + $form->shufflequestions = 1; + } + if (!isset($form->shuffleanswers)) { + $form->shuffleanswers = 1; + } + if (!isset($form->grade)) { $form->grade = ""; } - if (empty($form->questions)) { + if (!isset($form->questions)) { $form->questions = ""; } ?> @@ -147,6 +153,30 @@ ?> + + + + + + + +

:

+ shufflequestions", ""); + helpbutton("shufflequestions", get_string("shufflequestions","quiz"), "quiz"); + ?> +

:

+ shuffleanswers", ""); + helpbutton("shuffleanswers", get_string("shuffleanswers","quiz"), "quiz"); + ?> +

:

diff --git a/mod/quiz/version.php b/mod/quiz/version.php index c462022cb7f..9283b57bd61 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 = 2003033100; // The (date) version of this module +$module->version = 2003040901; // The (date) version of this module $module->cron = 0; // How often should cron check this module (seconds)? ?>