You are here

function quiz_questions_form in Quiz 7

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.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.

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 in ./quiz.admin.inc
Creates a form for quiz questions.

File

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

Code

function quiz_questions_form($form, $form_state, $quiz) {

  // We need to add this because of the use of ajax. Without this the form api might redirect the user
  // To the page with the ahah callback...
  $form['#action'] = url('node/' . $quiz->nid . '/questions');
  $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'),
    '#theme' => 'question_selection_table',
    '#collapsible' => TRUE,
    '#attributes' => array(
      'id' => 'mq-fieldset',
    ),
    'question_status' => array(
      '#tree' => TRUE,
    ),
  );
  $form['#attached']['js'] = array(
    drupal_get_path('module', 'quiz') . '/theme/quiz_question_browser.js',
  );

  // Add randomization settings if this quiz allows randomized questions
  _quiz_add_fields_for_random_quiz($form, $quiz);

  // Build up a list of questions
  $questions_to_add = array();

  // We use $form_state[post] to avoid validation failures when questions are added using AJAX
  if (isset($form_state['post']['weights'])) {
    $questions = _quiz_get_questions_from_form_state($form_state, $questions_to_add);
  }
  else {

    // We are coming in fresh and fetches the questions currently on the quiz from the database...
    $include_random = $quiz->randomization == 2;
    $questions = quiz_get_questions($quiz->nid, $quiz->vid, TRUE, FALSE, FALSE, $include_random);
  }
  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.') . '</div>',
    );
  }

  // We add the browser and allows the browser to give us information on what questions are displayed in the browser...
  $hidden_questions = array();
  $form['question_list']['browser'] = _quiz_question_browser_form($hidden_questions, $questions_to_add, $form_state, $quiz, $types);

  // We add the questions from the browser as hidden question rows in the question list. Doing this we can have
  // the question show up in the question list instantly when a question is chosen in the browser(using js).
  _quiz_add_hidden_questions($questions, $hidden_questions, $form_state, $quiz);

  // 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 = 0;
  foreach ($form['question_list']['stayers'] as $stayer) {
    if ($stayer['#default_value'] === 1) {
      $always_count++;
    }
  }
  $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['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
    '#submit' => array(
      'quiz_questions_form_submit',
    ),
  );
  return $form;
}