I am working on a quiz with categorized random questions and with some specific requirements.
For passing a training module one question from each category must be correct, but one is allowed fail any other question from the category. So failing the original question, another question is asked instead.
I manage this now somehow with 6.x-4.3 modifying the quiz_take_quiz function (from line 1783):
if ($quiz->repeat_until_correct && $_POST['op'] != t('Back') && $q_passed_validation === TRUE) {
// If the question was answered incorrectly, repeat it
if ($result && !$result->is_correct && $result->is_evaluated) {
$last_q = array_pop($_SESSION['quiz_' . $quiz->nid]['previous_quiz_questions']);
array_unshift($_SESSION['quiz_' . $quiz->nid]['quiz_questions'], $last_q);
// Are there alternative questions?
if ($quiz->randomization == 3) {
// We don't want the same question, but we also don't want to en up in an endless loop
if (taxonomy_term_count_nodes($last_q['tid'])>1) { //TODO: check node type also?
$different=FALSE;
while (!$different) {
$alternative_questions = quiz_build_question_list($quiz); // using existing function known to work
for ($i=0;$i<count($alternative_questions);$i++) {
if ($last_q['nid'] != $alternative_questions[$i]['nid']) {
if ($last_q['number'] == $alternative_questions[$i]['number']) {
$last_q=$alternative_questions[$i];
$_SESSION['quiz_' . $quiz->nid]['quiz_questions'][0]=$alternative_questions[$i];
$different=TRUE;
}
}
}
}
// we might want to dismiss the failed question result somehow, but then again, as finishing
// at all requires a correct answer for each term, 1% pass rate suffices for pass/not pass
}
drupal_set_message(t('The answer was incorrect. Please try another question from the same topic.'), 'error');
// We don't want to suppress feedback, as we changed the question
} else {
// The standard stuff
drupal_set_message(t('The answer was incorrect. Please try again.'), 'error');
unset($_SESSION['quiz_'. $quiz->nid]['feedback']);
}
}
}
It would be rather nice to have this as an option like "repeat category until correct". It would probably make it a bit easier to maintain and update.
Comments
Comment #1
ezraw commentedComment #2
smustgrave commentedWith D7 approaching EOL soon I've started the process of triaging the D7queue here. Since there hasn't been any movement on this going to close out.