public function MultichoiceResponse::getFeedbackValues in Quiz 8.6
Same name and namespace in other branches
- 8.5 question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceResponse.php \Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion\MultichoiceResponse::getFeedbackValues()
- 6.x question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceResponse.php \Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion\MultichoiceResponse::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_multichoice/ src/ Plugin/ quiz/ QuizQuestion/ MultichoiceResponse.php, line 132
Class
- MultichoiceResponse
- Extension of QuizQuestionResponse.
Namespace
Drupal\quiz_multichoice\Plugin\quiz\QuizQuestionCode
public function getFeedbackValues() {
// @todo d8
//$this->orderAlternatives($this->question->alternatives);
$simple_scoring = $this
->getQuizQuestion()
->get('choice_boolean')
->getString();
$user_answers = $this
->getResponse();
$data = array();
foreach ($this
->getQuizQuestion()
->get('alternatives')
->referencedEntities() as $alternative) {
$chosen = in_array($alternative
->getRevisionId(), $user_answers);
$not = $chosen ? '' : 'not_';
$data[] = array(
'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($alternative->{"multichoice_feedback_{$not}chosen"}->value, $alternative->{"multichoice_feedback_{$not}chosen"}->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;
}