Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
LLMS_Grades::calculate_grade_from_children( array $children, obj $student )
Calculates the grades for elements that have a list of children which are averaged / weighted to come up with the total grade
Description Description
Parameters Parameters
- $children
-
(array) (Required) list of child objects
- $student
-
(obj) (Required) LLMS_Student
Return Return
(float|null)
Source Source
File: includes/class-llms-grades.php
private function calculate_grade_from_children( $children, $student ) { $grade = null; $grades = array(); // loop through all the children and compile the overall grade & points data foreach ( $children as $child_id ) { $child = llms_get_post( $child_id ); $grade = $this->get_grade( $child_id, $student, false ); // non numeric grade (null) hasn't been taken yet or no gradable elements exist on the child if ( ! is_numeric( $grade ) ) { continue; } $points = $child->get( 'points' ); // if no points assigned to the child, the grade doesn't count towards the overall grade if ( ! $points ) { continue; } // add the grade & points for further processing after we have all the data $grades[] = array( 'grade' => $grade, 'points' => $points, ); } // if we have at least one grade if ( count( $grades ) ) { // get the total available points for all children with a numeric grade & a points value $total_points = array_sum( wp_list_pluck( $grades, 'points' ) ); // if we don't have any points this element can't have an overall grade if ( $total_points ) { // sum up the adjusted grade $grade = 0; foreach ( $grades as $data ) { // calculate the adjusted the grade // grade multiplied by available points over total points $grade += $data['grade'] * ( $data['points'] / $total_points ); } } } return $grade; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.24.0 | Introduced. |
User Contributed Notes User Contributed Notes
Permalink: