LLMS_Grades::calculate_grade( obj $post, obj $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


Description Description


Parameters Parameters

$post

(obj) (Required) LLMS_Post_Model

$student

(obj) (Required) LLMS_Student


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':
				$grade = $this->calculate_course_grade( $post, $student );
			break;

			case 'lesson':
				$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.





Permalink: