You are here

protected function MultichoiceResponse::orderAlternatives in Quiz 7.5

Same name and namespace in other branches
  1. 6.4 question_types/multichoice/multichoice.classes.inc \MultichoiceResponse::orderAlternatives()
  2. 7.6 question_types/multichoice/multichoice.classes.inc \MultichoiceResponse::orderAlternatives()
  3. 7 question_types/multichoice/multichoice.classes.inc \MultichoiceResponse::orderAlternatives()
  4. 7.4 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::getFeedbackValues in question_types/multichoice/multichoice.classes.inc
Implementation of getFeedbackValues().

File

question_types/multichoice/multichoice.classes.inc, line 993
Multichoice classes.

Class

MultichoiceResponse
Extension of QuizQuestionResponse.

Code

protected function orderAlternatives(array &$alternatives) {
  if (!$this->question->choice_random) {
    return;
  }
  $result = db_query('SELECT choice_order FROM {quiz_multichoice_user_answers}
            WHERE result_answer_id = :raid', array(
    ':raid' => $this->result_answer_id,
  ))
    ->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;
}