public function ClozeQuestion::getNodeView in Cloze 6
Same name and namespace in other branches
- 7 cloze.classes.inc \ClozeQuestion::getNodeView()
Implementation of getNodeView
See also
QuizQuestion#getNodeView()
File
- ./
cloze.classes.inc, line 78 - The main classes for the short answer question type.
Class
- ClozeQuestion
- Extension of QuizQuestion.
Code
public function getNodeView() {
$content = parent::getNodeView();
drupal_add_css(drupal_get_path('module', 'cloze') . '/theme/cloze.css');
$chunks = _cloze_get_question_chunks($this->node->body);
if ($this
->viewCanRevealCorrect() && !empty($chunks)) {
$solution = $this->node->body;
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(
'#type' => 'markup',
'#value' => '<div class="quiz-solution cloze-question">' . check_markup($solution, variable_get('filter_default_format', 1)) . '</div>',
);
}
else {
$content['answers'] = array(
'#type' => 'markup',
'#value' => '<div class="quiz-answer-hidden">Answer hidden</div>',
'#weight' => 2,
);
}
return $content;
}