You are here

public function ChoiceQuestion::getQuestionForm in Quiz 6.6

Generates the question form.

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

Overrides QuizQuestion::getQuestionForm

1 call to ChoiceQuestion::getQuestionForm()
ChoiceQuestion::view in question_types/choice/choice.classes.inc
Implementation of view

File

question_types/choice/choice.classes.inc, line 264
The main classes for the choice question type.

Class

ChoiceQuestion
Implementation of QuizQuestion.

Code

public function getQuestionForm($node, $context = NULL) {
  $form['question'] = array(
    '#type' => 'markup',
    '#value' => check_markup($node->body, $node->format, FALSE),
  );
  $form['tries[answer]'] = array(
    '#options' => array(),
    '#theme' => 'choice_alternative',
  );
  $form['tries[answer]']['#taking_quiz'] = _quiz_is_taking_context();
  $form['tries[answer]']['#correct_choice'] = array();
  for ($i = 0; is_array($node->alternatives[$i]); $i++) {
    $short = $node->alternatives[$i];
    if (drupal_strlen(strip_tags($short['answer'])) > 0) {
      $markup = check_markup($short['answer'], $short['answer_format']);
      if (!$form['tries[answer]']['#taking_quiz']) {

        // displaying outside a quiz-taking context
        $is_correct = $short['score_if_chosen'] > $short['score_if_not_chosen'];
        $form['tries[answer]']['#correct_choice'][$short['id']] = $is_correct;
      }
      $form['tries[answer]']['#options'][$short['id']] = $markup;
    }
  }
  if ($node->choice_random) {
    $form['tries[choice_order]'] = array(
      '#type' => 'hidden',
      '#value' => implode(',', $this
        ->shuffle($form['tries[answer]']['#options'])),
    );
  }
  if ($node->choice_multi) {
    $form['tries[answer]']['#type'] = 'checkboxes';
    $form['tries[answer]']['#title'] = t('Choose');
  }
  else {
    $form['tries[answer]']['#type'] = 'radios';
    $form['tries[answer]']['#title'] = t('Choose one');
  }
  if (!$form['tries[answer]']['#taking_quiz']) {
    unset($form['tries[answer]']['#title']);
    $form['tries[answer]']['#disabled'] = TRUE;
  }
  return $form;
}