You are here

public function QuizResultAnswerEntityTrait::getMaxScore in Quiz 8.6

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

Get the weighted max score of this question response. This is the score that is entered on the manage questions screen. For example if a multiple choice question is worth 4 points, but 8 points are entered on the manage questions screen, 8 points is returned here.

Return value

int The weighted max score of this question response.

5 calls to QuizResultAnswerEntityTrait::getMaxScore()
LongAnswerResponse::getFeedbackValues in question_types/quiz_long_answer/src/Plugin/quiz/QuizQuestion/LongAnswerResponse.php
Get the response part of the report form.
QuizResultAnswerEntityTrait::getReportFormScore in src/Entity/QuizResultAnswerEntityTrait.php
Implementation of getReportFormScore().
QuizResultAnswerEntityTrait::getWeightedRatio in src/Entity/QuizResultAnswerEntityTrait.php
Get the weighted score ratio.
QuizResultAnswerEntityTrait::isCorrect in src/Entity/QuizResultAnswerEntityTrait.php
Check to see if the answer is marked as correct.
ShortAnswerResponse::getFeedbackValues in question_types/quiz_short_answer/src/Plugin/quiz/QuizQuestion/ShortAnswerResponse.php
Get the response part of the report form.

File

src/Entity/QuizResultAnswerEntityTrait.php, line 107

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