You are here

function quiz_questions_form in Quiz 6.6

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

Parameters

$context: The form context

$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 113
Administrator interface for Quiz module.

Code

function quiz_questions_form($context, $quiz) {

  // This is a target for AHAH callbacks. Do not remove.
  $form['ahah_target'] = array(
    '#type' => 'markup',
    '#value' => '<div id="questions-always-target"></div>',
  );

  // Display links to create other questions.
  $form['additional_questions'] = array(
    '#type' => 'fieldset',
    '#title' => t('Create additional questions'),
    '#theme' => 'additional_questions',
  );
  $types = _quiz_get_question_types();
  foreach ($types as $type => $info) {
    $url_type = str_replace('_', '-', $type);
    $form['additional_questions'][$type] = array(
      '#type' => 'markup',
      // FIXME: This looks broken:
      '#value' => '<div class="add-questions">' . l(t($info['name']), 'node/add/' . $url_type . '/' . $quiz->nid, array(
        'title' => t('Go to @name administration', array(
          '@name' => $info['name'],
        )),
      )) . '</div>',
    );
  }

  // 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',
    '#theme' => 'question_selection_table',
    '#collapsible' => TRUE,
    'question_status' => array(
      '#tree' => TRUE,
    ),
  );
  $form['filtered_question_list_always']['always_box'] = array(
    '#type' => 'fieldset',
    '#title' => '<strong>' . t('Find and add a question') . '</strong>',
    '#description' => t('Begin typing a question title or keyword. Suggestions will be presented based on your typing. ') . '<strong>' . t('You must choose one of the suggested questions.') . '</strong> ' . t('To add a new question, use the "Create additional questions" section above.'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
  );
  $form['filtered_question_list_always']['always_box']['always_autocomplete'] = array(
    '#type' => 'textfield',
    //'#title' => t('Find a question'),

    // '#description' => t('Begin typing a question title or keyword. Suggestions will be presented based on your typing. ') .
    //       '<strong>' . t('You must choose one of the suggested questions.') . '</strong> ' .
    //       t('To add a new question, use the "Create additional questions" section above.'),
    '#default_value' => '',
    '#size' => 60,
    '#maxlength' => 256,
    '#required' => FALSE,
    '#autocomplete_path' => 'admin/quiz/listquestions',
  );
  $form['filtered_question_list_always']['always_box']['add_to_list'] = array(
    '#type' => 'submit',
    '#value' => t('Add to quiz'),
    '#submit' => 'quiz_questions_form_submit',
    '#ahah' => array(
      'path' => 'admin/quiz/newquestion',
      'wrapper' => 'questions-always-target',
      'progress' => array(
        'type' => 'bar',
        'message' => t('Adding question...'),
      ),
    ),
  );
  $form['filtered_question_list_always']['remove_from_quiz'] = array(
    '#type' => 'hidden',
    '#default_value' => '',
  );

  // Display questions 'random' on this quiz.
  $form['filtered_question_list_random'] = array(
    '#type' => 'fieldset',
    '#title' => t('Pool of questions randomly selected for this quiz'),
    '#theme' => 'question_selection_table',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    // Setting this to TRUE breaks tableDrag. What a drag.
    'question_status' => array(
      '#tree' => TRUE,
    ),
  );
  $form['filtered_question_list_random']['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 that should be assigned to this quiz.'),
    '#weight' => 1,
  );
  $form['filtered_question_list_random']['random_box'] = array(
    '#type' => 'fieldset',
    '#title' => '<strong>' . t('Find and add a question') . '</strong>',
    '#description' => t('Begin typing a question title or keyword. Suggestions will be presented based on your typing. ') . '<strong>' . t('You must choose one of the suggested questions.') . '</strong> ' . t('To add a new question, use the "Create additional questions" section above.'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
    '#weight' => -1,
  );
  $form['filtered_question_list_random']['random_box']['random_autocomplete'] = array(
    '#type' => 'textfield',
    '#default_value' => '',
    '#size' => 60,
    '#maxlength' => 256,
    '#required' => FALSE,
    '#weight' => -2,
    '#autocomplete_path' => 'admin/quiz/listquestions',
  );
  $form['filtered_question_list_random']['random_box']['add_to_random'] = array(
    '#type' => 'submit',
    '#value' => t('Add to quiz'),
    '#submit' => 'quiz_questions_form_submit',
    '#weight' => -1,
    '#ahah' => array(
      'path' => 'admin/quiz/newquestion',
      'wrapper' => 'questions-always-target',
      'progress' => array(
        'type' => 'bar',
        'message' => t('Adding question...'),
      ),
    ),
  );
  $terms = _quiz_taxonomy_select($quiz->tid);
  if (!empty($terms) && function_exists('taxonomy_get_vocabularies')) {
    $form['filtered_question_list_random']['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'),
      '#weight' => 2,
    );
  }

  // Build up a list of questions, sorted into those that are random and those that are
  // always on the quiz.
  $questions = _quiz_get_questions($quiz->nid, $quiz->vid);
  $rows = array();
  $form['filtered_question_list_random']['weights'] = array(
    '#tree' => TRUE,
  );
  $form['filtered_question_list_always']['weights'] = array(
    '#tree' => TRUE,
  );
  foreach ($questions as $question) {
    $id_mod = $question->question_status == QUESTION_RANDOM ? 'random' : 'always';
    $fieldset = 'filtered_question_list_' . $id_mod;
    $id = $id_mod . '-' . $question->nid;
    $form[$fieldset]['weights'][$id] = array(
      //'#type' => 'weight',

      //'#delta' => 60,
      '#type' => 'textfield',
      '#size' => 3,
      '#maxlength' => 4,
      '#default_value' => isset($question->weight) ? $question->weight : 0,
    );
    $form[$fieldset]['titles'][$id] = array(
      // '#value' => $question->question, // Question is too long for drag and drop.
      '#value' => $question->title,
    );
    $form[$fieldset]['types'][$id] = array(
      '#value' => $question->type,
    );
    $form[$fieldset]['view_links'][$id] = array(
      '#value' => l('View', 'node/' . $question->nid),
    );
    $form[$fieldset]['remove_links'][$id] = array(
      // FIXME: This does not degrade for non-JS browsers.

      //'#value' => l('Remove', 'node/' . $question->nid .'/questions/remove', array('attributes' => array('class' => 'rem-link'))),
      '#value' => '<a href="#" class="rem-link">' . t('Remove') . '</a>',
    );
  }

  // Show the number of 'always' questions in the 'always' table header.
  $always_count = isset($form['filtered_question_list_always']['titles']) ? count($form['filtered_question_list_always']['titles']) : 0;
  $form['filtered_question_list_always']['#title'] .= ' (' . $always_count . ')';
  $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;
}