You are here

public function MultichoiceResponse::__construct in Quiz 7.6

Same name and namespace in other branches
  1. 6.4 question_types/multichoice/multichoice.classes.inc \MultichoiceResponse::__construct()
  2. 7 question_types/multichoice/multichoice.classes.inc \MultichoiceResponse::__construct()
  3. 7.4 question_types/multichoice/multichoice.classes.inc \MultichoiceResponse::__construct()
  4. 7.5 question_types/multichoice/multichoice.classes.inc \MultichoiceResponse::__construct()

Constructor.

Parameters

type $result_id:

stdClass $question_node:

type $values: Form state values.

Overrides QuizQuestionResponse::__construct

File

question_types/multichoice/multichoice.classes.inc, line 815
The main classes for the multichoice question type.

Class

MultichoiceResponse
Extension of QuizQuestionResponse

Code

public function __construct($result_id, stdClass $question_node, $values = NULL) {
  parent::__construct($result_id, $question_node, $values['user_answer']);
  $this->user_answer_ids = array();

  // tries is the tries part of the post data
  if (isset($values['user_answer'])) {
    if (!is_array($values['user_answer'])) {

      // Account for single-select
      $values['user_answer'] = array(
        $values['user_answer'],
      );
    }
    if (isset($values['choice_order'])) {
      $this->choice_order = $values['choice_order'];
    }
    unset($values['choice_order']);
    if (isset($values['user_answer']) && is_array($values['user_answer'])) {
      foreach ($values['user_answer'] as $answer_id) {
        $this->user_answer_ids[] = $answer_id;
        $this->answer = $this->user_answer_ids;

        //@todo: Stop using user_answer_ids and only use answer instead...
      }
    }
    elseif (isset($values['user_answer'])) {
      $this->user_answer_ids[] = $values['user_answer'];
    }
  }
  else {
    $res = db_query('SELECT answer_id FROM {quiz_multichoice_user_answers} ua
              LEFT OUTER JOIN {quiz_multichoice_user_answer_multi} uam ON(uam.user_answer_id = ua.id)
              WHERE ua.result_id = :result_id AND ua.question_nid = :question_nid AND ua.question_vid = :question_vid', array(
      ':result_id' => $result_id,
      ':question_nid' => $this->question->nid,
      ':question_vid' => $this->question->vid,
    ));
    while ($res_o = $res
      ->fetch()) {
      $this->user_answer_ids[] = $res_o->answer_id;
    }
  }
}