You are here

public function ShortAnswerResponse::__construct in Quiz 7.5

Same name and namespace in other branches
  1. 6.6 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse::__construct()
  2. 6.3 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse::__construct()
  3. 6.4 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse::__construct()
  4. 6.5 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse::__construct()
  5. 7.6 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse::__construct()
  6. 7 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse::__construct()
  7. 7.4 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse::__construct()

Constructor.

Parameters

int $result_id: The result ID for the user's result set. There is one result ID per time the user takes a quiz.

stdClass $question_node: The question node.

mixed $answer: The answer (dependent on question type).

Overrides QuizQuestionResponse::__construct

File

question_types/short_answer/short_answer.classes.inc, line 290
Short answer classes.

Class

ShortAnswerResponse
Extension of QuizQuestionResponse.

Code

public function __construct($result_id, stdClass $question_node, $answer = NULL) {
  parent::__construct($result_id, $question_node, $answer);
  if (!isset($answer)) {
    $r = db_query('SELECT *
        FROM {quiz_short_answer_user_answers}
        WHERE result_answer_id = :raid', array(
      ':raid' => $this->result_answer_id,
    ))
      ->fetch();
    if (!empty($r)) {
      $this->answer = $r->answer;
      $this->score = $r->score;
      $this->evaluated = $r->is_evaluated;
      $this->answer_id = $r->answer_id;
      $this->answer_feedback = $r->answer_feedback;
      $this->answer_feedback_format = $r->answer_feedback_format;
    }
  }
  else {
    if (is_array($answer)) {
      $this->answer = $answer['answer'];
    }
    else {
      $this->answer = $answer;
      $this->evaluated = $this->question->correct_answer_evaluation != ShortAnswerQuestion::ANSWER_MANUAL;
    }
  }
}