You are here

function _cloze_get_correct_answer_chunks in Cloze 7

Same name and namespace in other branches
  1. 6 cloze.module \_cloze_get_correct_answer_chunks()
4 calls to _cloze_get_correct_answer_chunks()
ClozeQuestion::evaluateAnswer in ./cloze.classes.inc
Evaluate the correctness of an answer based on the correct answer and evaluation method.
ClozeQuestion::_answerJs in ./cloze.classes.inc
_cloze_get_correct_answer in ./cloze.module
_cloze_get_user_answer in ./cloze.module

File

./cloze.module, line 125

Code

function _cloze_get_correct_answer_chunks($question) {
  $correct_answer = array();
  $chunks = _cloze_get_question_chunks($question);
  foreach ($chunks as $key => $value) {
    if (strpos($value, '[') === FALSE) {
      continue;
    }
    else {
      $answer_chunk = str_replace(array(
        '[',
        ']',
      ), '', $value);
      $choice = explode(',', $answer_chunk);
      if (count($choice) == 1) {
        $correct_answer[$key] = $answer_chunk;
      }
      else {
        $correct_answer[$key] = $choice[0];
      }
    }
  }
  return $correct_answer;
}