You are here

function CourseObjectQuizFulfillment::grade in Course 8.3

Same name and namespace in other branches
  1. 8.2 modules/course_quiz/src/Plugin/course/CourseObject/CourseObjectQuizFulfillment.php \Drupal\course_quiz\Plugin\course\CourseObject\CourseObjectQuizFulfillment::grade()
  2. 3.x modules/course_quiz/src/Plugin/course/CourseObject/CourseObjectQuizFulfillment.php \Drupal\course_quiz\Plugin\course\CourseObject\CourseObjectQuizFulfillment::grade()

Marks a user's fulfillment record for this object complete if the user passed the quiz.

File

modules/course_quiz/src/Plugin/course/CourseObject/CourseObjectQuizFulfillment.php, line 34

Class

CourseObjectQuizFulfillment
Course fulfillment class for quizzes.

Namespace

Drupal\course_quiz\Plugin\course\CourseObject

Code

function grade(QuizResult $quiz_result) {

  // Store the result ID.
  $result_ids = (array) $this
    ->getOption('quiz_result_ids');
  $result_ids[] = $quiz_result
    ->id();
  $this
    ->setOption('instance', $quiz_result
    ->id());
  $this
    ->setOption('quiz_result_ids', $result_ids);
  if ($quiz_result && $quiz_result
    ->get('score')
    ->getString() >= $this
    ->getCourseObject()
    ->getOption('passing_grade')) {
    $this
      ->setGrade($quiz_result
      ->get('score')
      ->getString())
      ->setComplete()
      ->save();
  }
  else {
    $this
      ->setGrade($quiz_result
      ->get('score')
      ->getString())
      ->save();
  }
}