function _cloze_get_user_answer in Cloze 6
Same name and namespace in other branches
- 7 cloze.module \_cloze_get_user_answer()
1 call to _cloze_get_user_answer()
- ClozeResponse::getReportFormResponse in ./
cloze.classes.inc - Implementation of getReportFormResponse
File
- ./
cloze.module, line 160
Code
function _cloze_get_user_answer($question, $answer) {
$output = '';
$user_answer = $chunks = _cloze_get_question_chunks($question);
$correct_answer_chunks = _cloze_get_correct_answer_chunks($question);
foreach ($chunks as $key => $value) {
if (isset($answer[$key]) && !empty($answer[$key])) {
$class = drupal_strtolower($correct_answer_chunks[$key]) == drupal_strtolower($answer[$key]) ? 'correct' : 'incorrect';
$class .= ' answer user-answer';
$user_answer[$key] = '<span class="' . $class . '">' . $answer[$key] . '</span>';
}
elseif (isset($answer[$key])) {
$user_answer[$key] = '<span class="incorrect answer user-answer">' . str_repeat('_', strlen($correct_answer_chunks[$key])) . '</span>';
}
}
$output = implode(' ', $user_answer);
return str_replace("\n", "<br/>", $output);
}