New quiz switches to

- shuffle questions order
  - shuffle answers order
This commit is contained in:
moodler 2003-04-09 13:57:08 +00:00
parent f5cbbecaf5
commit 4b85b71712
10 changed files with 100 additions and 19 deletions

View File

@ -0,0 +1,13 @@
<P ALIGN=CENTER><B>Shuffle answers</B></P>
<p>If you enable this option, then the order of answers within
each question will be randinly shuffled each time a student
attempts this quiz.</p>
<p>Of course, this only applies to questions that have multiple
answers displayed, such as Multiple Choice, or Matching Questions.</p>
<p>The intention is simply to make it a little harder for students
to copy from each other.</p>
<p>This option is not related to the use of Random Questions.</p>

View File

@ -0,0 +1,11 @@
<P ALIGN=CENTER><B>Shuffle questions</B></P>
<p>If you enable this option, then the order of questions in
the quiz will be randomly shuffled each time a student attempts
the quiz.</p>
<p>This is not related to the use of Random Questions, this is only
about the displayed order of questions.</p>
<p>The intention is to make it a little harder for students to copy from
each other.</p>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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 "<P ALIGN=CENTER><FONT SIZE=1>$grade $strmarks</FONT></P>";
}
print_spacer(1,100);
echo "<p align=\"center\">";
quiz_print_question_icon($question, false);
echo "</p></TD><TD VALIGN=TOP>";
echo "</TD><TD VALIGN=TOP>";
if (empty($realquestion)) {
$realquestion->id = $question->id;
@ -522,6 +520,10 @@ function quiz_print_question($number, $question, $grade, $courseid,
echo "<TABLE>";
$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 "<BR>";
}

View File

@ -4,37 +4,43 @@
<?PHP
require_once("$CFG->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 @@
?>
</TD>
</TR>
<TR valign=top>
<TD align=right><P><B><? print_string("shufflequestions", "quiz") ?>:</B></P></TD>
<TD>
<?
$options = array();
$options[0] = get_string("no");
$options[1] = get_string("yes");
choose_from_menu($options, "shufflequestions", "$form->shufflequestions", "");
helpbutton("shufflequestions", get_string("shufflequestions","quiz"), "quiz");
?>
</TD>
</TR>
<TR valign=top>
<TD align=right><P><B><? print_string("shuffleanswers", "quiz") ?>:</B></P></TD>
<TD>
<?
$options = array();
$options[0] = get_string("no");
$options[1] = get_string("yes");
choose_from_menu($options, "shuffleanswers", "$form->shuffleanswers", "");
helpbutton("shuffleanswers", get_string("shuffleanswers","quiz"), "quiz");
?>
</TD>
</TR>
<TR valign=top>
<TD align=right><P><B><? print_string("maximumgrade") ?>:</B></P></TD>
<TD>

View File

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