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, LLMS_Student $student )

Calculates the grades for elements that have a list of children which are averaged / weighted to come up with the total grade


Parameters Parameters

$children

(array) (Required) list of child objects

$student

(LLMS_Student) (Required) A LLMS_Student object.


Top ↑

Return Return

(float|null)


Top ↑

Source Source

File: includes/class-llms-grades.php

			$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;

	}

	/**
	 * Calculate the grade for a course
	 *
	 * @param    LLMS_Course  $course  A LLMS_Course object.
	 * @param    LLMS_Student $student A LLMS_Student object.
	 * @return   float|null
	 * @since    3.24.0
	 * @version  3.24.0


Top ↑

Changelog Changelog

Changelog
Version Description
3.24.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.