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 Cascades up to parents and clears progress caches for parents Triggers actions for completion/incompletion Inserts / updates necessary user postmeta data
Description Description
Parameters Parameters
- $status
-
(string) (Required) new status to update to [complete|incomplete]
- $object_id
-
(int) (Required) WP Post ID of the lesson, section, course, or track
- $object_type
-
(string) (Required) object type [lesson|section|course|course_track]
- $trigger
-
(string) (Optional) String describing the reason for marking complete
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' ) { /** * Before hook * @action before_llms_mark_complete * @action before_llms_mark_incomplete */ do_action( 'before_llms_mark_' . $status, $this->get_id(), $object_id, $object_type, $trigger ); // can only be marked incomplete in the following post types if ( in_array( $object_type, apply_filters( 'llms_completable_post_types', array( 'course', 'lesson', 'section' ) ) ) ) { $object = llms_get_post( $object_id ); } elseif ( 'course_track' === $object_type ) { $object = get_term( $object_id, 'course_track' ); } else { return false; } // parent(s) to cascade up and check for incompletion // lessons -> section -> course -> track(s) $parent_ids = array(); $parent_type = false; // lessons are complete / incomplete automatically // other object types are dependent on their children's statuses // so the other object types need to check progress manually (bypassing cache) to see if it's complete / incomplete $complete = ( 'lesson' === $object_type ) ? ( 'complete' === $status ) : ( 100 == $this->get_progress( $object_id, $object_type, false ) ); // get the immediate parent so we can cascade up and maybe mark the parent as incomplete as well switch ( $object_type ) { case 'lesson': $parent_ids = array( $object->get( 'parent_section' ) ); $parent_type = 'section'; break; case 'section': $parent_ids = array( $object->get( 'parent_course' ) ); $parent_type = 'course'; break; case 'course': $parent_ids = wp_list_pluck( $object->get_tracks(), 'term_id' ); $parent_type = 'course_track'; break; } // 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_ids && $parent_type ) { foreach ( $parent_ids as $pid ) { $this->set( sprintf( '%1$s_%2$d_progress', $parent_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 ); } /** * Generic hook * @action llms_mark_complete * @action llms_mark_incomplete */ do_action( 'llms_mark_' . $status, $this->get_id(), $object_id, $object_type, $trigger ); /** * Specific hook * Also backwards compatible * @action lifterlms_{$object_type}_completed * @action lifterlms_{$object_type}_incompleted */ do_action( 'lifterlms_' . $object_type . '_' . $status . 'd', $this->get_id(), $object_id ); // cascade up for parents if ( $parent_ids && $parent_type ) { foreach ( $parent_ids as $pid ) { $this->update_completion_status( $status, $pid, $parent_type, $trigger ); } } /** * Generic after hook * @action after_llms_mark_complete * @action after_llms_mark_incomplete */ do_action( 'after_llms_mark_' . $status, $this->get_id(), $object_id, $object_type, $trigger ); }// End if(). return $update; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.17.0 | Introduced. |
User Contributed Notes User Contributed Notes
Permalink: