You are here

public function MatchingResponse::__construct in Quiz 8.4

Constructor

Overrides QuizQuestionResponse::__construct

File

question_types/matching/lib/Drupal/matching/MatchingResponse.php, line 19

Class

MatchingResponse
Extension of QuizQuestionResponse

Namespace

Drupal\matching

Code

public function __construct($result_id, $question_node, $answer = NULL) {
  parent::__construct($result_id, $question_node, $answer);
  if (!isset($answer)) {
    $res = db_query('SELECT ua.answer, score, ua.match_id FROM {quiz_matching_user_answers} ua
              JOIN {quiz_matching_node} n ON n.match_id = ua.match_id
              WHERE n.nid = :nid AND n.vid = :vid AND ua.result_id = :result_id', array(
      ':nid' => $question_node
        ->id(),
      ':vid' => $question_node
        ->getRevisionId(),
      ':result_id' => $result_id,
    ));
    $this->answer = array();
    while ($obj = $res
      ->fetch()) {
      $this->answer[$obj->match_id] = $obj->answer;
    }
  }
  $this->is_correct = $this
    ->isCorrect();
}