You are here

function multichoice_calculate_results in Quiz 5.2

Same name and namespace in other branches
  1. 5 multichoice.module \multichoice_calculate_results()
  2. 6.6 question_types/multichoice/multichoice.module \multichoice_calculate_results()
  3. 6.2 multichoice.module \multichoice_calculate_results()
  4. 6.3 question_types/multichoice/multichoice.module \multichoice_calculate_results()
  5. 6.5 question_types/multichoice/multichoice.module \multichoice_calculate_results()

File

./multichoice.module, line 658
Multiple choice question type for the Quiz module.

Code

function multichoice_calculate_results($answers, $tried, $showpoints = FALSE, $showfeedback = FALSE) {

  // Create results table.
  $rows = array();
  $correctanswers = array();
  while (list($key, $answer) = each($answers)) {
    $cols = array();
    $cols[] = $answer['answer'];
    if ($showpoints) {
      $cols[] = $answer['is_correct'] == 0 ? theme_multichoice_unselected() : theme_multichoice_selected();
    }
    $selected = array_search($answer['answer_id'], $tried) !== FALSE;
    $cols[] = $selected ? theme_multichoice_selected() : theme_multichoice_unselected();
    if ($showfeedback) {
      $cols[] = $selected ? '<div class="quiz_answer_feedback">' . $answer['feedback'] . '</div>' : '';
    }
    $rows[] = $cols;
    if ($answer['is_correct'] > 0) {
      $correctanswers[] = $answer['answer_id'];
    }
  }
  if ($correctanswers === $tried) {
    $score = 1;
  }
  else {
    $score = 0;
  }
  return array(
    'score' => $score,
    'resultstable' => $rows,
  );
}