LLMS_Processor_Course_Data::task( array $args )

Execute calculation for each item in the queue until all students in the course have been polled


Description Description

Stores the data in the postmeta table to be accessible via LLMS_Course.


Top ↑

Parameters Parameters

$args

(array) (Required) Query arguments passed to LLMS_Student_Query.


Top ↑

Return Return

(boolean) Always returns false to remove the item from the queue when processing is complete.


Top ↑

Source Source

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

	public function task( $args ) {

		$this->log( sprintf( 'Course data calculation task called for course %1$d with args: %2$s', $args['post_id'], wp_json_encode( $args ) ) );

		$course = llms_get_post( $args['post_id'] );

		// Only process existing courses.
		if ( ! $course instanceof LLMS_Course ) {
			$this->log( sprintf( 'Course data calculation task skipped for course %1$d.', $args['post_id'] ) );
			return false;
		}

		// Lock the course against duplicate processing.
		$course->set( 'temp_calc_data_lock', 'yes' );

		// Get saved data or empty array when on first page.
		$data = ( 1 !== $args['page'] ) ? $course->get( 'temp_calc_data' ) : array();

		// Merge with the defaults.
		$data = $this->get_task_data( $data );

		// Perform the query.
		$query = new LLMS_Student_Query( $args );

		foreach ( $query->get_students() as $student ) {

			// Progress, all students counted here.
			$data['students']++;
			$data['progress'] = $data['progress'] + $student->get_progress( $args['post_id'] );

			// Grades only counted when a student has taken a quiz.
			// If a student hasn't taken it, we don't count it as a 0 on the quiz.
			$grade = $student->get_grade( $args['post_id'] );

			// Only check actual quiz grades.
			if ( is_numeric( $grade ) ) {
				$data['quizzes']++;
				$data['grade'] = $data['grade'] + $grade;
			}
		}

		return $this->task_complete( $course, $data, $query->is_last_page() );

	}


Top ↑

Changelog Changelog

Changelog
Version Description
4.21.0 Use get_task_data() to merge/retrieve aggregate task data. Return early for non-courses.
4.16.0 Fix log string to properly record the post_id.
4.12.0 Moved task completion logic to task_complete().
3.15.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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