You are here

function _quiz_get_random_questions in Quiz 6.4

Same name and namespace in other branches
  1. 8.4 quiz.module \_quiz_get_random_questions()
  2. 5.2 quiz.module \_quiz_get_random_questions()
  3. 6.6 quiz.module \_quiz_get_random_questions()
  4. 6.2 quiz.module \_quiz_get_random_questions()
  5. 6.3 quiz.module \_quiz_get_random_questions()
  6. 6.5 quiz.module \_quiz_get_random_questions()
  7. 7.6 quiz.module \_quiz_get_random_questions()
  8. 7 quiz.module \_quiz_get_random_questions()
  9. 7.4 quiz.module \_quiz_get_random_questions()
  10. 7.5 quiz.module \_quiz_get_random_questions()

Get an array list of random questions for a quiz.

Parameters

$quiz: The quiz node.

Return value

Array of nid/vid combos for quiz questions.

1 call to _quiz_get_random_questions()
quiz_build_question_list in ./quiz.module
Retrieves a list of questions (to be taken) for a given quiz.

File

./quiz.module, line 3174
Quiz Module

Code

function _quiz_get_random_questions($quiz) {
  if (!is_object($quiz)) {
    drupal_set_message(t('The question pool cannot be generated.'), 'error');
    watchdog('quiz', '_quiz_get_random_questions was called incorrectly.', array(), WATCHDOG_ERROR);
    return FALSE;
  }
  $num_random = $quiz->number_of_random_questions;
  $tid = $quiz->tid;
  $questions = array();
  if ($num_random > 0) {
    if ($tid > 0) {
      $questions = _quiz_get_random_taxonomy_question_ids($tid, $num_random);
    }
    else {

      // Select random question from assigned pool.
      $result = db_query_range("SELECT child_nid as nid, child_vid as vid\n                                FROM {quiz_node_relationship} qnr\n                                JOIN {node} n on qnr.child_nid = n.nid\n                                WHERE qnr.parent_vid = %d\n                                AND qnr.parent_nid = %d\n                                AND qnr.question_status = %d\n                                AND n.status = 1\n                                ORDER BY RAND()", $quiz->vid, $quiz->nid, QUESTION_RANDOM, 0, $num_random);
      while ($question_node = db_fetch_array($result)) {
        $question_node['random'] = TRUE;
        $question_node['relative_max_score'] = $quiz->max_score_for_random;
        $questions[] = $question_node;
      }
    }
  }
  return $questions;
}