LLMS_Student::get_progress( int $object_id, string $type = 'course', boolean $use_cache = true )
Get students progress through a course or track
Parameters Parameters
- $object_id
-
(int) (Required) course or track id
- $type
-
(string) (Optional) object type [course|course_track|section]
Default value: 'course'
- $use_cache
-
(boolean) (Optional) if true, will use cached data from the usermeta table (if available) if false, will bypass cached data and recalculate the progress from scratch
Default value: true
Return Return
(float)
Source Source
File: includes/models/model.llms.student.php
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 | $orders = array (); if ( $q ->have_posts() ) { foreach ( $q ->posts as $post ) { $orders [ $post ->ID ] = new LLMS_Order( $post ); } } return array ( 'count' => count ( $q ->posts ), 'page' => $page , 'pages' => $q ->max_num_pages, 'orders' => $orders , ); } /** * Get students progress through a course or track * * @param int $object_id course or track id * @param string $type object type [course|course_track|section] * @param boolean $use_cache if true, will use cached data from the usermeta table (if available) * if false, will bypass cached data and recalculate the progress from scratch * @return float * @since 3.0.0 * @version 3.24.0 */ public function get_progress( $object_id , $type = 'course' , $use_cache = true ) { $ret = 0; $cache_key = sprintf( '%1$s_%2$d_progress' , $type , $object_id ); $cached = $use_cache ? $this ->get( $cache_key ) : '' ; if ( '' === $cached ) { $total = 0; $completed = 0; if ( 'course' === $type ) { $course = new LLMS_Course( $object_id ); $lessons = $course ->get_lessons( 'ids' ); $total = count ( $lessons ); foreach ( $lessons as $lesson ) { if ( $this ->is_complete( $lesson , 'lesson' ) ) { $completed ++; } } } elseif ( 'course_track' === $type ) { $track = new LLMS_Track( $object_id ); $courses = $track ->get_courses(); $total = count ( $courses ); foreach ( $courses as $course ) { if ( $this ->is_complete( $course ->ID, 'course' ) ) { $completed ++; } } } elseif ( 'section' === $type ) { |
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |