LLMS_Analytics::get_lesson_completion_avg( [array] $search )

Gets completion percentage for each lesson in course


Description Description


Parameters Parameters

$search

([array]) (Required) [analytics search object]


Top ↑

Return Return

([array]) [array of arrays]


Top ↑

Source Source

File: includes/class.llms.analytics.php

	public static function get_lesson_completion_avg( $search ) {

		$lesson_completions = array();
		$all_students = 0;

		if ( ! empty( $search->lessons ) ) {
			//loop through each lesson
			foreach ( $search->lessons as $lesson ) {
				//create array and add post title
				$lesson_array = array( $lesson->post_title );

				$unit = 0;

				if ( ! empty( $search->students ) ) {

					$all_students = count( $search->students );

					//loop through each student and check if lesson is completed
					foreach ( $search->students as $student ) {

						if ( self::is_lesson_completed( $student->user_id, $lesson->ID, $search->end_date ) ) {
							$unit++;
						}
					}
				}
				if ( $all_students > 0 ) {
					//calculate completion percentage
					$completion_percent = LLMS_Number::whole_number( ( $unit / $all_students ) );
				} else {
					$completion_percent = 0;
				}

				//add unit count to lesson array
				array_push( $lesson_array, $completion_percent );

				$lesson_completions[] = $lesson_array;

			}

			return $lesson_completions;
		}// End if().

	}


Top ↑

User Contributed Notes User Contributed Notes

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