function multichoice_evaluate_question in Quiz 6.2
Same name and namespace in other branches
- 5.2 multichoice.module \multichoice_evaluate_question()
- 5 multichoice.module \multichoice_evaluate_question()
- 6.6 question_types/multichoice/multichoice.module \multichoice_evaluate_question()
- 6.3 question_types/multichoice/multichoice.module \multichoice_evaluate_question()
- 6.5 question_types/multichoice/multichoice.module \multichoice_evaluate_question()
Evaluate whether a question is correct.
Parameters
$question: Question node.
Return value
Array of results, in the form of: array( 'answers' => array of correct answer(s) 'tried' => array of selected answer(s) );
File
- ./
multichoice.module, line 665 - Multiple choice question type for the Quiz module.
Code
function multichoice_evaluate_question($question, $rid = null) {
$tries = is_array($_POST['tries']) ? $_POST['tries'] : array(
$_POST['tries'],
);
// Unset $_POST, otherwise it tries to use the previous answers on the next page...
unset($_POST['tries']);
// See the note in multichoice_store_answer. This is probably not needed.
//$numanswers = db_query("SELECT count(answer_id) FROM {quiz_multichoice_answers} WHERE nid = %d AND vid = %d AND is_correct = 1", $question->nid, $question->vid);
if ($rid && !empty($tries)) {
// Clear old answers
multichoice_clear_answer($question->nid, $question->vid, $rid);
// Enter new answers
foreach ($tries as $answer_id) {
multichoice_store_answer($question->nid, $question->vid, $rid, $answer_id);
}
}
// Return whether or not the user's response was correct.
return multichoice_calculate_result($question->nid, $question->vid, $tries);
}