You are here

public function MatchingResponse::__construct in Quiz 7.5

Same name and namespace in other branches
  1. 6.6 question_types/matching/matching.classes.inc \MatchingResponse::__construct()
  2. 6.3 question_types/matching/matching.classes.inc \MatchingResponse::__construct()
  3. 6.4 question_types/matching/matching.classes.inc \MatchingResponse::__construct()
  4. 6.5 question_types/matching/matching.classes.inc \MatchingResponse::__construct()
  5. 7.6 question_types/matching/matching.classes.inc \MatchingResponse::__construct()
  6. 7 question_types/matching/matching.classes.inc \MatchingResponse::__construct()
  7. 7.4 question_types/matching/matching.classes.inc \MatchingResponse::__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/matching/matching.classes.inc, line 433
Matching classes.

Class

MatchingResponse
Extension of QuizQuestionResponse

Code

public function __construct($result_id, stdClass $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_answer_id = :result_answer_id', array(
      ':nid' => $question_node->nid,
      ':vid' => $question_node->vid,
      ':result_answer_id' => $this->result_answer_id,
    ));
    $this->answer = array();
    while ($obj = $res
      ->fetch()) {
      $this->answer[$obj->match_id] = $obj->answer;
    }
  }
  $this->is_correct = $this
    ->isCorrect();
}