You are here

public function ClozeResponse::getReportForm in Quiz 8.4

Implementation of getReportForm()

Overrides QuizQuestionResponse::getReportForm

See also

QuizQuestionResponse#getReportForm($showpoints, $showfeedback, $allow_scoring)

File

question_types/cloze/lib/Drupal/cloze/ClozeResponse.php, line 102

Class

ClozeResponse
Extension of QuizQuestionResponse

Namespace

Drupal\cloze

Code

public function getReportForm($showpoints = TRUE, $showfeedback = TRUE, $allow_scoring = FALSE) {
  $form = parent::getReportForm($showpoints, $showfeedback, $allow_scoring);
  $question = strip_tags($form['question']['#markup']);
  $question_form['open_wrapper'] = array(
    '#markup' => '<div class="cloze-question">',
  );
  foreach (_cloze_get_question_chunks($question) as $position => $chunk) {
    if (strpos($chunk, '[') === FALSE) {

      // this "tries[foobar]" hack is needed becaues response handler engine checks for input field
      // with name tries
      $question_form['tries[' . $position . ']'] = array(
        '#markup' => str_replace("\n", "<br/>", $chunk),
        '#prefix' => '<div class="form-item">',
        '#suffix' => '</div>',
      );
    }
    else {
      $chunk = str_replace(array(
        '[',
        ']',
      ), '', $chunk);
      $choices = explode(',', $chunk);
      if (count($choices) > 1) {
        $question_form['tries[' . $position . ']'] = array(
          '#type' => 'select',
          '#title' => '',
          '#options' => _cloze_shuffle_choices(drupal_map_assoc($choices)),
          '#required' => FALSE,
        );
      }
      else {
        $question_form['tries[' . $position . ']'] = array(
          '#type' => 'textfield',
          '#title' => '',
          '#size' => 32,
          '#required' => FALSE,
          '#attributes' => array(
            'autocomplete' => 'off',
          ),
        );
      }
    }
  }
  $question_form['close_wrapper'] = array(
    '#markup' => '</div>',
  );
  $form['question']['#markup'] = drupal_render($question_form);
  return $form;
}