You are here

function _quiz_add_questions_to_form in Quiz 7

Same name and namespace in other branches
  1. 8.4 quiz.admin.inc \_quiz_add_questions_to_form()
  2. 6.4 quiz.admin.inc \_quiz_add_questions_to_form()
  3. 7.6 quiz.admin.inc \_quiz_add_questions_to_form()
  4. 7.4 quiz.admin.inc \_quiz_add_questions_to_form()
  5. 7.5 quiz.admin.inc \_quiz_add_questions_to_form()

Adds the questions in the $questions array to the form

Parameters

$form: FAPI form(array)

$questions: The questions to be added to the question list(array)

$quiz: The quiz node(object)

$question_types: array of all available question types

1 call to _quiz_add_questions_to_form()
quiz_questions_form in ./quiz.admin.inc
Handles "manage questions" tab.

File

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

Code

function _quiz_add_questions_to_form(&$form, &$questions, &$quiz, &$question_types) {
  $form['question_list']['weights'] = array(
    '#tree' => TRUE,
  );
  $form['question_list']['max_scores'] = array(
    '#tree' => TRUE,
  );
  $form['question_list']['stayers'] = array(
    '#tree' => TRUE,
  );
  $form['question_list']['revision'] = array(
    '#tree' => TRUE,
  );
  if ($quiz->randomization == 2) {
    $form['question_list']['compulsories'] = array(
      '#tree' => TRUE,
    );
  }
  $my_dest = $_GET['q'];
  foreach ($questions as $question) {
    $fieldset = 'question_list';
    $id = $question->nid . '-' . $question->vid;
    $form[$fieldset]['weights'][$id] = array(
      '#type' => 'textfield',
      '#size' => 3,
      '#maxlength' => 4,
      '#default_value' => isset($question->weight) ? $question->weight : 0,
    );

    // Quiz directions don't have scoring...
    if ($question->type != 'quiz_directions') {
      $form[$fieldset]['max_scores'][$id] = array(
        '#type' => 'textfield',
        '#size' => 2,
        '#maxlength' => 2,
        '#default_value' => isset($question->max_score) ? $question->max_score : 0,
      );
    }
    else {
      $form[$fieldset]['max_scores'][$id] = array(
        '#markup' => '',
      );
    }

    // Add checkboxes to remove questions in js disabled browsers...
    $form[$fieldset]['stayers'][$id] = array(
      '#type' => 'checkbox',
      '#default_value' => isset($question->staying) && $question->staying === FALSE ? 0 : 1,
      '#attributes' => array(
        'class' => array(
          'q-staying',
        ),
      ),
    );

    //Add checkboxes to mark compulsory questions for randomized quizzes.
    if ($quiz->randomization == 2) {
      $form[$fieldset]['compulsories'][$id] = array(
        '#type' => 'checkbox',
        '#default_value' => isset($question->question_status) ? $question->question_status == QUESTION_ALWAYS ? 1 : 0 : 0,
        '#attributes' => array(
          'class' => array(
            'q-compulsory',
          ),
        ),
      );
    }
    $link_options = array(
      'attributes' => array(
        'class' => array(
          'handle-changes',
        ),
      ),
      'html' => TRUE,
    );
    $form[$fieldset]['titles'][$id] = array(
      '#markup' => l($question->title, 'node/' . $question->nid, $link_options),
    );
    $form[$fieldset]['types'][$id] = array(
      '#markup' => $question_types[$question->type]['name'],
    );
    $form[$fieldset]['view_links'][$id] = array(
      '#markup' => l(t('Edit'), 'node/' . $question->nid . '/edit', array(
        'query' => array(
          'destination' => $my_dest,
        ),
        'attributes' => array(
          'class' => array(
            'handle-changes',
          ),
        ),
      )),
    );

    // For js enabled browsers questions are removed by pressing a remove link
    $form[$fieldset]['remove_links'][$id] = array(
      '#markup' => '<a href="#" class="rem-link">' . t('Remove') . '</a>',
    );

    // Add a checkbox to update to the latest revision of the question
    if ($question->vid == $question->latest_vid) {
      $update_cell = array(
        '#markup' => t('<em>Up to date</em>'),
      );
    }
    else {
      $update_cell = array(
        '#type' => 'checkbox',
        '#title' => l(t('Latest'), 'node/' . $question->nid . '/revisions/' . $latest->vid . '/view') . ' of ' . l(t('revisions'), 'node/' . $question->nid . '/revisions'),
      );
    }
    $form[$fieldset]['revision'][$id] = $update_cell;
  }
}