public function QuizResultAnswerEntityTrait::getWeightedRatio in Quiz 8.6
Same name and namespace in other branches
- 8.5 src/Entity/QuizResultAnswerEntityTrait.php \Drupal\quiz\Entity\QuizResultAnswerEntityTrait::getWeightedRatio()
- 6.x src/Entity/QuizResultAnswerEntityTrait.php \Drupal\quiz\Entity\QuizResultAnswerEntityTrait::getWeightedRatio()
Get the weighted score ratio.
This returns the ratio of the weighted score of this question versus the question score. For example, if the question is worth 10 points in the associated quiz, but it is a 3 point multichoice question, the weighted ratio is 3.33.
This is marked as final to make sure that no question overrides this and causes reporting issues.
Return value
float The weight of the question
File
- src/
Entity/ QuizResultAnswerEntityTrait.php, line 294
Class
- QuizResultAnswerEntityTrait
- Each question type must store its own response data and be able to calculate a score for that data.
Namespace
Drupal\quiz\EntityCode
public function getWeightedRatio() {
if ($this
->getMaxScore() == 0) {
return 0;
}
// getMaxScore() will get the relationship max score.
// getMaximumScore() gets the unscaled question max score.
return $this
->getMaxScore() / $this
->getQuizQuestion()
->getMaximumScore();
}