You are here

public function ChoiceResponse::__construct in Quiz 6.6

Constructor

Parameters

$rid - response_id:

$question - as an object:

$answer - answer_id:

File

question_types/choice/choice.classes.inc, line 578
The main classes for the choice question type.

Class

ChoiceResponse
The short answer question response class.

Code

public function __construct($rid, $question, $tries = NULL) {
  $this->rid = $rid;
  $this->question = $question;
  $this->user_answer_ids = array();
  $this->choice_order = $tries['choice_order'];
  unset($tries['choice_order']);
  if (is_array($tries['answer'])) {
    foreach ($tries['answer'] as $answer_id) {
      $this->user_answer_ids[] = $answer_id;
    }
  }
  elseif (isset($tries['answer'])) {
    $this->user_answer_ids[] = $tries['answer'];
  }
  else {
    $sql = 'SELECT answer_id
              FROM {quiz_choice_user_answer_multi} uam
              JOIN {quiz_choice_user_answers} ua ON(uam.user_answer_id = ua.id)
              WHERE ua.result_id = %d AND ua.nid = %d AND ua.vid = %d';
    $res = db_query($sql, $rid, $this->question->nid, $this->question->vid);
    while ($res_o = db_fetch_object($res)) {
      $this->user_answer_ids[] = $res_o->answer_id;
    }
  }
}