public function MultichoiceResponse::__construct in Quiz 7.5
Same name and namespace in other branches
- 6.4 question_types/multichoice/multichoice.classes.inc \MultichoiceResponse::__construct()
- 7.6 question_types/multichoice/multichoice.classes.inc \MultichoiceResponse::__construct()
- 7 question_types/multichoice/multichoice.classes.inc \MultichoiceResponse::__construct()
- 7.4 question_types/multichoice/multichoice.classes.inc \MultichoiceResponse::__construct()
Constructor.
Parameters
int $result_id: The result ID for the user's result set. There is one result ID per time the user takes a quiz.
stdClass $question_node: The question node.
mixed $values: Array with values.
Overrides QuizQuestionResponse::__construct
File
- question_types/
multichoice/ multichoice.classes.inc, line 816 - Multichoice classes.
Class
- MultichoiceResponse
- Extension of QuizQuestionResponse.
Code
public function __construct($result_id, stdClass $question_node, $values = NULL) {
parent::__construct($result_id, $question_node, isset($values['user_answer']) ? $values['user_answer'] : NULL);
$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;
// @todo: Stop using user_answer_ids and only use answer instead...
$this->answer = $this->user_answer_ids;
}
}
elseif (isset($values['user_answer'])) {
$this->user_answer_ids[] = $values['user_answer'];
}
}
elseif (isset($this->result_answer_id)) {
$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_answer_id = :raid', array(
':raid' => $this->result_answer_id,
));
while ($res_o = $res
->fetch()) {
$this->user_answer_ids[] = $res_o->answer_id;
}
}
}