You are here

public function MultichoiceQuestion::getAnsweringForm in Quiz 7

Same name and namespace in other branches
  1. 6.4 question_types/multichoice/multichoice.classes.inc \MultichoiceQuestion::getAnsweringForm()
  2. 7.6 question_types/multichoice/multichoice.classes.inc \MultichoiceQuestion::getAnsweringForm()
  3. 7.4 question_types/multichoice/multichoice.classes.inc \MultichoiceQuestion::getAnsweringForm()
  4. 7.5 question_types/multichoice/multichoice.classes.inc \MultichoiceQuestion::getAnsweringForm()

Generates the question form.

This is called whenever a question is rendered, either to an administrator or to a quiz taker.

Overrides QuizQuestion::getAnsweringForm

File

question_types/multichoice/multichoice.classes.inc, line 387
The main classes for the multichoice question type.

Class

MultichoiceQuestion
Extension of QuizQuestion.

Code

public function getAnsweringForm(array $form_state = NULL, $rid) {
  $form = parent::getAnsweringForm($form_state, $rid);

  //$form['#theme'] = 'multichoice_answering_form';

  /* We use an array looking key to be able to store multiple answers in tries.
   * At the moment all user answers have to be stored in tries. This is something we plan
   * to fix in quiz 5.x.
   */
  $form['tries[answer]'] = array(
    '#options' => array(),
    '#theme' => 'multichoice_alternative',
  );
  if (isset($rid)) {

    // This question has already been answered. We load the answer.
    $response = new MultichoiceResponse($rid, $this->node);
  }
  for ($i = 0; isset($this->node->alternatives[$i]); $i++) {
    $short = $this->node->alternatives[$i];
    $answer_markup = check_markup($short['answer'], $short['answer_format']);
    if (drupal_strlen($answer_markup) > 0) {
      $form['tries[answer]']['#options'][$short['id']] = $answer_markup;
    }
  }
  if ($this->node->choice_random) {

    // We save the choice order so that the order will be the same in the answer report
    $form['tries[choice_order]'] = array(
      '#type' => 'hidden',
      '#value' => implode(',', $this
        ->shuffle($form['tries[answer]']['#options'])),
    );
  }
  if ($this->node->choice_multi) {
    $form['tries[answer]']['#type'] = 'checkboxes';
    $form['tries[answer]']['#title'] = t('Choose');
    if (isset($response)) {
      if (is_array($response
        ->getResponse())) {
        $form['tries[answer]']['#default_value'] = $response
          ->getResponse();
      }
    }
  }
  else {
    $form['tries[answer]']['#type'] = 'radios';
    $form['tries[answer]']['#title'] = t('Choose one');
    if (isset($response)) {
      if (is_array($response
        ->getResponse())) {
        $form['tries[answer]']['#default_value'] = array_pop($response
          ->getResponse());
      }
    }
  }
  return $form;
}