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.


Top ↑

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'


Top ↑

Return Return

(boolean)


Top ↑

Source Source

File: includes/models/model.llms.student.php

			 * By default, we'll automatically delete these enrollments regardless of trigger.
			 *
			 * @since 3.33.0
			 *
			 * @param boolean $delete Whether or not to delete the enrollment.
			 */
			$delete = apply_filters( 'lifterlms_legacy_delete_enrollment_action', true );

			// Ensure we have an `$enrollment_trigger` when firing the `llms_user_enrollment_deleted` hook.
			$enrollment_trigger = $trigger;

		}

		// Delete the enrollment.
		if ( $delete && $this->delete_enrollment_postmeta( $product_id ) ) {

			// Clean the cache.
			$this->cache_delete( sprintf( 'enrollment_status_%d', $product_id ) );
			$this->cache_delete( sprintf( 'date_enrolled_%d', $product_id ) );
			$this->cache_delete( sprintf( 'date_updated_%d', $product_id ) );

			if ( 'llms_membership' === get_post_type( $product_id ) ) {
				// Physically remove from the membership level & remove enrollments data on related products.
				$this->remove_membership_level( $product_id, '', true );
			}

			/**
			 * Fires after an user enrollment has been deleted.
			 *
			 * @since 3.33.0
			 * @since 4.2.0 The `$enrollment_trigger` parameter was added.
			 *
			 * @param int    $user_id            WP User ID.
			 * @param int    $product_id         WP Post ID of the course or membership.
			 * @param string $enrollment_trigger The enrollment trigger.
			 */
			do_action( 'llms_user_enrollment_deleted', $this->get_id(), $product_id, $enrollment_trigger );

			// Success.
			return true;

		}

		// Nothing was deleted.
		return false;

	}

	/**
	 * 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.
	 *
	 * @since 3.17.0
	 * @since 4.2.0 Use filterable functions to determine if the object is completable.
	 *              Added filter to allow customization of object parent data.
	 *
	 * @param string $status      New status to update to, either "complete" or "incomplete".
	 * @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.
	 * @return bool
	 */
	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 ) {


Top ↑

Changelog 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.

Top ↑

User Contributed Notes User Contributed Notes

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