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.
Parameters Parameters
- $args
-
(array) (Required) Query arguments passed to LLMS_Student_Query.
Return Return
(boolean) Always returns false
to remove the item from the queue when processing is complete.
Source Source
File: includes/processors/class.llms.processor.course.data.php
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | 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() ); } |
Expand full source code Collapse full source code View on GitHub
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. |