LLMS_Student::get_overall_grade( boolean $use_cache = true )
Retrieve the student’s overall grade Grade = sum of grades for all courses divided by number of enrolled courses if a course has no quizzes in it, it cannot be graded and is therefore excluded from the calculation
Description Description
cached data is automatically cleared when a student completes a quiz
Parameters Parameters
- $use_cache
-
(boolean) (Optional) if false, calculates the grade, otherwise utilizes cached data (if available)
Default value: true
Return Return
(float|string) grade as float or "N/A"
Source Source
File: includes/models/model.llms.student.php
public function get_overall_grade( $use_cache = true ) { $grade = null; // attempt to pull from the cache first if ( $use_cache ) { $grade = $this->get( $this->meta_prefix . 'overall_grade' ); if ( is_numeric( $grade ) ) { $grade = floatval( $grade ); } } // cache disabled or no cached data available if ( ! $use_cache || null === $grade || '' === $grade ) { $grades = array(); // get courses $courses = $this->get_courses( array( 'limit' => 9999, ) ); // loop through courses foreach ( $courses['results'] as $course_id ) { // get course grade $g = $this->get_grade( $course_id ); // if an actual grade (not N/A) is returned if ( is_numeric( $g ) ) { array_push( $grades, $g ); } } // if we have at least one grade $count = count( $grades ); if ( $count ) { $grade = round( array_sum( $grades ) / $count, 2 ); } else { $grade = _x( 'N/A', 'overall grade when no quizzes', 'lifterlms' ); } // cache the grade $this->set( 'overall_grade', $grade ); }// End if(). return apply_filters( 'llms_student_get_overall_grade', $grade, $this ); }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.2.0 | Introduced. |
User Contributed Notes User Contributed Notes
Permalink: