You are here

public function ClozeResponse::__construct in Cloze 7

Same name and namespace in other branches
  1. 6 cloze.classes.inc \ClozeResponse::__construct()

Constructor

File

./cloze.classes.inc, line 276
The main classes for the cloze question type. These inherit or implement code found in quiz_question.classes.inc.

Class

ClozeResponse
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 answer_id, answer, score, question_vid, question_nid, result_id FROM {quiz_cloze_user_answers} WHERE question_nid = :question_nid AND question_vid = :question_vid AND result_id = :result_id", array(
      ':question_nid' => $question_node->nid,
      ':question_vid' => $question_node->vid,
      ':result_id' => $result_id,
    ))
      ->fetch();
    if (!empty($r)) {
      $this->answer = unserialize($r->answer);
      $this->score = $r->score;
      $this->answer_id = $r->answer_id;
    }
  }
  else {
    $this->answer = $answer;
  }
}