You are here

function quiz_questions_form in Quiz 6.2

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.3 quiz.admin.inc \quiz_questions_form()
  6. 6.4 quiz.admin.inc \quiz_questions_form()
  7. 6.5 quiz.admin.inc \quiz_questions_form()
  8. 7.6 quiz.admin.inc \quiz_questions_form()
  9. 7 quiz.admin.inc \quiz_questions_form()
  10. 7.4 quiz.admin.inc \quiz_questions_form()
  11. 7.5 quiz.admin.inc \quiz_questions_form()

Handles "manage questions" tab.

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

Return value

HTML output to create page.

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

File

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

Code

function quiz_questions_form($context, $quiz) {

  // Set page title.
  drupal_set_title(check_plain($quiz->title));

  // Display links to create other questions.
  $form['additional_questions'] = array(
    '#type' => 'fieldset',
    '#title' => t('Create additional questions'),
    '#theme' => 'additional_questions',
  );
  foreach (_quiz_get_question_types() as $type) {
    $form['additional_questions'][$type] = array(
      '#type' => 'markup',
      '#value' => l(t($type), 'node/add/' . $type . '/' . $quiz->nid, array(
        'title' => t('Go to ' . $type . ' administration'),
      )) . ' ',
    );
  }

  // Display questions 'always' on this quiz.
  $form['filtered_question_list_always'] = array(
    '#type' => 'fieldset',
    '#title' => t("Questions 'always' on this quiz"),
    '#theme' => 'quiz_filtered_questions',
    '#collapsible' => TRUE,
    'question_status' => array(
      '#tree' => TRUE,
    ),
  );
  $form['filtered_random_question_list']['number_of_random_questions'] = array(
    '#type' => 'textfield',
    '#title' => t('Number of questions to randomize'),
    '#size' => 3,
    '#default_value' => $quiz->number_of_random_questions,
    '#description' => t('The number of randomly selected questions to assign to this quiz.'),
  );
  if (function_exists('taxonomy_get_vocabularies')) {
    $form['filtered_random_question_list']['random_term_id'] = array(
      '#type' => 'select',
      '#title' => t('Terms'),
      '#size' => 1,
      '#options' => _quiz_taxonomy_select($quiz->tid),
      '#default_value' => $quiz->tid,
      '#description' => t('Randomly select from questions with this term, or choose from the random question pool below'),
    );
  }

  // Display questions 'random' on this quiz.
  $form['filtered_question_list_random'] = array(
    '#type' => 'fieldset',
    '#title' => t("Questions 'random' on this quiz"),
    '#theme' => 'quiz_filtered_questions',
    '#collapsible' => TRUE,
    'question_status' => array(
      '#tree' => TRUE,
    ),
  );

  // Display filtered question list.
  $form['filtered_question_list'] = array(
    '#type' => 'fieldset',
    '#title' => t("Questions 'never' on this quiz"),
    '#theme' => 'quiz_filtered_questions',
    '#collapsible' => TRUE,
    'question_status' => array(
      '#tree' => TRUE,
    ),
  );

  // Get all questions and their status in relation to this quiz.
  $questions = array_merge(_quiz_get_unused_questions($quiz->vid), _quiz_get_questions($quiz->vid));
  foreach ($questions as $question) {
    switch ($question->status) {
      case QUESTION_RANDOM:
        $_form =& $form['filtered_question_list_random'];
        break;
      case QUESTION_ALWAYS:
        $_form =& $form['filtered_question_list_always'];
        break;
      case QUESTION_NEVER:
        $_form =& $form['filtered_question_list'];
        break;
    }
    $_form['question_status'][$question->nid] = array(
      '#type' => 'radios',
      '#options' => array(
        QUESTION_RANDOM => '',
        QUESTION_ALWAYS => '',
        QUESTION_NEVER => '',
      ),
      '#default_value' => $question->status,
    );
    $_form['question'][$question->nid] = array(
      '#type' => 'markup',
      '#value' => $question->question,
    );
    $_form['type'][$question->nid] = array(
      '#type' => 'markup',
      '#value' => $question->type,
    );
  }

  // Show the number of 'always' questions in the 'always' table header.
  $form['filtered_question_list_always']['#title'] .= ' (' . count($form['filtered_question_list_always']['type']) . ')';
  $form['new_revision'] = array(
    '#type' => 'checkbox',
    '#default_value' => in_array('revision', variable_get('node_options_quiz', array())),
    '#title' => t('New revision'),
    '#description' => t('Allow question status changes to create a new revision of the quiz?'),
  );
  $form['timestamp'] = array(
    '#type' => 'hidden',
    '#value' => time(),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit questions'),
  );
  return $form;
}