function CourseObjectQuiz::grade in Course 7
Same name and namespace in other branches
- 6 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 32
Class
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('instance', $rid);
$fulfillment
->setOption('quiz_result_ids', $result_ids);
$result = quiz_result_load($rid);
if ($result && $result->score >= $this
->getOption('passing_grade')) {
$fulfillment
->setGrade($result->score)
->setComplete()
->save();
}
else {
$fulfillment
->setGrade($result->score)
->save();
}
}