Skip to content

Commit

Permalink
Fixed a potential bug that would have hit if one quiz would have had …
Browse files Browse the repository at this point in the history
…two random questions for the same category, one of which was set to recurse into subcategories and the other not.

At the same time this improves performance because no longer all the potential questions are loaded from the database but only their ids.
  • Loading branch information
gustav_delius committed Feb 5, 2006
1 parent 1a914bc commit 5e468d3
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions mod/quiz/questiontypes/random/questiontype.php
Expand Up @@ -42,7 +42,7 @@ function create_session_and_responses(&$question, &$state, $cmoptions, $attempt)
$cmoptions->questionsinuse = $attempt->layout;
}

if (!isset($this->catrandoms[$question->category])) {
if (!isset($this->catrandoms[$question->category][$question->questiontext])) {
// Need to fetch random questions from category $question->category"
// (Note: $this refers to the questiontype, not the question.)
global $CFG;
Expand All @@ -53,23 +53,22 @@ function create_session_and_responses(&$question, &$state, $cmoptions, $attempt)
} else {
$categorylist = $question->category;
}
$this->catrandoms[$question->category] = get_records_sql
("SELECT * FROM {$CFG->prefix}quiz_questions
$catrandoms = get_records_sql
("SELECT id,id FROM {$CFG->prefix}quiz_questions
WHERE category IN ($categorylist)
AND parent = '0'
AND id NOT IN ($cmoptions->questionsinuse)
AND qtype NOT IN ($excludedtypes)");
$this->catrandoms[$question->category] =
draw_rand_array($this->catrandoms[$question->category],
count($this->catrandoms[$question->category])); // from bug 1889
$this->catrandoms[$question->category][$question->questiontext] =
draw_rand_array(catrandoms, count($catrandoms)); // from bug 1889
}

while ($wrappedquestion =
array_pop($this->catrandoms[$question->category])) {
array_pop($this->catrandoms[$question->category][$question->questiontext])) {
if (!ereg("(^|,)$wrappedquestion->id(,|$)", $cmoptions->questionsinuse)) {
/// $randomquestion is not in use and will therefore be used
/// as the randomquestion here...

$wrappedquestion = get_record('quiz_questions', 'id', $wrappedquestion->id);
global $QUIZ_QTYPES;
$QUIZ_QTYPES[$wrappedquestion->qtype]
->get_question_options($wrappedquestion);
Expand Down

0 comments on commit 5e468d3

Please sign in to comment.