public function MultichoiceQuestion::getMaximumScore in Quiz 8.6
Same name and namespace in other branches
- 8.5 question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceQuestion.php \Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion\MultichoiceQuestion::getMaximumScore()
- 6.x question_types/quiz_multichoice/src/Plugin/quiz/QuizQuestion/MultichoiceQuestion.php \Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion\MultichoiceQuestion::getMaximumScore()
Get the maximum possible score for this question.
Return value
int
Overrides QuizQuestionEntityTrait::getMaximumScore
File
- question_types/
quiz_multichoice/ src/ Plugin/ quiz/ QuizQuestion/ MultichoiceQuestion.php, line 775
Class
- MultichoiceQuestion
- @QuizQuestion ( id = "multichoice", label = Plugin annotation @Translation("Multiple choice question"), handlers = { "response" = "\Drupal\quiz_multichoice\Plugin\quiz\QuizQuestion\MultichoiceResponse" } )
Namespace
Drupal\quiz_multichoice\Plugin\quiz\QuizQuestionCode
public function getMaximumScore() {
if ($this
->get('choice_boolean')
->getString()) {
// Simple scoring - can only be worth 1 point.
return 1;
}
$maxes = [
0,
];
foreach ($this
->get('alternatives')
->referencedEntities() as $alternative) {
// "Not chosen" could have a positive point amount.
$maxes[] = max($alternative
->get('multichoice_score_chosen')
->getString(), $alternative
->get('multichoice_score_not_chosen')
->getString());
}
if ($this
->get('choice_multi')
->getString()) {
// For multiple answers, return the maximum possible points of all
// positively pointed answers.
return array_sum($maxes);
}
else {
// For a single answer, return the highest pointed amount.
return max($maxes);
}
}