You are here

public function LongAnswerResponse::__construct in OG Quiz 7

Constructor

Overrides QuizQuestionResponse::__construct

File

includes/og_long_answer.php, line 252
Long answer classes.

Class

LongAnswerResponse
Extension of QuizQuestionResponse

Code

public function __construct($result_id, stdClass $question_node, $answer = NULL) {
  parent::__construct($result_id, $question_node, $answer);
  if (!isset($answer)) {

    // Question has been answered allready. We fetch the answer data from the database.
    $r = db_query('SELECT answer_id, answer, is_evaluated, score, question_vid, question_nid, result_id, answer_feedback, answer_feedback_format
        FROM {quiz_long_answer_user_answers}
        WHERE question_nid = :qnid AND question_vid = :qvid AND result_id = :rid', array(
      ':qnid' => $question_node->nid,
      ':qvid' => $question_node->vid,
      ':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;
      $this->answer_feedback_format = $r->answer_feedback_format;
    }
  }
  else {
    $this->answer = $answer;
    $this->evaluated = FALSE;
  }
}