]> git.mjollnir.org Git - moodle.git/commitdiff
New quiz switches to
authormoodler <moodler>
Wed, 9 Apr 2003 13:57:08 +0000 (13:57 +0000)
committermoodler <moodler>
Wed, 9 Apr 2003 13:57:08 +0000 (13:57 +0000)
  - shuffle questions order
  - shuffle answers order

lang/en/help/quiz/shuffleanswers.html [new file with mode: 0644]
lang/en/help/quiz/shufflequestions.html [new file with mode: 0644]
lang/en/quiz.php
mod/quiz/db/mysql.php
mod/quiz/db/mysql.sql
mod/quiz/db/postgres7.php
mod/quiz/db/postgres7.sql
mod/quiz/lib.php
mod/quiz/mod.html
mod/quiz/version.php

diff --git a/lang/en/help/quiz/shuffleanswers.html b/lang/en/help/quiz/shuffleanswers.html
new file mode 100644 (file)
index 0000000..3039cbb
--- /dev/null
@@ -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>
diff --git a/lang/en/help/quiz/shufflequestions.html b/lang/en/help/quiz/shufflequestions.html
new file mode 100644 (file)
index 0000000..45c8ef5
--- /dev/null
@@ -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>
index 9947ea5d37f013d4a0b18d0b5f1b9e65c9a581e5..0c3b785997533107961092bf8708c9d46716247e 100644 (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";
index b73b912de1ddc7a26ddf6bc4555af5abc28e4fe4..37eeaa6d1938c062ae979008b020d65b1ade2dfa 100644 (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;
 }
 
index 90030d04c04a46dd241b5a163a75546f0c6f650b..1ccd6ef9b6a004b8d6fcbad2316739fd11581ccd 100644 (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',
index eac41b021bd1a523731211e36b3cfccf07ff50d3..dac1dc2ca1f60d451909b08fa2f9e97951d27781 100644 (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;
 }
 
index 33293c025d6a848617c0afe1492679745fd1f024..0dbd67f0cc9fd58ce023147160ffdddce8d899ce 100644 (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',
index bde77c2c9a659c60807fb4f789e91e9f59687976..8091ad56fb8464b1e4189a67026b7fe5ec01a2a9 100644 (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>";
     }
index ed70d9b5a9ac08e67adbe022eb586878ccb76525..5ac9de14a1414bb7beb50c05cf66200197f07e20 100644 (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 = "";
     }
 ?>
      ?>
     </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>
index c462022cb7fd9e583069dc0046156814dc0d41f6..9283b57bd61a50f80530025eadf4aab318ada0f7 100644 (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)?
 
 ?>