You are here

function quiz_question_evaluate_question in Quiz 7

Same name and namespace in other branches
  1. 8.4 question_types/quiz_question/quiz_question.module \quiz_question_evaluate_question()
  2. 6.6 question_types/quiz_question/quiz_question.module \quiz_question_evaluate_question()
  3. 6.3 question_types/quiz_question/quiz_question.module \quiz_question_evaluate_question()
  4. 6.4 question_types/quiz_question/quiz_question.module \quiz_question_evaluate_question()
  5. 6.5 question_types/quiz_question/quiz_question.module \quiz_question_evaluate_question()
  6. 7.4 question_types/quiz_question/quiz_question.module \quiz_question_evaluate_question()

Implements hook_evaluate_question().

Parameters

$question: The question node

$result_id: Result id

$answer: The users answer to the question

Return value

Object with nid, vid, rid, score, is_correct flags set.

File

question_types/quiz_question/quiz_question.module, line 222
Quiz Question module. This module provides the basic facilities for adding quiz question types to a quiz.

Code

function quiz_question_evaluate_question($question, $result_id, $answer = NULL) {
  if (empty($answer) && !empty($_POST['tries'])) {

    // FIXME this use of POST array is hacky. We will try to use FAPI mor accurately in Quiz 5.x
    $answer = $_POST['tries'];
  }
  unset($_POST['tries']);
  $response = _quiz_question_response_get_instance($result_id, $question, $answer);

  // If a result_id is set, we are taking a quiz.
  if ($result_id && isset($answer)) {

    // We don't know whether or not the user has gone back a question. However,
    // we do know that deleting a question for this result set should be safe in
    // the case where the user has not gone back (since there will be no entries
    // to delete). So we always run the delete.
    $response
      ->delete();
    $response
      ->saveResult();
  }

  // Convert the response to a bare object.
  return $response
    ->toBareObject();
}