You are here

public function MatchingQuestion::getAnsweringForm in Quiz 7.6

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

Implementation of getAnsweringForm

Overrides QuizQuestion::getAnsweringForm

See also

QuizQuestion#getAnsweringForm($form_state, $result_id)

File

question_types/matching/matching.classes.inc, line 216
matching.classes

Class

MatchingQuestion
Extension of QuizQuestion.

Code

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

    // The question has already been answered. We load the answers
    $response = new MatchingResponse($result_id, $this->node);
    $responses = $response
      ->getResponse();
  }
  list($matches, $select_option) = $this
    ->getSubquestions();

  //$form['#theme'] = 'matching_subquestion_form';
  foreach ($matches as $match) {
    $form[$match['match_id']] = array(
      '#title' => $match['question'],
      '#type' => 'select',
      '#options' => $this
        ->customShuffle($select_option),
    );
    if ($responses) {

      // If this question already has been answered
      $form[$match['match_id']]['#default_value'] = $responses[$match['match_id']];
    }
  }
  if (variable_get('quiz_matching_shuffle_options', TRUE)) {
    $form = $this
      ->customShuffle($form);
  }
  $form['scoring_info'] = array(
    '#markup' => '<p><em>' . t('You lose points by selecting incorrect options. You may leave an option blank to avoid losing points.') . '</em></p>',
  );
  return $form;
}