You are here

function quiz_questions_form in Quiz 7.5

Same name and namespace in other branches
  1. 8.4 quiz.admin.inc \quiz_questions_form()
  2. 5.2 quiz.module \quiz_questions_form()
  3. 5 quiz.module \quiz_questions_form()
  4. 6.6 quiz.admin.inc \quiz_questions_form()
  5. 6.2 quiz.admin.inc \quiz_questions_form()
  6. 6.3 quiz.admin.inc \quiz_questions_form()
  7. 6.4 quiz.admin.inc \quiz_questions_form()
  8. 6.5 quiz.admin.inc \quiz_questions_form()
  9. 7.6 quiz.admin.inc \quiz_questions_form()
  10. 7 quiz.admin.inc \quiz_questions_form()
  11. 7.4 quiz.admin.inc \quiz_questions_form()

Handles "manage questions" tab.

Displays form which allows questions to be assigned to the given quiz.

This function is not used if the question assignment type "categorized random questions" is chosen.

Parameters

$form_state: The form state variable

$quiz: The quiz node.

Return value

HTML output to create page.

1 string reference to 'quiz_questions_form'
quiz_questions_page in ./quiz.admin.inc
Creates a form for quiz questions.

File

./quiz.admin.inc, line 676
Administrator interface for Quiz module.

Code

function quiz_questions_form($form, $form_state, $quiz) {
  $types = quiz_get_question_types();
  _quiz_add_fields_for_creating_questions($form, $types, $quiz);

  // Display questions in this quiz.
  $form['question_list'] = array(
    '#type' => 'fieldset',
    '#title' => t('Questions in this @quiz', array(
      '@quiz' => QUIZ_NAME,
    )),
    '#theme' => 'question_selection_table',
    '#collapsible' => TRUE,
    '#attributes' => array(
      'id' => 'mq-fieldset',
    ),
    'question_status' => array(
      '#tree' => TRUE,
    ),
  );

  // Add randomization settings if this quiz allows randomized questions.
  _quiz_add_fields_for_random_quiz($form, $quiz);
  $include_random = $quiz->randomization == 2;

  // @todo deal with $include_random.
  $questions = quiz_get_questions($quiz->nid, $quiz->vid);
  if (empty($questions)) {
    $form['question_list']['no_questions'] = array(
      '#markup' => '<div id = "no-questions">' . t('There are currently no questions in this @quiz. Assign existing questions by using the question browser below. You can also use the links above to create new questions.', array(
        '@quiz' => QUIZ_NAME,
      )) . '</div>',
    );
  }

  // We add the questions to the form array.
  _quiz_add_questions_to_form($form, $questions, $quiz, $types);

  // Show the number of questions in the table header.
  $always_count = isset($form['question_list']['titles']) ? count($form['question_list']['titles']) : 0;
  $form['question_list']['#title'] .= ' (' . $always_count . ')';

  // Give the user the option to create a new revision of the quiz.
  _quiz_add_revision_checkbox($form, $quiz);

  // Timestamp is needed to avoid multiple users editing the same quiz at the
  // same time.
  $form['timestamp'] = array(
    '#type' => 'hidden',
    '#default_value' => REQUEST_TIME,
  );
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
    '#submit' => array(
      'quiz_questions_form_submit',
    ),
  );
  return $form;
}