You are here

public function TrueFalseResponse::score in Quiz 6.x

Same name and namespace in other branches
  1. 8.6 question_types/quiz_truefalse/src/Plugin/quiz/QuizQuestion/TrueFalseResponse.php \Drupal\quiz_truefalse\Plugin\quiz\QuizQuestion\TrueFalseResponse::score()
  2. 8.5 question_types/quiz_truefalse/src/Plugin/quiz/QuizQuestion/TrueFalseResponse.php \Drupal\quiz_truefalse\Plugin\quiz\QuizQuestion\TrueFalseResponse::score()

Calculate the unscaled score in points for this question response.

Parameters

array $values: A part of form state values with the question input from the user.

Return value

int|NULL The unscaled point value of the answer. If a point value is final, questions should make sure to run setEvaluated(). return NULL if the answer is not automatically scored.

Overrides QuizAnswerInterface::score

File

question_types/quiz_truefalse/src/Plugin/quiz/QuizQuestion/TrueFalseResponse.php, line 17

Class

TrueFalseResponse
Extension of QuizQuestionResponse.

Namespace

Drupal\quiz_truefalse\Plugin\quiz\QuizQuestion

Code

public function score(array $response) : ?int {
  $tfQuestion = $this
    ->getQuizQuestion();
  $this
    ->set('truefalse_answer', $response['answer']);
  $this
    ->setEvaluated();
  if ($response['answer'] == $tfQuestion
    ->getCorrectAnswer()) {
    return $tfQuestion
      ->getMaximumScore();
  }
  else {
    return 0;
  }
}