function _cloze_get_user_answer in Cloze 7
Same name and namespace in other branches
- 6 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 163
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 = _cloze_get_clean_text($correct_answer_chunks[$key]) == _cloze_get_clean_text($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);
}