function multichoice_calculate_results in Quiz 5
Same name and namespace in other branches
- 5.2 multichoice.module \multichoice_calculate_results()
- 6.6 question_types/multichoice/multichoice.module \multichoice_calculate_results()
- 6.2 multichoice.module \multichoice_calculate_results()
- 6.3 question_types/multichoice/multichoice.module \multichoice_calculate_results()
- 6.5 question_types/multichoice/multichoice.module \multichoice_calculate_results()
File
- ./
multichoice.module, line 427 - Multiple choice question type for 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['points'] == 0 ? theme_multichoice_unselected() : theme_multichoice_selected();
}
$selected = array_search($answer['aid'], $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['points'] > 0) {
$correctanswers[] = $answer['aid'];
}
}
if ($correctanswers === $tried) {
$score = 1;
}
else {
$score = 0;
}
return array(
'score' => $score,
'resultstable' => $rows,
);
}