You are here

function multichoice_evaluate_question in Quiz 5

Same name and namespace in other branches
  1. 5.2 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 question is correct

Parameters

$nid: Question Node ID

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 379
Multiple choice question type for quiz module

Code

function multichoice_evaluate_question($nid) {
  $question = node_load($nid);
  $results = array();
  if (isset($_POST['tries'])) {
    if (is_array($_POST['tries'])) {

      // Multi-answer question
      while (list($key, $try) = each($_POST['tries'])) {
        $results['answers'] = $question->answers;
        $results['tried'][] = $question->answers[$try]['aid'];
      }
    }
    else {

      // Single-answer question
      $results['answers'] = $question->answers;
      $results['tried'][] = $question->answers[$_POST['tries']]['aid'];
    }
  }

  //Unset $_POST, otherwise it tries to use the previous answers on the next page...
  unset($_POST['tries']);

  //Return the result
  return $results;
}