| @@ -6,8 +6,13 @@ | ||
| 6 | 6 | * @package LearnPress/Classes |
| 7 | 7 | * @version 3.0.0 |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | +use LearnPress\Models\CourseModel; | |
| 11 | +use LearnPress\Models\UserItems\UserCourseModel; | |
| 12 | +use LearnPress\Models\UserItems\UserItemModel; | |
| 13 | +use LearnPress\Models\UserModel; | |
| 14 | + | |
| 10 | 15 | defined( 'ABSPATH' ) || exit(); |
| 11 | 16 | |
| 12 | 17 | if ( ! class_exists( 'LP_Course_Item' ) ) { |
| 13 | 18 | /** |
| @@ -149,49 +154,19 @@ | ||
| 149 | 154 | |
| 150 | 155 | /** |
| 151 | 156 | * Get class of item. |
| 152 | 157 | * |
| 153 | - * @param string $more | |
| 154 | - * @param int $user_id | |
| 158 | + * @param $course_id | |
| 159 | + * @param $item_id | |
| 160 | + * @param $can_view_item | |
| 161 | + * @param $more | |
| 155 | 162 | * |
| 156 | - * @return array | |
| 163 | + * @return array|mixed|null | |
| 164 | + * @since 4.1.4.2 | |
| 165 | + * @version 1.0.1 | |
| 157 | 166 | */ |
| 158 | - public function get_class( $more = '', $user_id = 0 ) { | |
| 159 | - $course_id = get_the_ID(); | |
| 160 | - | |
| 161 | - if ( empty( $GLOBALS['get_class'] ) ) { | |
| 162 | - $GLOBALS['get_class'] = 0; | |
| 163 | - } | |
| 164 | - | |
| 165 | - $user_id = $user_id ? $user_id : get_current_user_id(); | |
| 166 | - $t = microtime( true ); | |
| 167 | - $classes = LP_Object_Cache::get( 'item-' . $user_id . '-' . $this->get_id(), 'learn-press/post-classes' ); | |
| 168 | - | |
| 169 | - if ( false === $classes ) { | |
| 170 | - $curd = new LP_User_Item_CURD(); | |
| 171 | - $all_items = $curd->parse_items_classes( $course_id, $user_id, $more ); | |
| 172 | - | |
| 173 | - $classes = ! empty( $all_items[ $this->get_id() ] ) ? $all_items[ $this->get_id() ] : $defaults = array( | |
| 174 | - 'course-item', | |
| 175 | - 'course-item-' . $this->get_item_type(), | |
| 176 | - 'course-item-' . $this->get_id(), | |
| 177 | - ); | |
| 178 | - } | |
| 179 | - | |
| 180 | - $GLOBALS['get_class'] += microtime( true ) - $t; | |
| 181 | - | |
| 182 | - return apply_filters( | |
| 183 | - 'learn-press/course-item-class-cached', | |
| 184 | - $classes, | |
| 185 | - $this->get_item_type(), | |
| 186 | - $this->get_id(), | |
| 187 | - $course_id | |
| 188 | - ); | |
| 189 | - } | |
| 190 | - | |
| 191 | 167 | public function get_class_v2( $course_id, $item_id, $can_view_item, $more = array() ) { |
| 192 | - $course = learn_press_get_course( $course_id ); | |
| 193 | - | |
| 168 | + $course = CourseModel::find( $course_id, true ); | |
| 194 | 169 | if ( ! $course ) { |
| 195 | 170 | return $more; |
| 196 | 171 | } |
| 197 | 172 | |
| @@ -203,18 +178,15 @@ | ||
| 203 | 178 | ), |
| 204 | 179 | (array) $more |
| 205 | 180 | ); |
| 206 | 181 | |
| 207 | - $user = learn_press_get_user( get_current_user_id() ); | |
| 182 | + $user_id = get_current_user_id(); | |
| 183 | + $user = UserModel::find( $user_id, true ); | |
| 208 | 184 | |
| 209 | - if ( ! $user ) { | |
| 210 | - return $defaults; | |
| 211 | - } | |
| 185 | + $userCourseModel = UserCourseModel::find( $user_id, $course_id, true ); | |
| 186 | + $enrolled = $user && $userCourseModel && $userCourseModel->has_enrolled_or_finished(); | |
| 187 | + $no_required_enroll = $course->has_no_enroll_requirement(); | |
| 212 | 188 | |
| 213 | - $is_free = $course->is_free(); | |
| 214 | - $enrolled = $user->has_enrolled_or_finished( $course_id ); | |
| 215 | - $no_required_enroll = $course->is_no_required_enroll(); | |
| 216 | - | |
| 217 | 189 | $post_format = $this->get_format(); |
| 218 | 190 | if ( 'standard' !== $post_format && $post_format ) { |
| 219 | 191 | $defaults[] = 'course-item-type-' . $post_format; |
| 220 | 192 | } |
| @@ -220,9 +192,11 @@ | ||
| 220 | 192 | } |
| 221 | 193 | |
| 222 | 194 | if ( $no_required_enroll ) { |
| 223 | 195 | $defaults[] = 'item-free'; |
| 224 | - } elseif ( ! $enrolled ) { | |
| 196 | + } | |
| 197 | + | |
| 198 | + if ( ! $enrolled ) { | |
| 225 | 199 | $defaults['item-locked'] = 'item-locked'; |
| 226 | 200 | |
| 227 | 201 | if ( $this->is_preview() ) { |
| 228 | 202 | $defaults['item-preview'] = 'item-preview'; |
| @@ -231,10 +205,18 @@ | ||
| 231 | 205 | } |
| 232 | 206 | } elseif ( ! $can_view_item->flag ) { |
| 233 | 207 | $defaults[] = 'item-locked'; |
| 234 | 208 | } else { |
| 235 | - $item_status = $user->get_item_status( $item_id, $course_id ); | |
| 236 | - $item_grade = $user->get_item_grade( $item_id, $course_id ); | |
| 209 | + $userItemModel = UserItemModel::find_user_item( | |
| 210 | + $user_id, | |
| 211 | + $item_id, | |
| 212 | + get_post_type( $item_id ), | |
| 213 | + $course_id, | |
| 214 | + LP_COURSE_CPT, | |
| 215 | + true | |
| 216 | + ); | |
| 217 | + $item_status = $userItemModel ? $userItemModel->get_status() : ''; | |
| 218 | + $item_grade = $userItemModel ? $userItemModel->get_graduation() : ''; | |
| 237 | 219 | |
| 238 | 220 | if ( $item_status ) { |
| 239 | 221 | $defaults[] = 'has-status'; |
| 240 | 222 | $defaults[] = 'status-' . $item_status; |
| @@ -441,9 +423,9 @@ | ||
| 441 | 423 | // $lp_course_cache->set_cache( $key_cache, $item ); |
| 442 | 424 | } |
| 443 | 425 | } |
| 444 | 426 | |
| 445 | - return apply_filters( 'learn-press/get-course-item', $item, $item_type, $item_id ); | |
| 427 | + return $item; | |
| 446 | 428 | } |
| 447 | 429 | |
| 448 | 430 | /** |
| 449 | 431 | * Get template name of item. |