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 +62 -27 4.1.7.2 → 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 );
@@ -190,9 +198,9 @@
190 198 }
191 199
192 200 /**
193 201 * @return LP_User_Item|bool
194 - * @depecated 4.1.6.9.2
202 + * @deprecated 4.1.6.9.2
195 203 */
196 204 /*public function get_viewing_item() {
197 205 $item = LP_Global::course_item();
198 206 if ( $item ) {
@@ -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 }
@@ -383,9 +421,9 @@
383 421 *
384 422 * @param string $context
385 423 *
386 424 * @return string
387 - * @depecated 4.1.6.9.3
425 + * @deprecated 4.1.6.9.3
388 426 */
389 427 public function get_grade( string $context = '' ): string {
390 428 $grade = $this->get_graduation() ?? '';
391 429
@@ -629,9 +667,9 @@
629 667 continue;
630 668 }
631 669
632 670 if ( $item->type == LP_QUIZ_CPT ) {
633 - $total_questions += count( $itemObj->get_questions() );
671 + $total_questions += count( $itemObj->get_question_ids() );
634 672 $total_mark_question += $itemObj->get_mark();
635 673 }
636 674 }
637 675 }
@@ -693,9 +731,9 @@
693 731 return $level;
694 732 }
695 733
696 734 /**
697 - * @depecated 4.1.6.9.2
735 + * @deprecated 4.1.6.9.2
698 736 */
699 737 /*protected function _is_passed( $result ) {
700 738 $is_passed = LP_COURSE_GRADUATION_FAILED;
701 739 $result = round( $result, 2 );
@@ -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 {
@@ -896,9 +931,9 @@
896 931 }
897 932
898 933 /**
899 934 * @return bool
900 - * @depecated 4.1.6.9.2
935 + * @deprecated 4.1.6.9.2
901 936 */
902 937 /*public function can_graduated() {
903 938 return $this->get_results( 'result' ) >= $this->get_passing_condition();
904 939 }*/
@@ -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
@@ -995,10 +1030,12 @@
995 1030 /**
996 1031 * Update course item and it's child.
997 1032 *
998 1033 * @TODO: tungnx - review to modify
1034 + * @deprecated 4.1.7.3
999 1035 */
1000 1036 public function save() {
1037 + _deprecated_function( __METHOD__, '4.1.7.3' );
1001 1038 /**
1002 1039 * @var LP_User_Item $item
1003 1040 */
1004 1041 $this->update();
@@ -1007,18 +1044,16 @@
1007 1044 return false;
1008 1045 }
1009 1046
1010 1047 foreach ( $items as $item_id => $item ) {
1011 -
1012 1048 if ( ! $item->get_status() ) {
1013 1049 continue;
1014 1050 }
1015 1051
1016 1052 /**
1017 - * Auto fill the end-time if it isn't already set
1053 + * Autofill the end-time if it isn't already set
1018 1054 */
1019 1055 if ( in_array( $item->get_status(), array( 'completed', 'finished' ) ) ) {
1020 -
1021 1056 if ( ! $item->get_end_time() || $item->get_end_time()->is_null() ) {
1022 1057 $item->set_end_time( current_time( 'mysql', 1 ) );
1023 1058 }
1024 1059 }
@@ -1036,9 +1071,9 @@
1036 1071 * @param bool $with_total - Optional. Include total if TRUE
1037 1072 * @param int $section_id - Optional. Get in specific section
1038 1073 *
1039 1074 * @return array|bool|mixed
1040 - * @depecated 4.1.6.9
1075 + * @deprecated 4.1.6.9
1041 1076 */
1042 1077 public function get_passed_items( $type = '', $with_total = false, $section_id = 0 ) {
1043 1078 _deprecated_function( __FUNCTION__, '4.1.6.9' );
1044 1079 $this->read_items();
@@ -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