You are here

public function TrueFalseResponse::getFeedbackValues in Quiz 6.x

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

Overrides QuizResultAnswerEntityTrait::getFeedbackValues

File

question_types/quiz_truefalse/src/Plugin/quiz/QuizQuestion/TrueFalseResponse.php, line 40

Class

TrueFalseResponse
Extension of QuizQuestionResponse.

Namespace

Drupal\quiz_truefalse\Plugin\quiz\QuizQuestion

Code

public function getFeedbackValues() : array {
  $answer = $this
    ->getResponse();
  if (is_numeric($answer)) {
    $answer = intval($answer);
  }
  $correct_answer = intval($this
    ->getQuizQuestion()
    ->getCorrectAnswer());
  $data = [];
  $data[] = [
    'choice' => t('True'),
    'attempt' => $answer === 1 ? QuizUtil::icon('selected') : '',
    'correct' => $answer === 1 ? QuizUtil::icon($correct_answer ? 'correct' : 'incorrect') : '',
    'score' => intval($correct_answer === 1 && $answer === 1),
    'answer_feedback' => '',
    'solution' => $correct_answer === 1 ? QuizUtil::icon('should') : '',
  ];
  $data[] = [
    'choice' => t('False'),
    'attempt' => $answer === 0 ? QuizUtil::icon('selected') : '',
    'correct' => $answer === 0 ? QuizUtil::icon(!$correct_answer ? 'correct' : 'incorrect') : '',
    'score' => intval($correct_answer === 0 && $answer === 0),
    'answer_feedback' => '',
    'solution' => $correct_answer === 0 ? QuizUtil::icon('should') : '',
  ];
  return $data;
}