You are here

public function QuizResultAnswerEntityTrait::getWeightedRatio in Quiz 6.x

Same name and namespace in other branches
  1. 8.6 src/Entity/QuizResultAnswerEntityTrait.php \Drupal\quiz\Entity\QuizResultAnswerEntityTrait::getWeightedRatio()
  2. 8.5 src/Entity/QuizResultAnswerEntityTrait.php \Drupal\quiz\Entity\QuizResultAnswerEntityTrait::getWeightedRatio()

File

src/Entity/QuizResultAnswerEntityTrait.php, line 208

Class

QuizResultAnswerEntityTrait
Each question type must store its own response data and be able to calculate a score for that data.

Namespace

Drupal\quiz\Entity

Code

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();
}