LLMS_Grades::calculate_grade( LLMS_Post_Model $post, LLMS_Student $student )
Main grade calculation function Calculates the grade for a gradable post model DOES NOT CACHE RESULTS! See get_grade() for a function which uses caching
Parameters Parameters
- $post
-
(LLMS_Post_Model) (Required) A LLMS_Post_Model object.
- $student
-
(LLMS_Student) (Required) A LLMS_Student object.
Return Return
(float|null)
Source Source
File: includes/class-llms-grades.php
public function calculate_grade( $post, $student ) {
$grade = null;
$post_type = $post->get( 'type' );
switch ( $post_type ) {
case 'course':
/** @var LLMS_Course $post */
$grade = $this->calculate_course_grade( $post, $student );
break;
case 'lesson':
/** @var LLMS_Lesson $post */
$grade = $this->calculate_lesson_grade( $post, $student );
break;
case 'llms_quiz':
$attempt = $student->quizzes()->get_best_attempt( $post->get( 'id' ) );
if ( $attempt ) {
$grade = $attempt->get( 'grade' );
}
break;
// 3rd party / custom element grading.
default:
$grade = apply_filters( 'llms_calculate_' . $post_type . '_grade', $grade, $post, $student );
}
// Round numeric results.
if ( is_numeric( $grade ) ) {
$grade = $this->round( $grade );
}
return apply_filters( 'llms_calculate_grade', $grade, $post, $student );
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 3.24.0 | Introduced. |