public function TrueFalseActivityAnswer::getAnswerResultItemData in Opigno module 8
Same name and namespace in other branches
- 3.x src/Plugin/ActivityAnswer/TrueFalseActivityAnswer.php \Drupal\opigno_module\Plugin\ActivityAnswer\TrueFalseActivityAnswer::getAnswerResultItemData()
Returns answer result data.
File
- src/
Plugin/ ActivityAnswer/ TrueFalseActivityAnswer.php, line 68
Class
- TrueFalseActivityAnswer
- Class TrueFalseActivityAnswer.
Namespace
Drupal\opigno_module\Plugin\ActivityAnswerCode
public function getAnswerResultItemData(OpignoAnswerInterface $answer) {
$data = [];
/** @var \Drupal\opigno_module\Entity\OpignoAnswer $answer */
$user_answer = $answer
->hasField('field_true_false') ? $answer
->get('field_true_false')->value : NULL;
/** @var \Drupal\opigno_module\Entity\OpignoActivityInterface $activity */
$activity = $answer
->getActivity();
$correct_answer = $activity
->hasField('field_true_false') ? $activity
->get('field_true_false')->value : NULL;
$data[] = [
'answer' => $user_answer !== NULL && $user_answer == 1 ? '->' : '',
'choice' => $this
->t('True'),
'correct' => $correct_answer !== NULL && $correct_answer == 1 ? '+' : '',
];
$data[] = [
'answer' => $user_answer !== NULL && $user_answer == 0 ? '->' : '',
'choice' => t('False'),
'correct' => $correct_answer !== NULL && $correct_answer == 0 ? '+' : '',
];
return $data;
}