You are here

public function MatchingQuestion::getAnsweringForm in Quiz 8.4

Implementation of getAnsweringForm

Overrides QuizQuestion::getAnsweringForm

See also

QuizQuestion#getAnsweringForm($form_state, $rid)

File

question_types/matching/lib/Drupal/matching/MatchingQuestion.php, line 218
The main classes for the matching question type.

Class

MatchingQuestion
Extension of QuizQuestion.

Namespace

Drupal\matching

Code

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

  //$form['#theme'] = 'matching_answering_form';
  if (isset($rid)) {

    // The question has already been answered. We load the answers
    $response = new MatchingResponse($rid, $this->node);
    $responses = $response
      ->getResponse();
  }
  list($matches, $select_option) = $this
    ->getSubquestions();
  $form['subquestions']['#theme'] = 'matching_subquestion_form';
  foreach ($matches as $match) {
    $form['subquestions'][$match['match_id']]['#question'] = check_markup($match['question']);
    $form['subquestions'][$match['match_id']]['tries[' . $match['match_id'] . ']'] = array(
      '#type' => 'select',
      '#options' => $this
        ->customShuffle($select_option),
    );
    if (isset($rid)) {

      // If this question already has been answered
      $form['subquestions'][$match['match_id']]['tries[' . $match['match_id'] . ']']['#default_value'] = $responses[$match['match_id']];
    }
  }
  $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>',
  );
  if (variable_get('quiz_matching_shuffle_options', TRUE)) {
    $form['subquestions'] = $this
      ->customShuffle($form['subquestions']);
  }
  return $form;
}