You are here

public function QuizResultAnswerEntityTrait::getMaxScore in Quiz 6.x

Same name and namespace in other branches
  1. 8.6 src/Entity/QuizResultAnswerEntityTrait.php \Drupal\quiz\Entity\QuizResultAnswerEntityTrait::getMaxScore()
  2. 8.5 src/Entity/QuizResultAnswerEntityTrait.php \Drupal\quiz\Entity\QuizResultAnswerEntityTrait::getMaxScore()
5 calls to QuizResultAnswerEntityTrait::getMaxScore()
LongAnswerResponse::getFeedbackValues in question_types/quiz_long_answer/src/Plugin/quiz/QuizQuestion/LongAnswerResponse.php
QuizResultAnswerEntityTrait::getReportFormScore in src/Entity/QuizResultAnswerEntityTrait.php
Implementation of getReportFormScore().
QuizResultAnswerEntityTrait::getWeightedRatio in src/Entity/QuizResultAnswerEntityTrait.php
QuizResultAnswerEntityTrait::isCorrect in src/Entity/QuizResultAnswerEntityTrait.php
ShortAnswerResponse::getFeedbackValues in question_types/quiz_short_answer/src/Plugin/quiz/QuizQuestion/ShortAnswerResponse.php

File

src/Entity/QuizResultAnswerEntityTrait.php, line 83

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 getMaxScore() : int {
  $quiz = $this
    ->getQuizResult()
    ->getQuiz();
  if ($quiz
    ->get('randomization')
    ->getString() == 2) {
    return (int) $quiz
      ->get('max_score_for_random')
      ->getString();
  }
  if ($quiz
    ->get('randomization')
    ->getString() == 3) {

    /* @var $terms Drupal\paragraphs\Entity\Paragraph[] */
    $terms = $quiz
      ->get('quiz_terms')
      ->referencedEntities();
    $total_questions = [];
    foreach ($terms as $term) {
      if ($term
        ->get('quiz_question_tid')
        ->getString() == $this
        ->get('tid')
        ->getString()) {
        return $term
          ->get('quiz_question_max_score')
          ->getString();
      }
    }
  }
  if ($relationship = $this
    ->getQuestionRelationship()) {
    return (int) $relationship
      ->get('max_score')
      ->getString();
  }
}