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.


Top ↑

Return Return

(float|null)


Top ↑

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

	}


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.