You are here

public function ShortAnswerResponse::getFeedbackValues in Quiz 6.x

Same name and namespace in other branches
  1. 8.6 question_types/quiz_short_answer/src/Plugin/quiz/QuizQuestion/ShortAnswerResponse.php \Drupal\quiz_short_answer\Plugin\quiz\QuizQuestion\ShortAnswerResponse::getFeedbackValues()
  2. 8.5 question_types/quiz_short_answer/src/Plugin/quiz/QuizQuestion/ShortAnswerResponse.php \Drupal\quiz_short_answer\Plugin\quiz\QuizQuestion\ShortAnswerResponse::getFeedbackValues()

Overrides QuizResultAnswerEntityTrait::getFeedbackValues

File

question_types/quiz_short_answer/src/Plugin/quiz/QuizQuestion/ShortAnswerResponse.php, line 62

Class

ShortAnswerResponse
Extension of QuizResultAnswer.

Namespace

Drupal\quiz_short_answer\Plugin\quiz\QuizQuestion

Code

public function getFeedbackValues() : array {
  $data = [];
  $score = $this
    ->getPoints();
  $max = $this
    ->getMaxScore();
  if ($this
    ->isEvaluated()) {

    // Question has been graded.
    if ($score == 0) {
      $icon = QuizUtil::icon('incorrect');
    }
    if ($score > 0) {
      $icon = QuizUtil::icon('almost');
    }
    if ($score == $max) {
      $icon = QuizUtil::icon('correct');
    }
  }
  else {
    $icon = QuizUtil::icon('unknown');
  }
  $answer_feedback = $this
    ->get('answer_feedback')
    ->getValue()[0];
  $data[] = [
    // Hide this column. Does not make sense for short answer as there are no
    // choices.
    'choice' => NULL,
    'attempt' => $this
      ->get('short_answer')
      ->getString(),
    'correct' => $icon,
    'score' => !$this
      ->isEvaluated() ? t('This answer has not yet been scored.') : $this
      ->getPoints(),
    'solution' => $this
      ->getQuizQuestion()
      ->get('short_answer_correct')
      ->getString(),
    'answer_feedback' => check_markup($answer_feedback['value'], $answer_feedback['format']),
  ];
  return $data;
}