You are here

function quiz_report_form in Quiz 7.6

Same name and namespace in other branches
  1. 8.4 quiz.pages.inc \quiz_report_form()
  2. 6.4 quiz.pages.inc \quiz_report_form()
  3. 7 quiz.pages.inc \quiz_report_form()
  4. 7.4 quiz.pages.inc \quiz_report_form()

Form for showing feedback, and for editing the feedback if necessary...

Parameters

$form_state: FAPI form state(array)

$questions: array of questions to inclide in the report

Return value

$form FAPI form array

2 string references to 'quiz_report_form'
quiz_question_feedback in question_types/quiz_question/quiz_question.module
Return a form with question feedback.
theme_quiz_result in ./quiz.pages.inc
Theme the result page.

File

./quiz.pages.inc, line 57
User pages.

Code

function quiz_report_form($form, $form_state, $questions, $result_id) {
  $form = array();

  // The submit button is only shown if one or more of the questions has input elements
  $show_submit = FALSE;
  foreach ($questions as $question) {
    $module = quiz_question_module_for_type($question->type);
    if (!$module) {
      return array();
    }
    $function = $module . '_report_form';
    $form_to_add = $function($question, $result_id);
    if (isset($form_to_add['submit'])) {
      $show_submit = TRUE;
    }
    if (!isset($form_to_add['#no_report'])) {
      $form_to_add['#element_validate'][] = 'quiz_report_form_element_validate';
      $form[] = $form_to_add;
    }
  }
  $form['#tree'] = TRUE;
  $form['navigation']['#type'] = 'actions';
  if ($show_submit) {
    $form['navigation']['submit'] = array(
      '#type' => 'submit',
      '#submit' => array(
        'quiz_report_form_submit',
      ),
      '#value' => t('Save score'),
    );
  }
  if (arg(4) == 'feedback') {

    // @todo figure something better than args.
    $quiz = node_load(arg(1));
    if (empty($_SESSION['quiz'][$quiz->nid])) {

      // Quiz is done.
      $form['navigation']['finish'] = array(
        '#type' => 'submit',
        '#submit' => array(
          'quiz_take_question_feedback_end_submit',
        ),
        '#value' => t('Finish'),
      );
    }
    else {
      $form['navigation']['next'] = array(
        '#type' => 'submit',
        '#submit' => array(
          'quiz_take_question_feedback_submit',
        ),
        '#value' => t('Next question'),
      );
    }
  }
  return $form;
}