You are here

public function ShortAnswerResponse::__construct in Quiz 6.4

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.5 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse::__construct()
  4. 7.6 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse::__construct()
  5. 7 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse::__construct()
  6. 7.4 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse::__construct()
  7. 7.5 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse::__construct()

Constructor

Overrides QuizQuestionResponse::__construct

File

question_types/short_answer/short_answer.classes.inc, line 316
The main classes for the short answer question type.

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)) {
    $sql = "SELECT answer_id, answer, is_evaluated, score, question_vid, question_nid, result_id, answer_feedback\n        FROM {quiz_short_answer_user_answers}\n        WHERE question_nid = %d AND question_vid = %d AND result_id = %d";
    $r = db_fetch_object(db_query($sql, $question_node->nid, $question_node->vid, $result_id));
    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;
    }
  }
  else {
    if (is_array($answer)) {
      $this->answer = $answer['answer'];
    }
    else {
      $this->answer = $answer;
      $this->evaluated = $this->question->correct_answer_evaluation != ShortAnswerQuestion::ANSWER_MANUAL;
    }
  }
}