You are here

public function MatchingResponse::getReportFormResponse in Quiz 7

Same name and namespace in other branches
  1. 6.4 question_types/matching/matching.classes.inc \MatchingResponse::getReportFormResponse()
  2. 7.4 question_types/matching/matching.classes.inc \MatchingResponse::getReportFormResponse()

Implementation of getReportFormResponse

Overrides QuizQuestionResponse::getReportFormResponse

See also

QuizQuestionResponse#getReportFormResponse($showpoints, $showfeedback, $allow_scoring)

File

question_types/matching/matching.classes.inc, line 467
matching.classes

Class

MatchingResponse
Extension of QuizQuestionResponse

Code

public function getReportFormResponse($showpoints = TRUE, $showfeedback = TRUE, $allow_scoring = FALSE) {
  $data = $metadata = array();

  // Build the question answers header (add blank space for IE).
  $metadata[] = t('Match');
  if ($showpoints) {
    $metadata[] = t('Correct Answer');
  }
  $metadata[] = t('User answer');
  $MatchingQuestion = new MatchingQuestion($this->question);
  $correct_answers = $MatchingQuestion
    ->getCorrectAnswer();
  $user_answers = isset($this->answer['answer']) ? $this->answer['answer'] : $this->answer;
  $has_feedback = TRUE;
  foreach ($correct_answers as $correct_answer) {
    $answer_data = array();
    $id = $user_answers[$correct_answer['match_id']];
    $correct = isset($correct_answers[$id]) && $correct_answer['answer'] == $correct_answers[$id]['answer'];
    $answer_data['question'] = $correct_answer['question'];
    if ($showpoints) {
      $answer_data['correct_answer'] = $correct_answer['answer'];
    }
    $answer_data['user_answer'] = isset($correct_answers[$id]) ? $correct_answers[$id]['answer'] : NULL;
    if ($showfeedback && !empty($correct_answer['feedback'])) {
      $answer_data['feedback'] = check_markup($correct_answer['feedback']);
      $answer_data['is_correct'] = $correct;
    }
    else {
      $has_feedback = FALSE;
    }
    $data[] = $answer_data;
  }
  if ($showfeedback && $has_feedback) {
    $metadata[] = t('Feedback');
  }
  return array(
    '#markup' => theme('matching_response', array(
      'metadata' => $metadata,
      'data' => $data,
    )),
  );
}