You are here

function CourseObjectQuiz::grade in Course 6

Same name and namespace in other branches
  1. 7 modules/course_quiz/course_quiz.classes.inc \CourseObjectQuiz::grade()

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

File

modules/course_quiz/course_quiz.classes.inc, line 36

Class

CourseObjectQuiz

Code

function grade($user, $rid) {
  $nid = (int) $this
    ->getInstanceId();
  $fulfillment = $this
    ->getFulfillment();
  $result_ids = (array) $fulfillment
    ->getOption('quiz_result_ids');
  $result_ids[] = $rid;
  $fulfillment
    ->setOption('quiz_result_ids', $result_ids);
  $result = reset(quiz_get_score_data(array(
    $nid,
  ), $user->uid));
  if ($result && $result->percent_score >= $this
    ->getOption('passing_grade')) {
    $fulfillment
      ->setGrade($result->percent_score)
      ->setComplete()
      ->save();
  }
  else {
    $fulfillment
      ->setGrade($result->percent_score)
      ->save();
  }
}