private function MultichoiceResponse::orderAlternatives in Quiz 7.4
Same name and namespace in other branches
- 6.4 question_types/multichoice/multichoice.classes.inc \MultichoiceResponse::orderAlternatives()
- 7.6 question_types/multichoice/multichoice.classes.inc \MultichoiceResponse::orderAlternatives()
- 7 question_types/multichoice/multichoice.classes.inc \MultichoiceResponse::orderAlternatives()
- 7.5 question_types/multichoice/multichoice.classes.inc \MultichoiceResponse::orderAlternatives()
Order the alternatives according to the choice order stored in the database
Parameters
array $alternatives: The alternatives to be ordered
1 call to MultichoiceResponse::orderAlternatives()
- MultichoiceResponse::getReportFormResponse in question_types/
multichoice/ multichoice.classes.inc - Implementation of getReportFormResponse
File
- question_types/
multichoice/ multichoice.classes.inc, line 1044 - The main classes for the multichoice question type.
Class
- MultichoiceResponse
- Extension of QuizQuestionResponse
Code
private function orderAlternatives(array &$alternatives) {
if (!$this->question->choice_random) {
return;
}
$result = db_query('SELECT choice_order FROM {quiz_multichoice_user_answers}
WHERE result_id = :result_id AND question_nid = :question_nid AND question_vid = :question_vid', array(
':result_id' => $this->rid,
':question_nid' => $this->question->nid,
':question_vid' => $this->question->vid,
))
->fetchField();
if (!$result) {
return;
}
$order = explode(',', $result);
$newAlternatives = array();
foreach ($order as $value) {
foreach ($alternatives as $alternative) {
if ($alternative['id'] == $value) {
$newAlternatives[] = $alternative;
break;
}
}
}
$alternatives = $newAlternatives;
}