function _quiz_show_finish_button in Quiz 7.5
Same name and namespace in other branches
- 7.6 quiz.module \_quiz_show_finish_button()
Show the finish button?
1 call to _quiz_show_finish_button()
- quiz_question_answering_form in question_types/
quiz_question/ quiz_question.module - Get the form to show to the quiz taker.
File
- ./
quiz.module, line 3356 - quiz.module Main file for the Quiz module.
Code
function _quiz_show_finish_button($quiz) {
$quiz_result = quiz_result_load($_SESSION['quiz'][$quiz->nid]['result_id']);
$current = $_SESSION['quiz'][$quiz->nid]['current'];
$layout = $quiz_result
->getLayout();
// Get a list of all the node types in bulk, because the question type isn't
// provided by getLayout(). We don't use to use VID here, since types never
// change.
$nids = array();
foreach ($layout as $idx => $question) {
$nids[] = $question['nid'];
}
$question_node_types = db_select('node', 'n')
->fields('n', array(
'nid',
'type',
))
->condition('nid', $nids)
->execute()
->fetchAllAssoc('nid');
foreach ($layout as $idx => $question) {
if ($question_node_types[$question['nid']]->type == 'quiz_page') {
if ($current == $idx) {
// Found a page that we are on.
$in_page = TRUE;
$last_page = TRUE;
}
else {
// Found a quiz page that we are not on.
$last_page = FALSE;
}
}
elseif (empty($question['qnr_pid'])) {
// A question without a parent showed up.
$in_page = FALSE;
$last_page = FALSE;
}
}
return $last_page || !isset($layout[$_SESSION['quiz'][$quiz->nid]['current'] + 1]);
}