You are here

public function ShortAnswerResponse::getFeedbackValues in Quiz 8.6

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

Get the response part of the report form.

Return value

array Array of response data, with each item being an answer to a response. For an example, see MultichoiceResponse::getFeedbackValues(). The sub items are keyed by the feedback type. Providing a NULL option means that feedback will not be shown. See an example at LongAnswerResponse::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() {
  $data = array();
  $score = $this
    ->getPoints();
  $max = $this
    ->getMaxScore(FALSE);
  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');
  }
  $data[] = array(
    // 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($this
      ->get('answer_feedback')
      ->getValue()[0]['value'], $this
      ->get('answer_feedback')
      ->getValue()[0]['format']),
  );
  return $data;
}