You are here

public function QuizQuestionResponse::getFeedback in Quiz 7.6

Returns a renderable array of question feedback.

1 call to QuizQuestionResponse::getFeedback()
QuizQuestionResponse::getReportForm in question_types/quiz_question/quiz_question.core.inc
Creates the report form for the admin pages, and for when a user gets feedback after answering questions.

File

question_types/quiz_question/quiz_question.core.inc, line 691
Classes used in the Quiz Question module.

Class

QuizQuestionResponse
Each question type must store its own response data and be able to calculate a score for that data.

Code

public function getFeedback() {
  $out = array();
  $node = node_load($this->question->nid, $this->question->vid);
  $entity_info = entity_get_info('node');
  foreach ($entity_info['view modes'] as $view_mode => $info) {
    if ($this
      ->canReview("quiz_question_view_" . $view_mode)) {
      node_build_content($node, $view_mode);
      unset($node->content['answers']);
      unset($node->content['links']);
      $out['question'][] = $node->content;
    }
  }
  $rows = array();
  $labels = array(
    'attempt' => t('Your answer'),
    'choice' => t('Choice'),
    'correct' => t('Correct?'),
    'score' => t('Score'),
    'answer_feedback' => t('Feedback'),
    'solution' => t('Correct answer'),
  );
  drupal_alter('quiz_feedback_labels', $labels);
  foreach ($this
    ->getFeedbackValues() as $idx => $row) {
    foreach ($labels as $reviewType => $label) {
      if (isset($row[$reviewType]) && $this
        ->canReview($reviewType)) {
        $rows[$idx][$reviewType] = $row[$reviewType];
      }
    }
  }
  if ($this
    ->isEvaluated()) {
    $score = $this
      ->getScore();
    if ($this
      ->isCorrect()) {
      $class = 'q-correct';
    }
    else {
      $class = 'q-wrong';
    }
  }
  else {
    $score = t('?');
    $class = 'q-waiting';
  }
  if ($this
    ->canReview('score') || quiz_access_to_score()) {
    $out['score_display']['#markup'] = theme('quiz_question_score', array(
      'score' => $score,
      'max_score' => $this
        ->getMaxScore(),
      'class' => $class,
    ));
  }
  if ($rows) {
    $headers = array_intersect_key($labels, $rows[0]);
    $type = $this
      ->getQuizQuestion()->node->type;
    $out['response']['#markup'] = theme('quiz_question_feedback__' . $type, array(
      'labels' => $headers,
      'data' => $rows,
    ));
  }
  if ($this
    ->canReview('question_feedback')) {
    if ($properties = entity_load('quiz_question', FALSE, array(
      'nid' => $this->quizQuestion->node->nid,
      'vid' => $this->quizQuestion->node->vid,
    ))) {
      $quiz_question = reset($properties);
      $out['question_feedback']['#markup'] = check_markup($quiz_question->feedback, $quiz_question->feedback_format);
    }
  }
  if ($this
    ->canReview('score')) {
    $out['max_score'] = array(
      '#type' => 'value',
      '#value' => $this
        ->getMaxScore(),
    );
  }
  return $out;
}