function quiz_question_answering_form in Quiz 7.6
Same name and namespace in other branches
- 8.4 question_types/quiz_question/quiz_question.module \quiz_question_answering_form()
- 6.4 question_types/quiz_question/quiz_question.module \quiz_question_answering_form()
- 7 question_types/quiz_question/quiz_question.module \quiz_question_answering_form()
- 7.4 question_types/quiz_question/quiz_question.module \quiz_question_answering_form()
- 7.5 question_types/quiz_question/quiz_question.module \quiz_question_answering_form()
Get the form to show to the quiz taker.
Parameters
$nodes: A list of question nodes to get answers from.
$result_id: The result ID for this attempt.
1 string reference to 'quiz_question_answering_form'
- quiz_take_question in ./
quiz.module - Take a quiz questions.
File
- question_types/
quiz_question/ quiz_question.module, line 145 - Quiz Question module. This module provides the basic facilities for adding quiz question types to a quiz.
Code
function quiz_question_answering_form($form, $form_state, $nodes, $result_id) {
$quiz_result = quiz_result_load($result_id);
$quiz = node_load($quiz_result->nid, $quiz_result->vid);
if (!is_array($nodes)) {
// One single question (or page?)
if ($nodes->type == 'quiz_page') {
foreach ($quiz_result->layout as $question) {
if ($question['nid'] == $nodes->nid) {
// Found a page
$nodes = array(
node_load($nodes->nid),
);
foreach ($quiz_result->layout as $question2) {
if ($question2['qnr_pid'] == $question['qnr_id']) {
// This question belongs in the requested page.
$nodes[] = node_load($question2['nid']);
}
}
break;
}
}
}
else {
$nodes = array(
$nodes->nid => $nodes,
);
}
}
$form['#attributes']['class'] = array(
'answering-form',
);
$form['#tree'] = TRUE;
foreach ($nodes as $node) {
$question = _quiz_question_get_instance($node);
$class = drupal_html_class('quiz-question-' . $node->type);
// Element for a single question
$element = $question
->getAnsweringForm($form_state, $result_id);
node_build_content($node, 'question');
unset($node->content['answers']);
unset($node->content['links']);
$form['question'][$node->nid] = array(
'#attributes' => array(
'class' => array(
$class,
),
),
'#type' => 'container',
'header' => $node->content,
'answer' => $element,
);
if (!$quiz->allow_change) {
if (quiz_result_is_question_answered($quiz_result, $node)) {
// This question was already answered, and not skipped.
$form['question'][$node->nid]['#disabled'] = TRUE;
}
}
if ($quiz->mark_doubtful) {
$form['question'][$node->nid]['is_doubtful'] = array(
'#type' => 'checkbox',
'#title' => t('Doubtful?'),
);
$form['question'][$node->nid]['is_doubtful']['#default_value'] = db_query('SELECT is_doubtful FROM {quiz_node_results_answers} WHERE result_id = :result_id AND question_nid = :question_nid AND question_vid = :question_vid', array(
':result_id' => $quiz_result->result_id,
':question_nid' => $node->nid,
':question_vid' => $node->vid,
))
->fetchField();
}
}
$is_last = _quiz_show_finish_button($quiz);
$form['navigation']['#type'] = 'actions';
$form['navigation']['#theme'] = 'quiz_question_navigation_form';
if (!empty($quiz->backwards_navigation) && arg(3) != 1) {
// Backwards navigation enabled, and we are looking at not the first
// question. @todo detect when on the first page.
$form['navigation']['back'] = array(
'#weight' => 10,
'#type' => 'submit',
'#value' => t('Back'),
'#submit' => array(
'quiz_question_answering_form_submit_back',
),
'#limit_validation_errors' => array(),
);
if ($is_last) {
$form['navigation']['#last'] = TRUE;
$form['navigation']['last_text'] = array(
'#weight' => 0,
'#markup' => '<p><em>' . t('This is the last question. Press Finish to deliver your answers') . '</em></p>',
);
}
}
$form['navigation']['submit'] = array(
'#weight' => 30,
'#type' => 'submit',
'#value' => $is_last ? t('Finish') : t('Next'),
);
if ($is_last && $quiz->backwards_navigation && !$quiz->repeat_until_correct) {
// Display a confirmation dialogue if this is the last question and a user
// is able to navigate backwards but not forced to answer correctly.
$form['#attributes']['class'][] = 'quiz-answer-confirm';
$form['#attributes']['data-confirm-message'] = t("By proceeding you won't be able to go back and edit your answers.");
$form['#attached'] = array(
'js' => array(
drupal_get_path('module', 'quiz') . '/theme/quiz_confirm.js',
),
);
}
if ($quiz->allow_skipping) {
$form['navigation']['skip'] = array(
'#weight' => 20,
'#type' => 'submit',
'#value' => $is_last ? t('Leave blank and finish') : t('Leave blank'),
'#access' => $node->type == 'quiz_directions' ? FALSE : TRUE,
'#submit' => array(
'quiz_question_answering_form_submit_blank',
),
'#limit_validation_errors' => array(),
);
}
return $form;
}