You are here

public function ClozeQuestion::getNodeView in Cloze 7

Same name and namespace in other branches
  1. 6 cloze.classes.inc \ClozeQuestion::getNodeView()

Implementation of getNodeView()

See also

QuizQuestion#getNodeView()

File

./cloze.classes.inc, line 90
The main classes for the cloze question type. These inherit or implement code found in quiz_question.classes.inc.

Class

ClozeQuestion
Extension of QuizQuestion.

Code

public function getNodeView() {
  $content = parent::getNodeView();
  $content['#attached']['css'] = array(
    drupal_get_path('module', 'cloze') . '/theme/cloze.css',
  );
  $question = $this->node->body[LANGUAGE_NONE][0]['value'];
  $chunks = _cloze_get_question_chunks($question);
  if ($this
    ->viewCanRevealCorrect() && !empty($chunks)) {
    $solution = $this->node->body[LANGUAGE_NONE][0]['value'];
    foreach ($chunks as $position => $chunk) {
      if (strpos($chunk, '[') === FALSE) {
        continue;
      }
      $chunk = str_replace(array(
        '[',
        ']',
      ), '', $chunk);
      $choices = explode(',', $chunk);
      $replace = '<span class="correct answer user-answer">' . $choices[0] . '</span>';
      $solution = str_replace($chunks[$position], $replace, $solution);
    }
    $content['answers'] = array(
      '#markup' => '<div class="quiz-solution cloze-question">' . $solution . '</div>',
      '#weight' => 5,
    );
    if (isset($this->node->learning_mode) && $this->node->learning_mode) {
      $content['learning_mode'] = array(
        '#markup' => '<div class="">' . t('Enabled to accept only the right answers.') . '</div>',
        '#weight' => 5,
      );
    }
  }
  else {
    $content['answers'] = array(
      '#markup' => '<div class="quiz-answer-hidden">Answer hidden</div>',
      '#weight' => 2,
    );
  }
  return $content;
}