You are here

public function ShortAnswerResponse::__construct in Quiz 6.3

Same name and namespace in other branches
  1. 6.6 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse::__construct()
  2. 6.4 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse::__construct()
  3. 6.5 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse::__construct()
  4. 7.6 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse::__construct()
  5. 7 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse::__construct()
  6. 7.4 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse::__construct()
  7. 7.5 question_types/short_answer/short_answer.classes.inc \ShortAnswerResponse::__construct()

Create a new user response.

Parameters

$rid: The result ID for the user's result set. There is one result ID per time the user takes a quiz.

$question: The question node.

$answer: The answer (dependent on question type).

Overrides QuizQuestionResponse::__construct

File

question_types/short_answer/short_answer.classes.inc, line 285
The main classes for the short answer question type.

Class

ShortAnswerResponse
The short answer question response class.

Code

public function __construct($rid, $question, $answer = NULL) {
  $this->rid = $rid;
  $this->question = $question;
  if (!isset($answer)) {
    $sql = "SELECT answer_id, answer, is_evaluated, score, question_vid, question_nid, result_id\n        FROM {quiz_short_answer_user_answers}\n        WHERE question_nid = %d AND question_vid = %d AND result_id = %d";
    $r = db_fetch_object(db_query($sql, $question->nid, $question->vid, $rid));
    if (!empty($r)) {
      $this->answer = $r->answer;
      $this->score = $r->score;
      $this->evaluated = $r->is_evaluated;
      $this->answer_id = $r->answer_id;
    }
  }
  else {
    $this->answer = $answer;
  }
}