You are here

function multichoice_evaluate_question in Quiz 5.2

Same name and namespace in other branches
  1. 5 multichoice.module \multichoice_evaluate_question()
  2. 6.6 question_types/multichoice/multichoice.module \multichoice_evaluate_question()
  3. 6.2 multichoice.module \multichoice_evaluate_question()
  4. 6.3 question_types/multichoice/multichoice.module \multichoice_evaluate_question()
  5. 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 593
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']);
  $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)) {
    foreach ($tries as $answer_id) {
      multichoice_store_answer($question->nid, $question->vid, $rid, $answer_id, $numanswers);
    }
  }

  // Return whether or not the user's response was correct.
  return multichoice_calculate_result($question->nid, $question->vid, $tries);
}