public function MultichoiceResponse::__construct in Quiz 7.4
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.5 question_types/multichoice/multichoice.classes.inc \MultichoiceResponse::__construct()
Constructor
Overrides QuizQuestionResponse::__construct
File
- question_types/
multichoice/ multichoice.classes.inc, line 813 - The main classes for the multichoice question type.
Class
- MultichoiceResponse
- Extension of QuizQuestionResponse
Code
public function __construct($result_id, stdClass $question_node, $tries = NULL) {
parent::__construct($result_id, $question_node, $tries);
$this->user_answer_ids = array();
// tries is the tries part of the post data
if (is_array($tries)) {
if (isset($tries['choice_order'])) {
$this->choice_order = $tries['choice_order'];
}
unset($tries['choice_order']);
if (isset($tries['answer']) && is_array($tries['answer'])) {
foreach ($tries['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($tries['answer'])) {
$this->user_answer_ids[] = $tries['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;
}
}
}