You are here

function quiz_get_questions in Quiz 7.6

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 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.

Return value

An array of questions.

3 calls to quiz_get_questions()
quiz_add_question_to_quiz in ./quiz.module
Action to add questions to the current quiz.
quiz_insert in ./quiz.module
Implements hook_insert().
quiz_questions_form in ./quiz.admin.inc
Handles "manage questions" tab.

File

./quiz.module, line 3052
quiz.module Main file for the Quiz module.

Code

function quiz_get_questions($quiz_nid, $quiz_vid = NULL) {
  $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',
    'auto_update_max_score',
    'qnr_id',
    'qnr_pid',
    'child_nid',
    'child_vid',
  ));
  $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');
  $query
    ->condition('n.status', 1);
  $query
    ->condition('qnr.parent_nid', $quiz_nid);
  if ($quiz_vid) {
    $query
      ->condition('qnr.parent_vid', $quiz_vid);
  }
  $query
    ->condition('qnr_pid', NULL, 'IS');
  $query
    ->orderBy('qnr.weight');
  $result = $query
    ->execute();
  foreach ($result as $question) {
    $questions[] = $question;
    quiz_get_sub_questions($question->qnr_id, $questions);
  }
  return $questions;
}