You are here

public function MatchingResponse::getReportFormResponse in Quiz 8.4

Implementation of getReportFormResponse

Overrides QuizQuestionResponse::getReportFormResponse

See also

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

File

question_types/matching/lib/Drupal/matching/MatchingResponse.php, line 118

Class

MatchingResponse
Extension of QuizQuestionResponse

Namespace

Drupal\matching

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();
    $correct = FALSE;
    $id = NULL;
    $answer_data['question'] = check_markup($correct_answer['question'], $this
      ->getFormat());
    if (isset($user_answers[$correct_answer['match_id']])) {
      $id = $user_answers[$correct_answer['match_id']];
      $correct = isset($correct_answers[$id]) && $correct_answer['answer'] == $correct_answers[$id]['answer'];
      $answer_data['user_answer'] = isset($correct_answers[$id]) ? check_markup($correct_answers[$id]['answer'], $this
        ->getFormat()) : NULL;
    }
    if ($showpoints) {
      $answer_data['correct_answer'] = $correct_answer['answer'];
    }
    if ($showfeedback && !empty($correct_answer['feedback'])) {
      $answer_data['feedback'] = check_markup($correct_answer['feedback'], $this
        ->getFormat());
    }
    else {

      //$has_feedback = FALSE;
      if ($showfeedback) {
        $answer_data['feedback'] = '';
      }
    }
    $answer_data['is_correct'] = $correct;
    $data[] = $answer_data;
  }
  if ($showfeedback && $has_feedback) {
    $metadata[] = t('Feedback');
  }
  return array(
    '#markup' => theme('matching_response', array(
      'metadata' => $metadata,
      'data' => $data,
    )),
  );
}