You are here

function qcollection_items_form in Quiz 6.6

Handles "manage questions" tab.

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

Parameters

$context: The form context

$quiz: The quiz node.

Return value

HTML output to create page.

1 string reference to 'qcollection_items_form'
qcollection_items in includes/qcollection/qcollection.inc
Creates a form for quiz questions.

File

includes/qcollection/qcollection.inc, line 40

Code

function qcollection_items_form($context, $quiz) {

  ////

  // ripped from quiz.admin.inc

  ///

  // 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('Add new question'),
    '#theme' => 'additional_questions',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $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>',
    );
  }

  // FIXME this should be something like "item_list" instead of 'filtered_question_list_always'
  // but qcollection is using quiz_admin_add_question_ahah() in quiz.admin.inc
  // which is hard-coded on this fieldset name
  $form['filtered_question_list_always'] = array(
    '#type' => 'fieldset',
    '#title' => t('Items in collection'),
    '#theme' => 'question_selection_table',
    'question_status' => array(
      '#tree' => TRUE,
    ),
  );
  $form['filtered_question_list_always']['remove_from_quiz'] = array(
    '#type' => 'hidden',
    '#default_value' => '',
  );
  $form['add_existing_question'] = 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, expand the "Add new question" section at top.'),
    '#collapsible' => FALSE,
    '#collapsed' => FALSE,
  );
  $form['add_existing_question']['always_autocomplete'] = array(
    '#type' => 'textfield',
    '#default_value' => '',
    '#size' => 60,
    '#maxlength' => 256,
    '#required' => FALSE,
    '#autocomplete_path' => 'admin/quiz/listquestions',
  );
  $form['add_existing_question']['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...'),
      ),
    ),
  );

  // 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 collection?'),
  );
  $form['timestamp'] = array(
    '#type' => 'hidden',
    '#value' => time(),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit questions'),
  );
  return $form;
}