You are here

function multichoice_calculate_result in Quiz 6.2

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

Check if the user selected all the correct answers for this question.

Parameters

$answers: Array of answers.

$tried: Array of answer id's the user selected.

Return value

TRUE if the user selected exactly all of the correct answers, otherwise FALSE.

1 call to multichoice_calculate_result()
multichoice_evaluate_question in ./multichoice.module
Evaluate whether a question is correct.

File

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

Code

function multichoice_calculate_result($nid, $vid, $tried) {
  $correct_answers = array();
  $answers = db_query("SELECT answer_id FROM {quiz_multichoice_answers} WHERE nid = %d AND vid = %d AND is_correct = 1", $nid, $vid);
  while ($answer = db_fetch_array($answers)) {
    $correct_answers[] = $answer['answer_id'];
  }
  if (empty($correct_answers)) {

    // We are in a personality test. Just return TRUE.
    return TRUE;
  }
  return array_values($correct_answers) === array_values($tried);
}