You are here

function _quiz_get_questions in Quiz 6.5

Same name and namespace in other branches
  1. 5.2 quiz.module \_quiz_get_questions()
  2. 5 quiz.module \_quiz_get_questions()
  3. 6.6 quiz.module \_quiz_get_questions()
  4. 6.2 quiz.module \_quiz_get_questions()
  5. 6.3 quiz.module \_quiz_get_questions()

Retrieve list of published questions assigned to quiz.

Return value

An array of questions.

3 calls to _quiz_get_questions()
quiz_questions_form in ./quiz.admin.inc
Handles "manage questions" tab.
quiz_update_questions in ./quiz.module
Updates the status of questions assigned to the quiz. Possible statuses are 'random', 'always', 'never'.
theme_quiz_view in ./quiz.pages.inc
Theme the node view for quizzes.

File

./quiz.module, line 2382
Quiz Module

Code

function _quiz_get_questions($quiz_vid = NULL, $include_all_types = TRUE, $nid_keys = FALSE) {
  $quiz = node_load((int) arg(1));
  $filter_types = '';
  $questions = array();
  $where_add = array();
  $where_sql = '';
  if ($include_all_types === TRUE) {
    $types = array_keys(_quiz_get_question_types());
    if (count($types) > 0) {
      $str_types = "'" . implode("','", $types) . "'";
      $where_add[] = 'question.type IN ( ' . $str_types . ' )';
    }
  }
  if (!is_null($quiz_vid)) {
    $where_add[] = 'qnr.parent_vid = ' . (int) $quiz_vid;
    $where_add[] = 'qnr.parent_nid = ' . $quiz->nid;
  }

  // Only include published questions.
  $where_add[] = 'question.status = 1';
  if (count($where_add)) {
    $where_sql = ' WHERE ';
    foreach ($where_add as $where) {
      $where_sql .= $where . ' AND ';
    }
    $where_sql = trim($where_sql, ' AND ');
  }
  $result = db_query('SELECT DISTINCT question.nid, question.vid, question.type, nr.title, nr.body, nr.format, qnr.question_status, qnr.weight
    FROM {node} question
    INNER JOIN {node_revisions} nr ON question.nid = nr.nid
    LEFT JOIN {quiz_node_relationship} qnr ON nr.vid = qnr.child_vid
      AND qnr.parent_vid = %d
      AND qnr.question_status != %d
    ' . $where_sql . ' ORDER BY weight', $quiz_vid, QUESTION_NEVER);

  // Create questions array.
  if ($nid_keys === FALSE) {
    while ($node = db_fetch_object($result)) {
      $questions[] = quiz_node_map($node);
    }
  }
  else {
    while ($node = db_fetch_object($result)) {
      $n = quiz_node_map($node);
      $questions[$n->nid] = $n;
    }
  }
  return $questions;
}