PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9
4.4.9 4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 All 140 releases
← All changes | inc/user-item/class-lp-user-item-course.php +53 -18 4.1.7.3 → 4.4.9 View file →
@@ -1,10 +1,14 @@
1 1 <?php
2 +
3 +use LearnPress\Filters\UserItemsFilter;
4 +use LearnPress\Models\UserItems\UserCourseModel;
5 +
2 6 /**
3 7 * Class LP_User_Item_Course
4 8 */
5 9
6 -class LP_User_Item_Course extends LP_User_Item implements ArrayAccess {
10 +class LP_User_Item_Course extends LP_User_Item {
7 11 public $_item_type = LP_COURSE_CPT;
8 12 public $_ref_type = LP_ORDER_CPT;
9 13
10 14 /**
@@ -153,10 +157,14 @@
153 157 public function get_course_id() {
154 158 return $this->get_data( 'item_id' );
155 159 }
156 160
161 + /**
162 + * @deprecated 4.1.7.3
163 + */
157 164 public function get_finishing_type() {
158 - $type = $this->get_meta( 'finishing_type' );
165 + _deprecated_function( __METHOD__, '4.1.7.3' );
166 + /*$type = $this->get_meta( 'finishing_type' );
159 167
160 168 if ( ! $type ) {
161 169 $type = $this->is_exceeded() <= 0 ? 'exceeded' : 'click';
162 170
@@ -164,9 +172,9 @@
164 172
165 173 $this->set_meta( 'finishing_type', $type );
166 174 }
167 175
168 - return $type;
176 + return $type;*/
169 177 }
170 178
171 179 public function offsetSet( $offset, $value ) {
172 180 // $this->set_data( $offset, $value );
@@ -280,8 +288,31 @@
280 288 /**
281 289 * Calculate course result
282 290 */
283 291 public function calculate_course_results( bool $force_cache = false ) {
292 + $results = array(
293 + 'count_items' => 0,
294 + 'completed_items' => 0,
295 + 'items' => array(),
296 + 'evaluate_type' => '',
297 + 'pass' => 0,
298 + 'result' => 0,
299 + );
300 +
301 + try {
302 + $userCourseModel = UserCourseModel::find( $this->get_user_id(), $this->get_course_id(), true );
303 + if ( ! $userCourseModel instanceof UserCourseModel ) {
304 + return $results;
305 + }
306 +
307 + $results = $userCourseModel->calculate_course_results();
308 + } catch ( Throwable $e ) {
309 + LP_Debug::error_log( $e );
310 + }
311 +
312 + return $results;
313 +
314 + // Code old
284 315 $items = array();
285 316 $results = array(
286 317 'count_items' => 0,
287 318 'completed_items' => 0,
@@ -311,12 +342,19 @@
311 342 // Todo: tungnx - set cache
312 343 return LP_User_Items_Result_DB::instance()->get_result( $this->get_user_item_id() );
313 344 }
314 345
346 + if ( $this->get_status() !== LP_COURSE_ENROLLED ) {
347 + return $results;
348 + }
349 +
315 350 $count_items = $course->count_items();
316 351 $count_items_completed = $this->count_items_completed();
317 352
318 - $evaluate_type = $course->get_data( 'course_result', 'evaluate_lesson' );
353 + $evaluate_type = get_post_meta( $course->get_id(), '_lp_course_result', true );
354 + if ( ! $evaluate_type ) {
355 + $evaluate_type = 'evaluate_lesson';
356 + }
319 357 switch ( $evaluate_type ) {
320 358 case 'evaluate_lesson':
321 359 $results_evaluate = $this->evaluate_course_by_lesson( $count_items_completed, $course->count_items( LP_LESSON_CPT ) );
322 360 break;
@@ -371,9 +409,9 @@
371 409 );
372 410
373 411 LP_Cache::cache_load_first( 'set', $key_first_cache, $results );
374 412 } catch ( Throwable $e ) {
375 -
413 + error_log( __METHOD__ . ': ' . $e->getMessage() );
376 414 }
377 415
378 416 return $results;
379 417 }
@@ -769,9 +807,9 @@
769 807 }
770 808
771 809 if ( $type === $item_type ) {
772 810 if ( $item->get_status() == 'completed' ) {
773 - $completed ++;
811 + ++$completed;
774 812 }
775 813 $completed = apply_filters(
776 814 'learn-press/course-item/completed',
777 815 $completed,
@@ -778,9 +816,9 @@
778 816 $item,
779 817 $item->get_status()
780 818 );
781 819 // if ( ! $item->is_preview() ) {
782 - $total ++;
820 + ++$total;
783 821 // }
784 822 }
785 823 }
786 824 }
@@ -805,17 +843,15 @@
805 843 $count_items_completed = new stdClass();
806 844
807 845 try {
808 846 $course = learn_press_get_course( $this->get_course_id() );
809 -
810 847 if ( ! $course ) {
811 - throw new Exception( __FUNCTION__ . ': Course is invalid!' );
848 + throw new Exception( 'Course is invalid!' );
812 849 }
813 850
814 851 $user_course = $this->get_last_user_course();
815 -
816 852 if ( ! $user_course ) {
817 - throw new Exception();
853 + throw new Exception( 'User course is invalid!' );
818 854 }
819 855
820 856 $filter_count = new LP_User_Items_Filter();
821 857 $filter_count->parent_id = $user_course->user_item_id;
@@ -824,9 +860,9 @@
824 860 $filter_count->status = 'completed';
825 861 $filter_count->graduation = LP_COURSE_GRADUATION_PASSED;
826 862 $count_items_completed = $lp_user_items_db->count_items_of_course_with_status( $filter_count );
827 863 } catch ( Throwable $e ) {
828 -
864 + error_log( __METHOD__ . ': ' . $e->getMessage() );
829 865 }
830 866
831 867 return $count_items_completed;
832 868 }
@@ -877,9 +913,8 @@
877 913 /**
878 914 * Check course is completed or not.
879 915 *
880 916 * @return bool
881 - * @throws Exception
882 917 * @editor tungnx
883 918 * @modify 4.1.3
884 919 */
885 920 public function is_finished(): bool {
@@ -986,9 +1021,9 @@
986 1021 * @return bool|int
987 1022 */
988 1023 public function increase_retake_count() {
989 1024 $count = $this->get_retaken_count();
990 - $count ++;
1025 + ++$count;
991 1026
992 1027 return $this->update_meta( '_lp_retaken_count', $count );
993 1028 }
994 1029
@@ -1082,9 +1117,9 @@
1082 1117 }
1083 1118
1084 1119 if ( $type === $item_type ) {
1085 1120 if ( $item->get_status( 'graduation' ) == 'passed' ) {
1086 - $passed ++;
1121 + ++$passed;
1087 1122 }
1088 1123 $passed = apply_filters(
1089 1124 'learn-press/course-item/passed',
1090 1125 $passed,
@@ -1091,9 +1126,9 @@
1091 1126 $item,
1092 1127 $item->get_status()
1093 1128 );
1094 1129 // if ( ! $item->is_preview() ) {
1095 - $total ++;
1130 + ++$total;
1096 1131 // }
1097 1132 }
1098 1133 }
1099 1134 }
@@ -1157,14 +1192,14 @@
1157 1192
1158 1193 /**
1159 1194 * Get courses only by course's user are learning
1160 1195 *
1161 - * @param LP_User_Items_Filter $filter
1196 + * @param LP_User_Items_Filter|UserItemsFilter $filter
1162 1197 * @param int $total_rows return total row query
1163 1198 *
1164 1199 * @return array|null|int|string
1165 1200 */
1166 - public static function get_user_courses( LP_User_Items_Filter $filter, int &$total_rows = 0 ) {
1201 + public static function get_user_courses( $filter, int &$total_rows = 0 ) {
1167 1202 try {
1168 1203 /*$key_cache = md5( json_encode( $filter ) );
1169 1204 $courses_cache = LP_Cache::instance()->get_cache( $key_cache );
1170 1205