Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
LLMS_Student::update_completion_status( string $status, int $object_id, string $object_type, string $trigger = 'unspecified' )
Update the completion status of a track, course, section, or lesson for the current student
Description Description
Cascades up to parents and clears progress caches for parents.
Triggers actions for completion/incompletion.
Inserts / updates necessary user postmeta data.
Parameters Parameters
- $status
-
(string) (Required) New status to update to, either "complete" or "incomplete".
- $object_id
-
(int) (Required) WP_Post ID of the object.
- $object_type
-
(string) (Required) The type of object. A lesson, section, course, or course_track.
- $trigger
-
(string) (Optional) String describing the reason for the status change.
Default value: 'unspecified'
Return Return
(boolean)
Source Source
File: includes/models/model.llms.student.php
private function update_completion_status( $status, $object_id, $object_type, $trigger = 'unspecified' ) { $student_id = $this->get_id(); /** * Fires before a student's object completion status is updated. * * The dynamic portion of this hook, `$status`, refers to the new completion status of the object, * either "complete" or "incomplete" * * @since Unknown * * @param int $student_id WP_User ID of the student. * @param int $object_id WP_Post ID of the object. * @param string $object_type The type of object. A lesson, section, course, or course_track. * @param string $trigger String describing the reason for the status change. */ do_action( "before_llms_mark_{$status}", $student_id, $object_id, $object_type, $trigger ); // Retrieve an instance of the objec we're acting on. if ( in_array( $object_type, llms_get_completable_post_types(), true ) ) { $object = llms_get_post( $object_id ); } elseif ( in_array( $object_type, llms_get_completable_taxonomies(), true ) ) { $object = get_term( $object_id, $object_type ); } else { return false; } /** * Lessons have binary completion (complete or incomplete). * * Other objects are dependent on their children's statuses. These other object types * must check the combined progress of their children to see if it's complete / incomplete. */ $complete = ( 'lesson' === $object_type ) ? ( 'complete' === $status ) : ( 100 == $this->get_progress( $object_id, $object_type, false ) ); // Get parent information. $parent_data = array( 'ids' => array(), 'type' => false, ); // Get the immediate parent so we can cascade up and maybe update the parent's status. switch ( $object_type ) { case 'lesson': $parent_data['ids'] = array( $object->get( 'parent_section' ) ); $parent_data['type'] = 'section'; break; case 'section': $parent_data['ids'] = array( $object->get( 'parent_course' ) ); $parent_data['type'] = 'course'; break; case 'course': $parent_data['ids'] = wp_list_pluck( $object->get_tracks(), 'term_id' ); $parent_data['type'] = 'course_track'; break; } /** * Filter the parent data used to cascade object completion up to an object's parent(s). * * @since 4.2.0 * * @param array $parent_data { * Array of the object's parent information. * * @type int[] $ids Object ids for the parent object(s). * @type string $type Object type (course, course_track, etc...). * } * @param object $object The object. An `LLMS_Course`, for example. * @param int $ojbect_id The object's ID. * @param string $object_type The object's type. */ $parent_data = apply_filters( 'llms_mark_complete_parent_data', $parent_data, $object, $object_id, $object_type ); // Reset the cached progress for any objects with children. if ( 'lesson' !== $object_type ) { $this->set( sprintf( '%1$s_%2$d_progress', $object_type, $object_id ), '' ); } // Reset cache for all parents. if ( $parent_data['ids'] && $parent_data['type'] ) { foreach ( $parent_data['ids'] as $pid ) { $this->set( sprintf( '%1$s_%2$d_progress', $parent_data['type'], $pid ), '' ); } } // Determine if an update should be made. $update = ( 'complete' === $status && $complete ) || ( 'incomplete' === $status && ! $complete ); if ( $update ) { // Insert meta data. if ( 'complete' === $status ) { $this->insert_completion_postmeta( $object_id, $trigger ); } elseif ( 'incomplete' === $status ) { $this->insert_incompletion_postmeta( $object_id, $trigger ); } /** * Hook that fires when a student's completion status is updated for any object. * * The dynamic portion of this hook, `$status`, refers to the new completion status of the object, * either "complete" or "incomplete" * * @since Unknown * * @param int $student_id WP_User ID of the student. * @param int $object_id WP_Post ID of the object. * @param string $object_type The type of object. A lesson, section, course, or course_track. * @param string $trigger String describing the reason for the status change. */ do_action( "llms_mark_{$status}", $student_id, $object_id, $object_type, $trigger ); /** * Hook that fires when a student's completion status is updated for a specific object type. * * The dynamic portion of this hook, `$object_type` refers to the WP_Post post_type of the object * which the student's completion status is being updated for. * * The dynamic portion of this hook, `$status`, refers to the new completion status of the object, * either "complete" or "incomplete" * * @since Unknown * * @param int $student_id WP_User ID of the student. * @param int $object_id WP_Post ID of the object. */ do_action( "lifterlms_{$object_type}_{$status}d", $student_id, $object_id ); // Cascade up for parents. if ( $parent_data['ids'] && $parent_data['type'] ) { foreach ( $parent_data['ids'] as $pid ) { $this->update_completion_status( $status, $pid, $parent_data['type'], $trigger ); } } /** * Hook that fires after a student's completion status for an object and it's parents have * been updated. * * The dynamic portion of this hook, `$status`, refers to the new completion status of the object, * either "complete" or "incomplete" * * @since Unknown * * @param int $student_id WP_User ID of the student. * @param int $object_id WP_Post ID of the object. * @param string $object_type The type of object. A lesson, section, course, or course_track. * @param string $trigger String describing the reason for the status change. */ do_action( "after_llms_mark_{$status}", $student_id, $object_id, $object_type, $trigger ); } return $update; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
4.2.0 | Use filterable functions to determine if the object is completable. Added filter to allow customization of object parent data. |
3.17.0 | Introduced. |