| @@ -1083,8 +1083,51 @@ | ||
| 1083 | 1083 | LP_User_Items_Result_DB::instance()->insert( $this->get_user_item_id() ); |
| 1084 | 1084 | } |
| 1085 | 1085 | |
| 1086 | 1086 | /** |
| 1087 | + * Reset course progress for the enrolled user. | |
| 1088 | + * | |
| 1089 | + * Sets status back to enrolled, graduation to in-progress, removes all child | |
| 1090 | + * items (lessons, quizzes), clears cached item data and deletes the result. | |
| 1091 | + * | |
| 1092 | + * @return void | |
| 1093 | + * @throws Exception | |
| 1094 | + * @since 4.4.5 | |
| 1095 | + * @version 1.0.0 | |
| 1096 | + */ | |
| 1097 | + public function reset_progress() { | |
| 1098 | + $this->status = self::STATUS_ENROLLED; | |
| 1099 | + $this->graduation = self::GRADUATION_IN_PROGRESS; | |
| 1100 | + $this->start_time = gmdate( LP_Datetime::$format, time() ); | |
| 1101 | + $this->end_time = null; | |
| 1102 | + $this->set_meta_value_for_key( self::META_KEY_RETAKEN_COUNT, 0 ); | |
| 1103 | + $this->save(); | |
| 1104 | + | |
| 1105 | + $courseModel = $this->get_course_model(); | |
| 1106 | + | |
| 1107 | + if ( $courseModel && $courseModel->count_items() > 0 ) { | |
| 1108 | + // Remove items' course user learned. | |
| 1109 | + $filter_remove = new LP_User_Items_Filter(); | |
| 1110 | + $filter_remove->parent_id = $this->get_user_item_id(); | |
| 1111 | + $filter_remove->user_id = $this->user_id; | |
| 1112 | + $filter_remove->limit = - 1; | |
| 1113 | + LP_User_Items_DB::getInstance()->remove_items_of_user_course( $filter_remove ); | |
| 1114 | + | |
| 1115 | + // Clean cache items. | |
| 1116 | + foreach ( $courseModel->get_section_items() as $section_items ) { | |
| 1117 | + foreach ( $section_items->items as $item ) { | |
| 1118 | + $key_cache = "userItemModel/find/{$this->user_id}/{$item->id}/{$item->type}/{$this->item_id}/" . LP_COURSE_CPT; | |
| 1119 | + $lpUserItemCache = new LP_User_Items_Cache(); | |
| 1120 | + $lpUserItemCache->clear( $key_cache ); | |
| 1121 | + } | |
| 1122 | + } | |
| 1123 | + } | |
| 1124 | + | |
| 1125 | + // Delete result in table learnpress_user_item_results. | |
| 1126 | + LP_User_Items_Result_DB::instance()->delete( $this->get_user_item_id() ); | |
| 1127 | + } | |
| 1128 | + | |
| 1129 | + /** | |
| 1087 | 1130 | * Check can impact item. |
| 1088 | 1131 | * |
| 1089 | 1132 | * @return bool|WP_Error |
| 1090 | 1133 | * @since 4.2.7.6 |