You are here

public function ScaleQuestion::getCreationForm in Quiz 6.4

Same name and namespace in other branches
  1. 8.6 question_types/quiz_scale/src/Plugin/quiz/QuizQuestion/ScaleQuestion.php \ScaleQuestion::getCreationForm()
  2. 8.5 question_types/quiz_scale/src/Plugin/quiz/QuizQuestion/ScaleQuestion.php \ScaleQuestion::getCreationForm()
  3. 6.6 question_types/scale/scale.classes.inc \ScaleQuestion::getCreationForm()
  4. 7.6 question_types/scale/scale.classes.inc \ScaleQuestion::getCreationForm()
  5. 7 question_types/scale/scale.classes.inc \ScaleQuestion::getCreationForm()
  6. 7.4 question_types/scale/scale.classes.inc \ScaleQuestion::getCreationForm()
  7. 7.5 question_types/scale/scale.classes.inc \ScaleQuestion::getCreationForm()

Implementation of getCreationForm

Overrides QuizQuestion::getCreationForm

See also

QuizQuestion#getCreationForm()

File

question_types/scale/scale.classes.inc, line 339
The main classes for the scale question type.

Class

ScaleQuestion
Extension of QuizQuestion.

Code

public function getCreationForm(array $form_state = NULL) {
  $form = array();

  /*
   * Getting presets from the database
   */
  $collections = $this
    ->getPresetCollections(TRUE);
  $options = $this
    ->makeOptions($collections);
  $options['d'] = '-';

  // Default
  // We need to add the available preset collections as javascript so that the alternatives can be populated instantly
  // when a
  $jsArray = $this
    ->makeJSArray($collections);
  $form['answer'] = array(
    '#type' => 'fieldset',
    '#title' => t('Answer'),
    '#description' => t('Provide alternatives for the user to answer.'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#weight' => -4,
  );
  $form['answer']['#theme'][] = 'scale_creation_form';
  $form['answer']['presets'] = array(
    '#type' => 'select',
    '#title' => t('Presets'),
    '#options' => $options,
    '#default_value' => 'd',
    '#description' => t('Select a set of alternatives'),
    '#attributes' => array(
      'onchange' => 'refreshAlternatives(this)',
    ),
  );
  $max_num_alts = variable_get('scale_max_num_of_alts', 10);
  $form['jsArray'] = array(
    '#type' => 'markup',
    '#value' => "<script type='text/javascript'>{$jsArray} var scale_max_num_of_alts = {$max_num_alts};</script>",
  );
  $form['answer']['alternatives'] = array(
    '#type' => 'fieldset',
    '#title' => t('Alternatives'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  for ($i = 0; $i < $max_num_alts; $i++) {
    $form['answer']['alternatives']["alternative{$i}"] = array(
      '#type' => 'textfield',
      '#title' => t('Alternative !i', array(
        '!i' => $i + 1,
      )),
      '#size' => 60,
      '#maxlength' => 256,
      '#default_value' => isset($this->node->{$i}->answer) ? $this->node->{$i}->answer : '',
      '#required' => $i < 2,
    );
  }
  $form['answer']['alternatives']['save'] = array(
    // @todo: Rename save to save_as_preset or something
    '#type' => 'checkbox',
    '#title' => t('Save as a new preset'),
    '#description' => t('Current alternatives will be saved as a new preset'),
    '#default_value' => FALSE,
  );
  $form['answer']['manage'] = array(
    '#type' => 'markup',
    '#value' => l(t('Manage presets'), 'scale/collection/manage'),
  );
  return $form;
}