You are here

protected function MultichoiceResponse::orderAlternatives in Quiz 7.6

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

File

question_types/multichoice/multichoice.classes.inc, line 995
The main classes for the multichoice question type.

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_id = :result_id AND question_nid = :question_nid AND question_vid = :question_vid', array(
    ':result_id' => $this->result_id,
    ':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;
}