You are here

public function ShortAnswerResponse::__construct in Quiz 8.4

Constructor

Overrides QuizQuestionResponse::__construct

File

question_types/short_answer/lib/Drupal/short_answer/ShortAnswerResponse.php, line 90
The main classes for the short answer response.

Class

ShortAnswerResponse
Extension of QuizQuestionResponse

Namespace

Drupal\short_answer

Code

public function __construct($result_id, \Drupal\node\Entity\Node $question_node, $answer = NULL) {
  parent::__construct($result_id, $question_node, $answer);
  if (!isset($answer)) {
    $r = db_query('SELECT answer_id, answer, is_evaluated, score, question_vid, question_nid, result_id, answer_feedback
        FROM {quiz_short_answer_user_answers}
        WHERE question_nid = :qnid AND question_vid = :qvid AND result_id = :rid', array(
      ':qnid' => $question_node
        ->id(),
      ':qvid' => $question_node
        ->getRevisionId(),
      ':rid' => $result_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;
    }
  }
  else {
    if (is_array($answer)) {
      $this->answer = $answer['answer'];
    }
    else {
      $this->answer = $answer;
      $this->evaluated = $this->question->correct_answer_evaluation != ShortAnswerQuestion::ANSWER_MANUAL;
    }
  }
}