You are here

function multichoice_get_report in Quiz 6.6

Same name and namespace in other branches
  1. 5.2 multichoice.module \multichoice_get_report()
  2. 6.2 multichoice.module \multichoice_get_report()
  3. 6.3 question_types/multichoice/multichoice.module \multichoice_get_report()
  4. 6.5 question_types/multichoice/multichoice.module \multichoice_get_report()

Retrieve a full multichoice question with answers and user answers for reporting.

Parameters

$nid: The question node id.

$vid: The question node revision id.

$rid: The result id.

Return value

$question Question object with all available answers, and the user answers, and question properties.

File

question_types/multichoice/multichoice.module, line 1051
Multiple choice question type for the Quiz module.

Code

function multichoice_get_report($nid, $vid, $rid) {
  $sql = "SELECT *,\n      COALESCE((SELECT 1\n        FROM {quiz_multichoice_user_answers} ua\n        WHERE question_nid = n.nid AND question_vid = n.vid AND result_id = %d AND ua.answer_id = ma.answer_id\n      ),0) AS user_answer,\n      (SELECT is_correct\n        FROM {quiz_node_results_answers}\n        WHERE question_nid = n.nid AND question_vid = n.vid AND result_id = %d\n      ) AS question_correct\n    FROM {node} n\n    LEFT JOIN {node_revisions} USING (nid, vid)\n    LEFT JOIN {quiz_multichoice_answers} ma USING (nid, vid)\n    WHERE n.nid = %d AND n.vid = %d";
  $result = db_query($sql, $rid, $rid, $nid, $vid);
  if ($result) {
    $question = new stdClass();
    while ($next_row = db_fetch_array($result)) {
      $row = $next_row;
      $question->answers[$row['answer_id']] = $row;
    }
    $question->title = $row['title'];
    $question->body = $row['body'];
    $question->teaser = $row['teaser'];
    $question->correct = $row['question_correct'];
    $question->type = $row['type'];
  }
  return $question;
}