]> git.mjollnir.org Git - moodle.git/commitdiff
Changed user interface for adding multiple random questions, see http://moodle.org...
authorgustav_delius <gustav_delius>
Wed, 29 Dec 2004 22:57:35 +0000 (22:57 +0000)
committergustav_delius <gustav_delius>
Wed, 29 Dec 2004 22:57:35 +0000 (22:57 +0000)
lang/en/help/quiz/random.html
lang/en/quiz.php
mod/quiz/lib.php
mod/quiz/multiple.php

index 189bfe2979fe2b5edbe361b6edc8183997e882cb..ea5ae4ab002726b66a02055eebefd21b2c56406f 100644 (file)
@@ -1,18 +1,15 @@
 <p align="center"><b>Random Question</b></p>
 
-<p>Random questions are a special question type.</p>
-
-<p>When you put a Random Question into a quiz, then a question 
-   will be chosen randomly from the whole category, on each attempt.</p>
-
-<p>The maximum grade for the question will always be when you have chosen
-   as the grade for the Random Question.</p>
-
-<p>If you make a quiz with, say, 10 random questions, then each student 
-   may get a completely different set of 10 questions each time they
-   attempt the quiz.</p>
-
-<p>Note that you can mix random and non-random questions if you want to 
-   ensure that particular questions are always included.</p>
-
-
+<p>When you put a random question into a quiz, then a question 
+   will be chosen randomly from the category, on each attempt. Thus different students
+   are likely to get a different selection of questions and furthermore for quizzes that allow
+   reattempts that are not based on previous attempts, the new attempt are likely to contain a
+   new selection of questions. </p>
+   
+<p>If you include several random questions then different questions will be chosen for each of
+   them. If you mix random and non-random questions then the random questions
+   will be chosen so that they do not duplicate one of the non-random questions.
+   </p>
+
+<p>The grade for the randomly chosen question will be rescaled so that the maximum grade is 
+   what you have chosen as the grade for the random question.</p>
index 76f5631640d66d930aac2c750fe09afe15f7ff6c..1dfc09fdfc8fc72f808e53a13a96f234c06886d3 100644 (file)
@@ -6,6 +6,8 @@ $string['acceptederror'] = 'Accepted error';
 $string['addingquestions'] = 'This side of the page is where you manage your database of questions.  Questions are stored in categories to help you keep them organised, and can be used by any quiz in your course or even other courses if you choose to \'publish\' them. <br /><br />After you select or create a question category you will be able to create or edit questions.  You can select any of these questions to add to your quiz over on the other side of this page.';
 $string['addquestions'] = 'Add questions';
 $string['addquestionstoquiz'] = 'Add questions to current quiz';
+$string['addrandom1'] = ' Add ';
+$string['addrandom2'] = 'random questions ';
 $string['addselectedtoquiz'] = 'Add selected to quiz';
 $string['aiken'] = 'Aiken format';
 $string['allowreview'] = 'Allow review';
@@ -59,7 +61,7 @@ $string['countdownfinished'] = 'The quiz is closing, you should submit your answ
 $string['countdowntenminutes'] = 'The quiz will be closing in ten minutes.';
 $string['coursetestmanager'] = 'Course Test Manager format';
 $string['createfirst'] = 'You must create some short-answer questions first. ';
-$string['createmultiple'] = 'Create multiple questions';
+$string['createmultiple'] = 'Add several random questions to quiz';
 $string['createnewquestion'] = 'Create new question';
 $string['custom'] = 'Custom format';
 $string['datasetdefinitions'] = 'Reusable dataset definitions for category $a';
index cdba95e9a3b91340becd5c046335191345fa4dc3..ad71e8792185940266ee45163d34d6877a5daba7 100644 (file)
@@ -31,7 +31,6 @@ $QUIZ_QUESTION_TYPE = array ( MULTICHOICE   => get_string("multichoice", "quiz")
                               CALCULATED    => get_string("calculated", "quiz"),
                               MATCH         => get_string("match", "quiz"),
                               DESCRIPTION   => get_string("description", "quiz"),
-                              RANDOM        => get_string("random", "quiz"),
                               RANDOMSAMATCH => get_string("randomsamatch", "quiz"),
                               MULTIANSWER   => get_string("multianswer", "quiz")
                               );
@@ -936,7 +935,7 @@ function quiz_print_question_icon($question, $editlink=true) {
 
     if ($editlink) {
         echo "<a href=\"question.php?id=$question->id\" title=\""
-                .$QUIZ_QUESTION_TYPE[$question->qtype]."\">";
+                .$QUIZ_QTYPES[$question->qtype]->name()."\">";
     }
     echo '<img border="0" height="16" width="16" src="questiontypes/';
     echo $QUIZ_QTYPES[$question->qtype]->name().'/icon.gif" alt="';
@@ -1385,14 +1384,6 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true) {
         echo '<td width="10" valign="top" align="right">';
         helpbutton("questiontypes", $strcreatenewquestion, "quiz");
         echo '</td></tr>';
-
-        echo '<tr><td colspan="3" align="right">';
-        echo '<form method="get" action="import.php">';
-        echo "<input type=\"hidden\" name=\"category\" value=\"$category->id\" />";
-        echo "<input type=\"submit\" value=\"$strimportquestions\" />";
-        helpbutton("import", $strimportquestions, "quiz");
-        echo '</form>';
-        echo '</td></tr>';
     }
     else {
         echo '<tr><td>';
@@ -1400,23 +1391,15 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true) {
         echo '</td></tr>';
     }
 
-    echo '<tr><td colspan="3" align="right">';
-    echo '<form method="get" action="export.php">';
-    echo "<input type=\"hidden\" name=\"category\" value=\"$category->id\" />";
-    echo "<input type=\"submit\" value=\"$strexportquestions\" />";
-    helpbutton("export", $strexportquestions, "quiz");
-    echo '</form>';
-    echo '</td></tr>';
-
+    echo '<tr><td colspan="3" align="right"><font size="2">';
     if (isteacheredit($category->course)) {
-        echo '<tr><td colspan="3" align="right">';
-        echo '<form method="get" action="multiple.php">';
-        echo "<input type=\"hidden\" name=\"category\" value=\"$category->id\" />";
-        echo "<input type=\"submit\" value=\"$strcreatemultiple\" />";
-        helpbutton("createmultiple", $strcreatemultiple, "quiz");
-        echo '</form>';
-        echo '</td></tr>';
+        echo '<a href="import.php?category='.$category->id.'">'.$strimportquestions.'</a>';
+        helpbutton("import", $strimportquestions, "quiz");
+        echo ' | ';
     }
+    echo '<a href="export.php?category='.$category->id.'">'.$strexportquestions.'</a>';
+    helpbutton("export", $strexportquestions, "quiz");
+    echo '</font></td></tr>';
 
     echo '</table>';
 
@@ -1443,6 +1426,9 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true) {
     }
     echo "</tr>\n";
     foreach ($questions as $question) {
+        if ($question->qtype == RANDOM) {
+            continue;
+        }
         echo "<tr bgcolor=\"$THEME->cellcontent\">\n";
         if ($quizselected) {
             echo "<td align=\"center\">";
@@ -1474,6 +1460,22 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true) {
     }
     echo "</table>\n";
     echo "</form>\n";
+    if ($quizselected and isteacheredit($category->course)) {
+        for ($i=1;$i<=10; $i++) {
+            $randomcount[$i] = $i;
+        }
+        echo '<form method="post" action="multiple.php">';
+        print_string('addrandom1', 'quiz');
+        choose_from_menu($randomcount, 'randomcreate', '10', '');
+        print_string('addrandom2', 'quiz');
+        // Don't offer the option to change the grade
+        //choose_from_menu($randomcount, 'randomgrade', '1', '');
+        echo '<input type="hidden" name="randomgrade", value="1" />';
+        echo "<input type=\"hidden\" name=\"category\" value=\"$category->id\" />";
+        echo ' <input type="submit" name="save" value="'. get_string('add') .'" />';
+        helpbutton('random', get_string('random', 'quiz'), 'quiz');
+        echo '</form>';
+    }
 }
 
 
index 862d1518b32d140b17bad733bf2072c1d19a9a27..3c715c6ad3c4697ad6b3cc3808b026f1f8be77e1 100644 (file)
 
     if ($form = data_submitted()) {
         if ($form->randomcreate > 0) {
-            $existing = count_records('quiz_questions', 'qtype', RANDOM, 'category', $category->id);
-            $randomcreate = $form->randomcreate - $existing;
+            $newquestionids = array(); // this will hold the ids of the random questions
+            
+            // find existing random questions in this category
+            $random = RANDOM;
+            if ($existingquestions = get_records_select('quiz_questions', "qtype = '$random' AND category = '$category->id'")) {
+                // now remove the ones that are already used in this quiz, if any
+                if ($questionids = explode(',', $modform->questions)) {
+                    foreach ($questionids as $questionid) {
+                        foreach ($existingquestions as $key => $existingquestion) {
+                            if ($existingquestion->id == $questionid) {
+                                unset($existingquestions[$key]);
+                                break;
+                            }
+                        }
+                    }
+                }
+                // now take as many of these as needed
+                $i = 0;
+                while (($existingquestion = array_pop($existingquestions)) and ($i < $form->randomcreate)) {
+                    $newquestionids[] = $existingquestion->id;
+                    $i++;
+                }
+                $randomcreate = $form->randomcreate - $i; // the number of additional random questions needed.
+            } else {
+                $randomcreate = $form->randomcreate;
+            }
 
             if ($randomcreate > 0) {
-                $newquestionids = array();
 
                 $question->qtype = RANDOM;
                 $question->category = $category->id;
                         error('Could not insert new random question!');
                     }
                 }
+            }
 
-                // Add them to the quiz if necessary
-                if (!empty($form->addquestionstoquiz)) {
-                    if (!empty($modform->questions)) {
-                        $questionids = explode(',', $modform->questions);
-                        foreach ($questionids as $questionid) {
-                            foreach ($newquestionids as $key => $newquestionid) {
-                                if ($newquestionid == $questionid) {
-                                    unset($newquestionids[$key]);
-                                    break;
-                                }
-                            }
-                        }
-                    } else {
-                        $questionids = array();
-                    }
-
-                    foreach ($newquestionids as $newquestionid) {
-                        $modform->grades[$newquestionid] = $form->randomgrade;
-                        $modform->sumgrades += $form->randomgrade;
-                    }
+            // Add them to the quiz
+            if (!empty($modform->questions)) {
+                $questionids = explode(',', $modform->questions);
+            } else {
+                $questionids = array();
+            }
 
-                    $newquestionids = array_merge($questionids, $newquestionids);
-                    $modform->questions = implode(',', $newquestionids);
-                    $SESSION->modform = $modform;
-                }
+            foreach ($newquestionids as $newquestionid) {
+                $modform->grades[$newquestionid] = $form->randomgrade;
+                $modform->sumgrades += $form->randomgrade;
             }
+
+            $newquestionids = array_merge($questionids, $newquestionids);
+            $modform->questions = implode(',', $newquestionids);
+            $SESSION->modform = $modform;
         }
         redirect('edit.php');
     }
     choose_from_menu($gradecount, 'randomgrade', '1', '');
     echo '</tr>';
 
-    echo '<tr><td align="right">';
-    print_string('addquestionstoquiz', 'quiz');
-    echo ':</td><td>';
-    choose_from_menu($options, 'addquestionstoquiz', '1', '');
-    echo '</tr>';
-
     echo '<tr><td>&nbsp;</td><td>';
     echo ' <input type="hidden" name="category" value="'. $category->id .'" />';
-    echo ' <input type="submit" name="save" value="'. $strcreatemultiple .'" />';
+    echo ' <input type="submit" name="save" value="'. get_string('add') .'" />';
     echo '</td></tr>';
     echo '</table>';
     echo '</form>';
 
     print_footer();
 
-?>
\ No newline at end of file
+?>