public function MultichoiceResponse::getFeedbackValues in Quiz 6.x
Same name and namespace in other branches
- 8.6 question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceResponse.php \Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion\MultichoiceResponse::getFeedbackValues()
- 8.5 question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceResponse.php \Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion\MultichoiceResponse::getFeedbackValues()
Overrides QuizResultAnswerEntityTrait::getFeedbackValues
File
- question_types/
quiz_multichoice/ src/ Plugin/ quiz/ QuizQuestion/ MultichoiceResponse.php, line 107
Class
- MultichoiceResponse
- Extension of QuizQuestionResponse.
Namespace
Drupal\quiz_multichoice\Plugin\quiz\QuizQuestionCode
public function getFeedbackValues() : array {
// @todo d8
//$this->orderAlternatives($this->question->alternatives);
$simple_scoring = $this
->getQuizQuestion()
->get('choice_boolean')
->getString();
$user_answers = $this
->getResponse();
$data = [];
$alternatives = $this
->getQuizQuestion()
->get('alternatives')
->referencedEntities();
foreach ($alternatives as $alternative) {
$chosen = in_array($alternative
->getRevisionId(), $user_answers);
$not = $chosen ? '' : 'not_';
$chosen_feedback = $alternative->{"multichoice_feedback_{$not}chosen"};
$data[] = [
'choice' => check_markup($alternative->multichoice_answer->value, $alternative->multichoice_answer->format),
'attempt' => $chosen ? QuizUtil::icon('selected') : '',
'correct' => $chosen ? $alternative->multichoice_score_chosen->value > 0 ? QuizUtil::icon('correct') : QuizUtil::icon('incorrect') : '',
'score' => (int) $alternative->{"multichoice_score_{$not}chosen"}->value,
'answer_feedback' => check_markup($chosen_feedback->value, $chosen_feedback->format),
'question_feedback' => 'Question feedback',
'solution' => $alternative->multichoice_score_chosen->value > 0 ? QuizUtil::icon('should') : ($simple_scoring ? QuizUtil::icon('should-not') : ''),
'quiz_feedback' => "Quiz feedback",
];
}
return $data;
}