Excluded form quiz_choose_random_questions the quiz
authorstronk7 <stronk7>
Wed, 2 Jul 2003 17:30:42 +0000 (17:30 +0000)
committerstronk7 <stronk7>
Wed, 2 Jul 2003 17:30:42 +0000 (17:30 +0000)
questions to avoid duplicates in quiz. Bug #544. Closed.

mod/quiz/lib.php

index dadd39d3ec3766b6c671b257ed10fb1a3d6b4e3a..f5e7c652772868d6e5802c92f58e90779b3c835b 100644 (file)
@@ -747,7 +747,7 @@ function quiz_print_quiz_questions($quiz, $results=NULL, $questions=NULL, $shuff
         if ($randomcats = quiz_get_random_categories($quiz->questions)) {
             foreach ($randomcats as $randomcat => $randomdraw) {
                 /// Get the appropriate amount of random questions from this category
-                if (!$catquestions[$randomcat] = quiz_choose_random_questions($randomcat, $randomdraw)) {
+                if (!$catquestions[$randomcat] = quiz_choose_random_questions($randomcat, $randomdraw, $quiz->questions)) {
                     notify(get_string("toomanyrandom", "quiz", $randomcat));
                     return false;
                 }
@@ -908,12 +908,12 @@ function quiz_print_category_form($course, $current) {
 
 
 
-function quiz_choose_random_questions($category, $draws) {
+function quiz_choose_random_questions($category, $draws, $excluded=0) {
 /// Given a question category and a number of draws, this function
 /// creates a random subset of that size - returned as an array of questions
 
     if (!$pool = get_records_select_menu("quiz_questions", 
-                "category = '$category' AND qtype <> ".RANDOM, "", "id,qtype")) {
+                "category = '$category' AND id NOT IN ($excluded) AND qtype <> ".RANDOM, "", "id,qtype")) {
         return false;
     }