You are here

function quiz_get_questions in Quiz 7

Same name and namespace in other branches
  1. 8.4 quiz.module \quiz_get_questions()
  2. 6.4 quiz.module \quiz_get_questions()
  3. 7.6 quiz.module \quiz_get_questions()
  4. 7.4 quiz.module \quiz_get_questions()
  5. 7.5 quiz.module \quiz_get_questions()

Retrieve list of published questions assigned to quiz.

This function should be used for question browsers and similiar... It should not be used to decide what questions a user should answer when taking a quiz. quiz_build_question_list is written for that purpose.

Parameters

$quiz_nid: Quiz node id.

$quiz_vid: Quiz node version id.

$include_all_types: Should the results be filtered on available question types? @todo: review this.

$nid_keys: Should nid be used as keys in the array we return?

$include_question: Should the question(the node body) be included for the questions in the returned array?

Return value

An array of questions.

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

File

./quiz.module, line 3437
Quiz Module

Code

function quiz_get_questions($quiz_nid = NULL, $quiz_vid = NULL, $include_all_types = TRUE, $nid_keys = FALSE, $include_question = TRUE, $include_random) {
  $questions = array();
  $query = db_select('node', 'n');
  $query
    ->fields('n', array(
    'nid',
    'type',
  ));
  $query
    ->fields('nr', array(
    'vid',
    'title',
  ));
  $query
    ->fields('qnr', array(
    'question_status',
    'weight',
    'max_score',
  ));
  $query
    ->addField('n', 'vid', 'latest_vid');
  $query
    ->join('node_revision', 'nr', 'n.nid = nr.nid');
  $query
    ->leftJoin('quiz_node_relationship', 'qnr', 'nr.vid = qnr.child_vid');
  if ($include_all_types === TRUE) {
    $query
      ->condition('n.type', array_keys(_quiz_get_question_types()), 'IN');
  }
  if (!is_null($quiz_vid)) {
    $query
      ->condition('parent_vid', $quiz_vid);
    $query
      ->condition('parent_nid', $quiz_nid);
  }
  $query
    ->condition('question_status', $include_random ? QUESTION_NEVER : QUESTION_ALWAYS)
    ->condition('n.status', 1)
    ->orderBy('weight');
  $results = $query
    ->execute();
  foreach ($results as $result) {
    $node = $result;

    // Create questions array.
    if ($nid_keys === FALSE) {

      //while ($node = db_fetch_object($result)) {
      $questions[] = quiz_node_map($node, $include_question);

      //}
    }
    else {

      //while ($node = db_fetch_object($result)) {
      $n = quiz_node_map($node, $include_question);
      $questions[$n->nid] = $n;

      //}
    }
  }
  return $questions;
}