You are here

function _quiz_get_unused_questions in Quiz 6.2

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

Retrieve list of published questions not assigned to quiz.

@access public

Parameters

integer $quiz_nid:

Return value

array Array of questions objects.

1 call to _quiz_get_unused_questions()
quiz_questions_form in ./quiz.admin.inc
Handles "manage questions" tab.

File

./quiz.module, line 1618
Quiz Module

Code

function _quiz_get_unused_questions($quiz_vid = NULL, $nid_keys = FALSE) {
  $quiz = menu_get_object();
  $types = _quiz_get_question_types();
  $where_sql = '';
  $questions = array();
  if (count($types)) {
    $where_sql = "AND question.type IN ('" . implode("','", $types) . "')";
  }
  $result = db_query('SELECT DISTINCT question.nid, question.vid, question.type, nr.body, nr.format
    FROM {node} question
    LEFT JOIN {node_revisions} nr ON (question.nid = nr.nid)
    WHERE question.status = 1
    AND (question.vid NOT IN
      (SELECT DISTINCT qnr.child_vid
      FROM {quiz_node_relationship} qnr
      WHERE qnr.parent_vid = %d
      AND qnr.question_status != ' . QUESTION_NEVER . '))
    ' . $where_sql, $quiz_vid);

  // 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;
}