You are here

function quiz_build_question_list in Quiz 5

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

Retrieves a question list for a given quiz

Parameters

$nid: Quiz node ID

Return value

Array of question node IDs

1 call to quiz_build_question_list()
quiz_take_quiz in ./quiz.module
Handles quiz taking

File

./quiz.module, line 857
Quiz Module

Code

function quiz_build_question_list($nid) {
  $questions = array();
  $quiz = node_load($nid);

  // Get required questions first
  $result = db_query("SELECT question_nid FROM {quiz_questions} WHERE quiz_nid = %d AND question_status = %d", $nid, QUESTION_ALWAYS);
  while ($question_node = db_fetch_object($result)) {
    $questions[] = $question_node->question_nid;
  }

  // Get random questions for the remainder
  $quiz->number_of_questions -= count($questions);
  if ($quiz->number_of_questions > 0) {
    $result = db_query_range("SELECT question_nid FROM {quiz_questions} WHERE quiz_nid = %d AND question_status = %d ORDER BY RAND()", $nid, QUESTION_RANDOM, 0, $quiz->number_of_questions);
    while ($question_node = db_fetch_object($result)) {
      $questions[] = $question_node->question_nid;
    }
  }

  // Shuffle questions if required
  if ($quiz->shuffle == 1) {
    shuffle($questions);
  }
  return $questions;
}