LLMS_Processor_Course_Data::task_complete( LLMS_Course $course, array $data, boolean $last_page )

Complete a task

Description Description

Stores the current (incomplete) array of course data on the postmeta table for use by the next task in the queue.

Upon completion, uses the data array to calculate the final aggregate values and store them on the postmeta table for the course for quick retrieval later.

Top ↑

Parameters Parameters


(LLMS_Course) (Required) Course object.


(array) (Required) Aggregate calculation data array.


(boolean) (Required) Whether or not this is the last page set of students for the process.

Top ↑

Return Return

(boolean) Always returns false.

Top ↑

Source Source

File: includes/processors/class.llms.processor.course.data.php

	protected function task_complete( $course, $data, $last_page ) {

		$this->log( sprintf( 'Course data calculation task completed for course %1$d with data: %2$s', $course->get( 'id' ), wp_json_encode( $data ) ) );

		// Save our work on the last run.
		if ( $last_page ) {

			// Calculate.
			$grade    = $data['quizzes'] ? round( $data['grade'] / $data['quizzes'], 2 ) : 0;
			$progress = $data['students'] ? round( $data['progress'] / $data['students'], 2 ) : 0;

			// Save the data to the course.
			$course->set( 'average_grade', $grade );
			$course->set( 'average_progress', $progress );
			$course->set( 'enrolled_students', $data['students'] );
			$course->set( 'last_data_calc_run', time() );

			// Delete the temporary data so its fresh for next time.
			delete_post_meta( $course->get( 'id' ), '_llms_temp_calc_data' );

			// Unlock the course.
			delete_post_meta( $course->get( 'id' ), '_llms_temp_calc_data_lock' );

			$this->log( sprintf( 'Course data calculation completed for course %d.', $course->get( 'id' ) ) );

		} else {

			// Save temporary data so it can be used by the next run in the process.
			$course->set( 'temp_calc_data', $data );


		return false;


Top ↑

Changelog Changelog

Version Description
4.16.0 Fix log string to properly log the course id.
4.12.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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