private function MultichoiceResponse::orderAlternatives in Quiz 8.4
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/ lib/ Drupal/ multichoice/ MultichoiceResponse.php - Implementation of getReportFormResponse
File
- question_types/
multichoice/ lib/ Drupal/ multichoice/ MultichoiceResponse.php, line 255
Class
- MultichoiceResponse
- Extension of QuizQuestionResponse
Namespace
Drupal\multichoiceCode
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
->id(),
':question_vid' => $this->question
->getRevisionId(),
))
->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;
}