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
1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 | * 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 ) { |
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. |