Posted by mediumgrade on June 7, 2011 at 10:37pm
Hello, I am wondering if the following is possible:
I would like to create my quizzes such that a user is able to skipped through questions, but is forced to answer them all before finishing. In such a scenario, the user would likely receive some sort of error if they tried to Finish the exam without going back to answer their skipped questions. Currently, skipping automatically allows the user to leave questions blank. Is what I am asking for possible? I have tried looking at the various hooks and I am not sure where this kind of validation would go, or even how to really check for it.
A little help? Thanks!
Comments
See function quiz_take_quiz()
See
function quiz_take_quiz()in quiz.module. Code block around line number 1900 handles this logic, snip of the code is below// Check for a skip.
if (($POST['op'] == t('Skip') || $_POST['op'] == t('Skip and finish')) && $allow_skipping) {
if (!isset($_SESSION['quiz' . $quiz->nid]['result_id'])) {
$SESSION['quiz' . $quiz->nid]['result_id'] = quiz_create_rid($quiz);
}
$q_passed_validation = TRUE;
// Advance the question.
if (!$jumping) {
$SESSION['quiz' . $quiz->nid]['previous_quiz_questions'][] = $SESSION['quiz' . $quiz->nid]['quiz_questions'][0];
// Load the last asked question.
$former_question_array = array_shift($SESSION['quiz' . $quiz->nid]['quiz_questions']);
$former_question = node_load($former_question_array['nid'], $former_question_array['vid']);
}
// Call hook_skip_question().
$module = quiz_question_module_for_type($former_question->type);
if (!$module) {
return array('body' => array('#value' => ' '));
}
$result = module_invoke($module, 'skip_question', $former_question, $SESSION['quiz' . $quiz->nid]['result_id']);
// Store that the question was skipped:
quiz_store_question_result($quiz, $result, array('set_msg' => TRUE, 'question_data' => $former_question_array));
}