You are here

public function QuizResultAnswerEntityTrait::getQuestionRelationship in Quiz 8.5

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

Get the related question relationship from this quiz result answer.

Return value

QuizQuestionRelationship

1 call to QuizResultAnswerEntityTrait::getQuestionRelationship()
QuizResultAnswerEntityTrait::getMaxScore in src/Entity/QuizResultAnswerEntityTrait.php
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…

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 getQuestionRelationship() {
  $quiz_result = QuizResult::load($this
    ->get('result_id')
    ->getString());
  $relationships = Drupal::entityTypeManager()
    ->getStorage('quiz_question_relationship')
    ->loadByProperties([
    'quiz_id' => $quiz_result
      ->get('qid')
      ->getString(),
    'quiz_vid' => $quiz_result
      ->get('vid')
      ->getString(),
    'question_id' => $this
      ->get('question_id')
      ->getString(),
    'question_vid' => $this
      ->get('question_vid')
      ->getString(),
  ]);
  if ($relationships) {
    return reset($relationships);
  }
}