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/templates/class-lp-template-course.php +249 -377 4.1.6.9.3 → 4.4.9 View file →
@@ -1,6 +1,14 @@
1 1 <?php
2 2
3 +use LearnPress\Helpers\Template;
4 +use LearnPress\Models\CourseModel;
5 +use LearnPress\Models\UserItems\UserCourseModel;
6 +use LearnPress\Models\UserModel;
7 +use LearnPress\TemplateHooks\Course\SingleCourseModernLayout;
8 +use LearnPress\TemplateHooks\Course\SingleCourseTemplate;
9 +use LearnPress\TemplateHooks\UserItem\UserCourseTemplate;
10 +
3 11 /**
4 12 * Class LP_Course_Template
5 13 *
6 14 * Groups templates related course and items
@@ -7,9 +15,8 @@
7 15 *
8 16 * @since 3.x.x
9 17 */
10 18 class LP_Template_Course extends LP_Abstract_Template {
11 -
12 19 /**
13 20 * @var LP_Course
14 21 */
15 22 public $course = null;
@@ -19,9 +26,9 @@
19 26 */
20 27 public function __construct() {
21 28 parent::__construct();
22 29
23 - add_action( 'the_post', array( $this, 'get_course' ), 1000 );
30 + add_action( 'the_post', array( $this, 'get_course' ) );
24 31 }
25 32
26 33 public function get_course() {
27 34 // global $post;
@@ -33,8 +40,10 @@
33 40 learn_press_get_template( 'single-course/sidebar/preview' );
34 41 }
35 42
36 43 public function course_buttons() {
44 + global $lp_user;
45 + $lp_user = learn_press_get_current_user();
37 46 learn_press_get_template( 'single-course/buttons' );
38 47 }
39 48
40 49 public function course_graduation() {
@@ -58,12 +67,17 @@
58 67 * Show button retry course
59 68 *
60 69 * @throws Exception
61 70 */
62 - public function button_retry() {
63 - $user = learn_press_get_current_user();
64 - $course = learn_press_get_course();
71 + public function button_retry( $course = null ) {
72 + _deprecated_function( __METHOD__, '4.3.2.4', 'UserCourseTemplate::html_btn_retake' );
73 + return;
65 74
75 + $user = learn_press_get_current_user();
76 + if ( empty( $course ) ) {
77 + $course = learn_press_get_course();
78 + }
79 +
66 80 if ( ! $user || ! $course ) {
67 81 return;
68 82 }
69 83
@@ -88,42 +102,16 @@
88 102 echo wp_kses_post( $course->get_image() );
89 103 }
90 104
91 105 /**
92 - * @editor tungnx
93 - * @modify 4.1.3
94 - */
95 - /*
96 - public function loop_item_user_progress() {
97 - $course = learn_press_get_course();
98 - $user = learn_press_get_current_user();
99 -
100 - if ( ! $user || ! $course ) {
101 - return;
102 - }
103 -
104 - if ( $user->has_enrolled_course( $course->get_id() ) ) {
105 - echo $user->get_course_status( $course->get_id() );
106 - }
107 - }*/
108 -
109 - /**
110 106 * @param LP_Quiz $item
111 107 */
112 108 public function quiz_meta_questions( $item ) {
113 109 $count = $item->count_questions();
114 - echo '<span class="item-meta count-questions">' . sprintf(
115 - $count ? _n(
116 - '%d question',
117 - '%d questions',
118 - $count,
119 - 'learnpress'
120 - ) : __(
121 - '%d question',
122 - 'learnpress'
123 - ),
124 - $count
125 - ) . '</span>';
110 + printf(
111 + '<span class="item-meta count-questions">%s</span>',
112 + sprintf( _n( '%1$d question', '%1$d questions', $count, 'learnpress' ), $count )
113 + );
126 114 }
127 115
128 116 /**
129 117 * @param LP_Quiz|LP_Lesson $item
@@ -141,9 +129,10 @@
141 129 */
142 130 public function quiz_meta_final( $item ) {
143 131 $course = $item->get_course();
144 132
145 - if ( ! $course || ! $course->is_final_quiz( $item->get_id() ) ) {
133 + if ( ! $course || ! $course->is_final_quiz( $item->get_id() )
134 + || $course->get_evaluation_type() != 'evaluate_final_quiz' ) {
146 135 return;
147 136 }
148 137
149 138 echo '<span class="item-meta final-quiz">' . esc_html__( 'Final', 'learnpress' ) . '</span>';
@@ -160,30 +149,33 @@
160 149 public function courses_top_bar() {
161 150 learn_press_get_template( 'courses-top-bar' );
162 151 }
163 152
153 + /**
154 + * Display price or free of course, not button, it is label.
155 + *
156 + * @return void
157 + * @since 4.0.0
158 + * @version 1.0.3
159 + */
164 160 public function course_pricing() {
165 - $can_show = true;
166 - $course = learn_press_get_course();
167 - $user = learn_press_get_current_user();
168 - $price_html = '';
161 + $course = learn_press_get_course();
162 + $user = learn_press_get_current_user();
169 163
170 - try {
171 - if ( $user && $user->has_enrolled_course( get_the_ID() ) ) {
172 - throw new Exception( 'User has enrolled course' );
164 + $courseModel = CourseModel::find( $course->get_id(), true );
165 + $can_purchase = $courseModel->can_purchase( UserModel::find( $user->get_id(), true ) );
166 + $userCourseModel = UserCourseModel::find( $user->get_id(), $course->get_id(), true );
167 + if ( get_current_user_id() ) {
168 + if ( $userCourseModel ) {
169 + if ( $userCourseModel->has_enrolled() ) {
170 + return;
171 + } elseif ( $can_purchase instanceof WP_Error ) {
172 + return;
173 + }
173 174 }
174 -
175 - $price_html = $course->get_course_price_html();
176 - } catch ( Throwable $e ) {
177 - $can_show = false;
178 175 }
179 176
180 - $can_show = apply_filters( 'learnpress/course/template/price/can-show', $can_show, $user, $course );
181 -
182 - if ( ! $can_show ) {
183 - return;
184 - }
185 -
177 + $price_html = $course->get_course_price_html();
186 178 learn_press_get_template( 'single-course/price', compact( 'course', 'user', 'price_html' ) );
187 179 }
188 180
189 181 /**
@@ -190,51 +182,19 @@
190 182 * Template purchase course button
191 183 *
192 184 * @editor tungnx
193 185 * @modify 4.1.3.1
194 - * @version 4.0.1
195 186 * @throws Exception
187 + * @version 4.0.2
196 188 */
197 - public function course_purchase_button() {
198 - $can_show = true;
199 - $course = learn_press_get_course();
200 - $user = learn_press_get_current_user();
189 + public function course_purchase_button( $course = null ) {
190 + _deprecated_function( __METHOD__, '4.3.2', 'SingleCourseTemplate::html_btn_purchase_course' );
191 + return;
201 192
202 - try {
203 - if ( ! $user || ! $course ) {
204 - throw new Exception( 'User or Course is not exists' );
205 - }
206 -
207 - if ( ! $user->can_purchase_course( $course->get_id() ) ) {
208 - throw new Exception( 'You can not purchase course' );
209 - }
210 - } catch ( Throwable $e ) {
211 - $can_show = false;
212 - }
213 -
214 - $can_show = apply_filters( 'learnpress/course/template/button-purchase/can-show', $can_show, $user, $course );
215 -
216 - if ( ! $can_show ) {
217 - return;
218 - }
219 -
220 - $args_load_tmpl = array(
221 - 'template_name' => 'single-course/buttons/purchase.php',
222 - 'template_path' => '',
223 - 'default_path' => '',
224 - );
225 -
226 - $args_load_tmpl = apply_filters( 'learn-press/tmpl-button-purchase-course', $args_load_tmpl, $course );
227 -
228 - learn_press_get_template(
229 - $args_load_tmpl['template_name'],
230 - array(
231 - 'user' => $user,
232 - 'course' => $course,
233 - ),
234 - $args_load_tmpl['template_path'],
235 - $args_load_tmpl['default_path']
236 - );
193 + $singleCourseTemplate = SingleCourseTemplate::instance();
194 + $course = CourseModel::find( get_the_ID(), true );
195 + $user = UserModel::find( get_current_user_id(), true );
196 + echo $singleCourseTemplate->html_btn_purchase_course( $course, $user );
237 197 }
238 198
239 199 /**
240 200 * Show button enroll course
@@ -241,14 +201,26 @@
241 201 *
242 202 * @editor tungnx
243 203 * @modify 4.1.3.1
244 204 * @throws Exception
245 - * @version 4.0.2
205 + * @version 4.0.3
246 206 */
247 - public function course_enroll_button() {
207 + public function course_enroll_button( $course = null ) {
208 + _deprecated_function( __METHOD__, '4.3.2.4', 'SingleCourseTemplate::html_btn_enroll_course' );
209 + return;
210 +
211 + $singleCourseTemplate = SingleCourseTemplate::instance();
212 + $course = CourseModel::find( get_the_ID(), true );
213 + $user = UserModel::find( get_current_user_id(), true );
214 + echo $singleCourseTemplate->html_btn_enroll_course( $course, $user );
215 + return;
216 +
248 217 $can_show = true;
249 218 $user = learn_press_get_current_user();
250 - $course = learn_press_get_course();
219 + if ( empty( $course ) ) {
220 + $course = learn_press_get_course();
221 + }
222 + $error_code = '';
251 223
252 224 try {
253 225 if ( ! $course || ! $user ) {
254 226 throw new Exception( 'User or Course is not exists' );
@@ -254,22 +226,28 @@
254 226 throw new Exception( 'User or Course is not exists' );
255 227 }
256 228
257 229 // User can not enroll course.
258 - if ( ! $user->can_enroll_course( $course->get_id() ) ) {
259 - throw new Exception( 'You can not enroll course' );
230 + $can_enroll_course = $user->can_enroll_course( $course->get_id(), false );
231 + if ( ! $can_enroll_course->check ) {
232 + $error_code = $can_enroll_course->code;
233 + throw new Exception( $can_enroll_course->message );
260 234 }
261 235
262 236 if ( $user->has_finished_course( $course->get_id() ) ) {
263 - throw new Exception( 'Course is finished' );
264 -
237 + $error_code = 'course_is_finished';
238 + throw new Exception( __( 'Course is finished', 'learnpress' ) );
265 239 }
266 240 } catch ( Throwable $e ) {
241 + if ( ! in_array( $error_code, [ 'course_is_enrolled', 'course_can_retry' ] ) ) {
242 + if ( $course && $course->is_free() ) {
243 + Template::print_message( $e->getMessage(), 'warning' );
244 + }
245 + }
267 246 $can_show = false;
268 247 }
269 248
270 249 $can_show = apply_filters( 'learnpress/course/template/button-enroll/can-show', $can_show, $user, $course );
271 -
272 250 if ( ! $can_show ) {
273 251 return;
274 252 }
275 253
@@ -282,8 +260,11 @@
282 260 }
283 261
284 262 public function course_extra_requirements( $course_id ) {
285 263 $course = LP_Course::get_course( $course_id );
264 + if ( ! $course ) {
265 + return;
266 + }
286 267
287 268 $requirements = apply_filters(
288 269 'learn-press/course-extra-requirements',
289 270 $course->get_extra_info( 'requirements' ),
@@ -305,8 +286,11 @@
305 286 }
306 287
307 288 public function course_extra_key_features( $course_id ) {
308 289 $course = LP_Course::get_course( $course_id );
290 + if ( ! $course ) {
291 + return;
292 + }
309 293
310 294 $key_features = apply_filters(
311 295 'learn-press/course-extra-key-features',
312 296 $course->get_extra_info( 'key_features' ),
@@ -328,8 +312,11 @@
328 312 }
329 313
330 314 public function course_extra_target_audiences( $course_id ) {
331 315 $course = LP_Course::get_course( $course_id );
316 + if ( ! $course ) {
317 + return;
318 + }
332 319
333 320 $target_audiences = apply_filters(
334 321 'learn-press/course-extra-target-audiences',
335 322 $course->get_extra_info( 'target_audiences' ),
@@ -350,158 +337,69 @@
350 337 );
351 338 }
352 339
353 340 /**
354 - * Show button retake course
355 - *
356 - * @throws Exception
357 - * @deprecated 4.0.0
358 - */
359 - public function course_retake_button() {
360 - _deprecated_function( __FUNCTION__, '4.0.0', 'button_retry' );
361 - $user = learn_press_get_current_user();
362 -
363 - if ( ! $user ) {
364 - return;
365 - }
366 -
367 - if ( ! isset( $course ) ) {
368 - $course = learn_press_get_course();
369 - }
370 -
371 - if ( ! $user->has_enrolled_course( $course->get_id() ) && $course->get_external_link() ) {
372 - return;
373 - }
374 -
375 - // If user has not finished course
376 - if ( ! $user->has_finished_course( $course->get_id() ) ) {
377 - return;
378 - }
379 - learn_press_get_template( 'single-course/buttons/retake.php' );
380 - }
381 -
382 - /**
383 341 * Show template "continue" button con single course
384 342 *
385 343 * @throws Exception
386 - * @editor tungnx
387 344 * @modify 4.1.3.1
388 - * @version 4.0.2
345 + * @version 4.0.4
389 346 * @since 4.0.0
390 347 */
391 - public function course_continue_button() {
392 - $can_show = true;
393 - $user = learn_press_get_current_user();
394 - $course = learn_press_get_course();
348 + public static function course_continue_button( $args = [] ) {
349 + _deprecated_function( __METHOD__, '4.3.2.4', 'UserCourseTemplate::html_btn_continue' );
350 + return;
395 351
352 + $course_id_param = $args['course-id'] ?? 0;
353 + $course_id = ! empty( $course_id_param ) ? $course_id_param : get_the_ID();
354 + $courseModel = CourseModel::find( $course_id, true );
355 + $user_id = get_current_user_id();
356 +
396 357 try {
397 - if ( ! $user || ! $course ) {
358 + if ( ! $user_id || ! $courseModel ) {
398 359 throw new Exception( 'User or Course not exists!' );
399 360 }
400 361
401 - if ( ! $user->has_enrolled_course( $course->get_id() ) ) {
402 - throw new Exception( 'User has not enrolled course' );
362 + $userCourseModel = UserCourseModel::find( $user_id, $courseModel->get_id(), true );
363 + if ( ! $userCourseModel || ! $userCourseModel->has_enrolled() ) {
364 + throw new Exception( 'User not enrolled course' );
403 365 }
404 366
405 - if ( $user->has_finished_course( $course->get_id() ) ) {
367 + if ( $userCourseModel->has_finished() ) {
406 368 throw new Exception( 'User has finished course' );
407 369 }
408 370
409 371 // Course has no items
410 - if ( empty( $course->count_items() ) ) {
372 + if ( empty( $courseModel->get_total_items() ) ) {
411 373 throw new Exception( 'Course no any item' );
412 374 }
413 375
414 376 // Do not display continue button if course is block duration
415 - if ( $user->can_view_content_course( $course->get_id() )->key === LP_BLOCK_COURSE_DURATION_EXPIRE ) {
377 + if ( $userCourseModel->timestamp_remaining_duration() === 0 ) {
416 378 throw new Exception( 'Course is blocked' );
417 379 }
380 +
381 + $section = [
382 + 'start' => '<div>',
383 + 'link' => UserCourseTemplate::instance()->html_btn_continue( $userCourseModel ),
384 + 'end' => '</div>',
385 + ];
386 +
387 + echo Template::combine_components( $section );
418 388 } catch ( Throwable $e ) {
419 - $can_show = false;
420 - }
421 389
422 - $can_show = apply_filters( 'learnpress/course/template/button-continue/can-show', $can_show, $user, $course );
423 -
424 - if ( ! $can_show ) {
425 - return;
426 390 }
427 -
428 - $args = array(
429 - 'user' => $user,
430 - 'course' => $course,
431 - );
432 -
433 - learn_press_get_template( 'single-course/buttons/continue.php', $args );
434 391 }
435 392
436 - /**
437 - * Check can show button finish course
438 - *
439 - * @param LP_Course|false $course
440 - * @param LP_User|LP_User_Guest $user
441 - *
442 - * @return array
443 - * @editor tungnx
444 - * @modify 4.1.4.1 - comment - not use - replace on function can_show_finish_course_btn on LP_User
445 - */
446 - /*
447 - public function can_show_finish_course_btn( $course, $user ): array {
448 - $return = [
449 - 'flag' => false,
450 - 'message' => '',
451 - ];
393 + public function course_finish_button( $course = null ) {
394 + _deprecated_function( __METHOD__, '4.3.2.4', 'UserCourseTemplate::html_btn_finish' );
395 + return;
452 396
453 - try {
454 - if ( ! $course || ! $user ) {
455 - throw new Exception( esc_html__( 'Error: No Course or User available.', 'learnpress' ) );
456 - }
457 -
458 - $course_id = $course->get_id();
459 -
460 - if ( ! $user->has_enrolled_course( $course_id ) ) {
461 - throw new Exception( esc_html__( 'Course is not enroll.', 'learnpress' ) );
462 - }
463 -
464 - $course_data = $user->get_course_data( $course_id );
465 -
466 - if ( ! $user->is_course_in_progress( $course_id ) ) {
467 - throw new Exception( esc_html__( 'Error: Course is not in-progress.', 'learnpress' ) );
468 - }
469 -
470 - // Get option Allow show finish button when the student has completed all items but has not passed the course assessment.
471 - $has_finish = get_post_meta( $course_id, '_lp_has_finish', true ) ?? 'yes';
472 - $is_passed = $user->has_reached_passing_condition( $course_id );
473 -
474 - if ( ! $is_passed && $has_finish === 'no' ) {
475 - throw new Exception( esc_html__( 'Error: Course is not has finish.', 'learnpress' ) );
476 - }
477 -
478 - if ( $course_data ) {
479 - $course_result = $course_data->get_result();
480 -
481 - $is_all_completed = $user->is_completed_all_items( $course_id );
482 -
483 - if ( ! $is_all_completed && $has_finish === 'yes' && ! $course_result['pass'] ) {
484 - throw new Exception( esc_html__( 'Error: Cannot finish course.', 'learnpress' ) );
485 - }
486 - }
487 -
488 - if ( ! apply_filters( 'lp_can_finish_course', true ) ) {
489 - throw new Exception( esc_html__( 'Error: Filter disable finish course.', 'learnpress' ) );
490 - }
491 -
492 - $return['flag'] = true;
493 - } catch ( Exception $e ) {
494 - $return['message'] = $e->getMessage();
397 + $user = learn_press_get_current_user();
398 + if ( empty( $course ) ) {
399 + $course = learn_press_get_course();
495 400 }
496 401
497 - return $return;
498 - }*/
499 -
500 - public function course_finish_button() {
501 - $user = learn_press_get_current_user();
502 - $course = learn_press_get_course();
503 -
504 402 if ( ! $course ) {
505 403 return;
506 404 }
507 405
@@ -531,12 +429,18 @@
531 429 * @throws Exception
532 430 * @editor tungnx
533 431 * @modify 4.1.3
534 432 */
535 - public function course_external_button() {
536 - $course = learn_press_get_course();
537 - $user = learn_press_get_current_user();
433 + public function course_external_button( $course = null ) {
434 + _deprecated_function( __METHOD__, '4.3.2.4', 'SingleCourseTemplate::html_btn_external' );
435 + return;
538 436
437 + if ( empty( $course ) ) {
438 + $course = learn_press_get_course();
439 + }
440 +
441 + $user = learn_press_get_current_user();
442 +
539 443 if ( ! $course ) {
540 444 return;
541 445 }
542 446
@@ -548,10 +452,11 @@
548 452 $user = learn_press_get_current_user();
549 453
550 454 if ( $user && ! $user->has_enrolled_or_finished( $course->get_id() ) ) {
551 455 // Remove all another buttons
552 - learn_press_remove_course_buttons();
456 + // learn_press_remove_course_buttons();
553 457 learn_press_get_template( 'single-course/buttons/external-link.php' );
458 +
554 459 // Add back other buttons for other courses
555 460 add_action( 'learn-press/after-course-buttons', 'learn_press_add_course_buttons' );
556 461 }
557 462 }
@@ -568,9 +473,9 @@
568 473 $total_items = 0;
569 474 $completed_items = 0;
570 475 $course_data = $user->get_course_data( $course->get_id() );
571 476
572 - if ( $course_data && ! $course->is_no_required_enroll() ) {
477 + if ( $course_data && ! empty( $course_data->get_user_id() ) && ! $course->is_no_required_enroll() ) {
573 478 $course_results = $course_data->get_result();
574 479 $completed_items = $course_results['completed_items'];
575 480 $total_items = $course_results['count_items'];
576 481 $percentage = $course_results['count_items'] ? absint( $course_results['completed_items'] / $course_results['count_items'] * 100 ) : 0;
@@ -632,34 +537,62 @@
632 537 )
633 538 );
634 539 }
635 540
541 + /**
542 + * Display course curriculum.
543 + *
544 + * @since 4.1.6
545 + * @since 4.2.5.5 remove code load old template user for course curriculum load page instead of via AJAX.
546 + * @version 1.0.2
547 + * @depreacted 4.2.8.7.1
548 + */
636 549 public function course_curriculum() {
637 - if ( ! learn_press_override_templates() || ( learn_press_override_templates() && has_filter( 'lp/template-course/course_curriculum/skeleton' ) ) ) {
638 - $course_item = LP_Global::course_item();
550 + /**
551 + * @var CourseModel $lpCourseModel
552 + */
553 + global $lpCourseModel;
554 + $courseModel = CourseModel::find( get_the_ID(), true );
555 + if ( $lpCourseModel instanceof CourseModel ) {
556 + $courseModel = $lpCourseModel;
557 + }
639 558
640 - if ( $course_item ) { // Check if current item is viewable
641 - $item_id = $course_item->get_id();
642 - $section_id = LP_Section_DB::getInstance()->get_section_id_by_item_id( absint( $item_id ) );
559 + $course_item = LP_Global::course_item();
560 + $userModel = UserModel::find( get_current_user_id(), true );
561 +
562 + $singleCourseTemplate = SingleCourseTemplate::instance();
563 + echo $singleCourseTemplate->html_curriculum( $courseModel, $userModel );
564 + }
565 +
566 + /**
567 + * Display course curriculum.
568 + *
569 + * @since 4.1.6
570 + * @since 4.2.5.5 remove code load old template user for course curriculum load page instead of via AJAX.
571 + * @version 1.0.2
572 + */
573 + public function course_curriculum_bk() {
574 + /**
575 + * @var CourseModel $lpCourseModel
576 + */
577 + global $lpCourseModel;
578 + $course_item = LP_Global::course_item();
579 +
580 + if ( $course_item ) { // Check if current item is viewable
581 + $course_id = 0;
582 + if ( $lpCourseModel ) {
583 + $course_id = $lpCourseModel->get_id();
643 584 }
644 - ?>
645 - <div class="learnpress-course-curriculum" data-section="<?php echo esc_attr( $section_id ?? '' ); ?>" data-id="<?php echo esc_attr( $item_id ?? '' ); ?>">
646 - <ul class="lp-skeleton-animation">
647 - <li style="width: 100%; height: 50px"></li>
648 - <li style="width: 100%; height: 20px"></li>
649 - <li style="width: 100%; height: 20px"></li>
650 - <li style="width: 100%; height: 20px"></li>
651 585
652 - <li style="width: 100%; height: 50px; margin-top: 40px;"></li>
653 - <li style="width: 100%; height: 20px"></li>
654 - <li style="width: 100%; height: 20px"></li>
655 - <li style="width: 100%; height: 20px"></li>
656 - </ul>
657 - </div>
658 - <?php
659 - } else {
660 - learn_press_get_template( 'single-course/tabs/curriculum' );
586 + $item_id = (int) $course_item->get_id();
587 + $section_id = LP_Section_DB::getInstance()->get_section_id_by_item_id( $item_id, $course_id );
661 588 }
589 + ?>
590 + <div class="learnpress-course-curriculum" data-section="<?php echo esc_attr( $section_id ?? '' ); ?>"
591 + data-id="<?php echo esc_attr( $item_id ?? '' ); ?>">
592 + <?php lp_skeleton_animation_html( 10 ); ?>
593 + </div>
594 + <?php
662 595 }
663 596
664 597 /**
665 598 * Get template content item's course
@@ -699,15 +632,13 @@
699 632 }
700 633
701 634 public function course_item_content() {
702 635 $course = learn_press_get_course();
703 - $item = LP_Global::course_item();
636 + if ( ! $course ) {
637 + return;
638 + }
704 639
705 - // if ( $item->is_blocked() ) {
706 - // learn_press_get_template( 'global/block-content.php' );
707 - //
708 - // return;
709 - // }
640 + $item = LP_Global::course_item();
710 641
711 642 /**
712 643 * Fix only for WPBakery load style inline
713 644 * custom CSS is provided, load inline style.
@@ -718,22 +649,15 @@
718 649 $shortcodes_custom_css = get_post_meta( $item->get_id(), '_wpb_shortcodes_custom_css', true );
719 650
720 651 if ( ! empty( $shortcodes_custom_css ) ) {
721 652 $shortcodes_custom_css = strip_tags( $shortcodes_custom_css );
722 - echo '<style type="text/css" data-type="vc_shortcodes-custom-css">';
653 + echo '<style data-type="vc_shortcodes-custom-css">';
723 654 echo wp_kses_post( $shortcodes_custom_css );
724 655 echo '</style>';
725 656 }
726 657 // End
727 658
728 - // Get timestamp remaining duration of course
729 - /*$course_item = $item->get_course();
730 - if ( ! $course_item ) {
731 - return;
732 - }*/
733 -
734 659 $timestamp_remaining = $course->timestamp_remaining_duration();
735 -
736 660 if ( $timestamp_remaining > 0 ) {
737 661 echo '<input type="hidden" name="lp-course-timestamp-remaining" value="' . esc_attr( $timestamp_remaining ) . '">';
738 662 }
739 663 // End
@@ -746,36 +670,8 @@
746 670 echo esc_html( sprintf( 'File %s not exists', $item_template_name ) );
747 671 }
748 672 }
749 673
750 - /**
751 - * @editor tungnx
752 - * @reason comment - not use
753 - * @since 4.1.2
754 - */
755 - /*
756 - public function remaining_time() {
757 -
758 - if ( ! $course = learn_press_get_course() ) {
759 - return;
760 - }
761 -
762 - if ( ! $user = learn_press_get_current_user() ) {
763 - return;
764 - }
765 -
766 - if ( false === ( $remain = $user->get_course_remaining_time( $course->get_id() ) ) ) {
767 -
768 - return;
769 - }
770 -
771 - if ( $user->has_finished_course( $course->get_id() ) ) {
772 - return;
773 - }
774 -
775 - learn_press_get_template( 'single-course/remaining-time.php', array( 'remaining_time' => $remain ) );
776 - }*/
777 -
778 674 public function item_lesson_title() {
779 675 $item = LP_Global::course_item();
780 676 $format = $item->get_format();
781 677 $format_template = learn_press_locate_template( "content-lesson/{$format}/title.php" );
@@ -799,23 +695,11 @@
799 695 return;
800 696 }
801 697 do_action( 'learn-press/lesson-start', $item );
802 698
803 - learn_press_get_template( 'content-lesson/content.php', array( 'lesson' => $item ) );
699 + Template::instance()->get_frontend_template( 'content-lesson/content.php', array( 'lesson' => $item ) );
804 700 }
805 701
806 - public function item_quiz_content() {
807 - $item = LP_Global::course_item();
808 -
809 - learn_press_get_template( 'content-quiz/js.php' );
810 - }
811 -
812 - public function item_lesson_content_blocked() {
813 - $item = LP_Global::course_item();
814 -
815 - learn_press_get_template( 'global/block-content.php' );
816 - }
817 -
818 702 /**
819 703 * Get template button complete lesson
820 704 */
821 705 public function item_lesson_complete_button() {
@@ -820,64 +704,53 @@
820 704 */
821 705 public function item_lesson_complete_button() {
822 706 $user = learn_press_get_current_user();
823 707 $course = learn_press_get_course();
824 - $item = LP_Global::course_item();
825 -
826 - if ( ! $user || ! $course || ! $user->is_course_in_progress( $course->get_id() ) ) {
708 + if ( ! $course ) {
827 709 return;
828 710 }
829 711
830 - // The complete button is not displayed when the course is locked --hungkv--
831 - if ( $user->can_view_content_course( $course->get_id() )->key === LP_BLOCK_COURSE_DURATION_EXPIRE ) {
832 - return;
833 - }
712 + try {
713 + $item = LP_Global::course_item();
714 + if ( ! $user || ! $user->is_course_in_progress( $course->get_id() ) ) {
715 + return;
716 + }
834 717
835 - learn_press_get_template(
836 - 'content-lesson/button-complete.php',
837 - array(
838 - 'user' => $user,
839 - 'course' => $course,
840 - 'item' => $item,
841 - )
842 - );
843 - }
718 + // The complete button is not displayed when the course is locked --hungkv--
719 + if ( $user->can_view_content_course( $course->get_id() )->key === LP_BLOCK_COURSE_DURATION_EXPIRE ) {
720 + return;
721 + }
844 722
845 - /**
846 - * @depecated 4.1.6.9
847 - */
848 - /*public function lesson_comment_form() {
849 - $course = learn_press_get_course();
850 - if ( ! $course ) {
851 - return;
723 + learn_press_get_template(
724 + 'content-lesson/button-complete.php',
725 + array(
726 + 'user' => $user,
727 + 'course' => $course,
728 + 'item' => $item,
729 + )
730 + );
731 + } catch ( Throwable $e ) {
732 + error_log( $e->getMessage() );
852 733 }
734 + }
853 735
854 - $lesson = LP_Global::course_item();
855 - if ( ! $lesson ) {
856 - return;
736 + public function item_lesson_material() {
737 + try {
738 + do_action( 'learn-press/course-material/layout', [] );
739 + } catch ( Throwable $e ) {
740 + error_log( $e->getMessage() );
857 741 }
742 + }
858 743
859 - if ( $lesson->setup_postdata() ) {
860 -
861 - if ( comments_open() || get_comments_number() ) {
862 - add_filter( 'deprecated_file_trigger_error', '__return_false' );
863 - comments_template();
864 - remove_filter( 'deprecated_file_trigger_error', '__return_false' );
865 - }
866 - $lesson->reset_postdata();
867 - }
868 - }*/
869 -
870 744 /**
871 745 * Template show count items
872 746 *
873 747 * @since 4.0.0
874 - * @version 1.0.1
748 + * @version 1.0.2
875 749 * @editor tungnx
876 750 */
877 751 public function count_object() {
878 - $course = learn_press_get_course();
879 -
752 + $course = CourseModel::find( get_the_ID(), true );
880 753 if ( ! $course ) {
881 754 return;
882 755 }
883 756
@@ -916,9 +789,13 @@
916 789 }
917 790
918 791 public function course_extra_boxes() {
919 792 $course = LP_Course::get_course( get_the_ID() );
920 - $boxes = apply_filters(
793 + if ( ! $course ) {
794 + return;
795 + }
796 +
797 + $boxes = apply_filters(
921 798 'learn-press/course-extra-boxes-data',
922 799 array(
923 800 array(
924 801 'title' => __( 'Requirements', 'learnpress' ),
@@ -948,10 +825,13 @@
948 825 }
949 826
950 827 learn_press_get_template( 'single-course/extra-info', $box );
951 828 }
829 + }
952 830
953 - }
831 + /*public function metarials() {
832 + echo wp_kses_post( do_shortcode( '[learn_press_course_materials]' ) );
833 + }*/
954 834
955 835 public function faqs() {
956 836 $course = LP_Course::get_course( get_the_ID() );
957 837 $faqs = $course->get_faqs();
@@ -992,17 +872,8 @@
992 872 )
993 873 );
994 874 }
995 875
996 - public function instructor_socials() {
997 - $instructor = $this->course->get_instructor();
998 - $socials = $instructor->get_profile_socials( $instructor->get_id() );
999 -
1000 - foreach ( $socials as $social ) {
1001 - echo wp_kses_post( $social );
1002 - }
1003 - }
1004 -
1005 876 public function has_sidebar() {
1006 877 $actions = array(
1007 878 'learn-press/before-course-summary-sidebar',
1008 879 'learn-press/course-summary-sidebar',
@@ -1038,14 +909,15 @@
1038 909 if ( ! $item ) {
1039 910 return;
1040 911 }
1041 912
1042 - $user = learn_press_get_current_user();
913 + $user = learn_press_get_current_user();
914 + $user_can_view_course = $user->can_view_content_course( $course->get_id() );
915 + $user_can_view_item = $user->can_view_item( $item->get_id(), $user_can_view_course );
916 + if ( ! $user_can_view_item->flag ) {
917 + return;
918 + }
1043 919
1044 - // if ( ! $user->is_admin() && ! $user->has_course_status( $course->get_id(), array( 'enrolled', 'finished' ) ) ) {
1045 - // return;
1046 - // }
1047 -
1048 920 if ( $item->setup_postdata() ) {
1049 921
1050 922 if ( comments_open() || get_comments_number() ) {
1051 923 learn_press_get_template( 'single-course/item-comments' );
@@ -1053,11 +925,10 @@
1053 925 $item->reset_postdata();
1054 926 }
1055 927 }
1056 928
929 +
1057 930 public function course_comment_template() {
1058 - global $post;
1059 -
1060 931 if ( comments_open() || get_comments_number() ) {
1061 932 add_filter( 'deprecated_file_trigger_error', '__return_false' );
1062 933 comments_template();
1063 934 remove_filter( 'deprecated_file_trigger_error', '__return_false' );
@@ -1067,10 +938,13 @@
1067 938 /**
1068 939 * Show info time handle of user
1069 940 *
1070 941 * @throws Exception
942 + * @deprecated 4.4.0
1071 943 */
1072 944 public function user_time() {
945 + _deprecated_function( __METHOD__, '4.4.0' );
946 + return;
1073 947 $user = learn_press_get_current_user();
1074 948
1075 949 if ( ! $user ) {
1076 950 return;
@@ -1092,12 +966,18 @@
1092 966 $status = $user_course->get_status();
1093 967 $start_time = $user_course->get_start_time();
1094 968 $end_time = $user_course->get_end_time();
1095 969 $expiration_time = $user_course->get_expiration_time();
970 + $data = [
971 + 'status' => $status,
972 + 'start_time' => $start_time,
973 + 'end_time' => $end_time,
974 + 'expiration_time' => $expiration_time,
975 + ];
1096 976
1097 977 learn_press_get_template(
1098 978 'single-course/sidebar/user-time',
1099 - compact( 'status', 'start_time', 'end_time', 'expiration_time' )
979 + compact( 'data' )
1100 980 );
1101 981 }
1102 982
1103 983 /**
@@ -1108,26 +988,19 @@
1108 988 * @throws Exception
1109 989 * @author Nhamdv.
1110 990 */
1111 991 public function user_progress() {
1112 - if ( ! is_user_logged_in() ) {
992 + $courseModel = CourseModel::find( get_the_ID(), true );
993 + if ( ! $courseModel ) {
1113 994 return;
1114 995 }
1115 996
1116 - $course = learn_press_get_course();
1117 - $user = learn_press_get_current_user();
997 + $userModel = UserModel::find( get_current_user_id(), true );
998 + echo SingleCourseModernLayout::instance()->html_info_learning( $courseModel, $userModel );
1118 999
1119 - if ( ! $course ) {
1120 - return;
1121 - }
1122 -
1123 - if ( ! $user->has_enrolled_or_finished( $course->get_id() ) ) {
1124 - return;
1125 - }
1126 -
1127 - if ( LP_LAZY_LOAD_ANIMATION ) {
1000 + /*if ( LP_LAZY_LOAD_ANIMATION ) {
1128 1001 echo '<div class="lp-course-progress-wrapper">';
1129 - echo lp_skeleton_animation_html( 3 );
1002 + lp_skeleton_animation_html();
1130 1003 echo '</div>';
1131 1004 } else {
1132 1005 $course_data = $user->get_course_data( $course->get_id() );
1133 1006 if ( ! $course_data ) {
@@ -1139,15 +1012,14 @@
1139 1012 learn_press_get_template(
1140 1013 'single-course/sidebar/user-progress',
1141 1014 compact( 'user', 'course', 'course_data', 'course_results' )
1142 1015 );
1143 - }
1016 + }*/
1144 1017 }
1145 1018
1146 1019 public function course_extra_boxes_position_control() {
1147 1020 $course = LP_Course::get_course( get_the_ID() );
1148 1021 $user = learn_press_get_current_user();
1149 -
1150 1022 if ( ! $user || ! $course ) {
1151 1023 return;
1152 1024 }
1153 1025
@@ -1154,15 +1026,15 @@
1154 1026 $enrolled = $user->has_enrolled_course( $course->get_id() );
1155 1027 if ( $enrolled ) {
1156 1028 remove_action(
1157 1029 'learn-press/course-content-summary',
1158 - LP()->template( 'course' )->func( 'course_extra_boxes' ),
1030 + LearnPress::instance()->template( 'course' )->func( 'course_extra_boxes' ),
1159 1031 40
1160 1032 );
1161 1033 } else {
1162 1034 remove_action(
1163 1035 'learn-press/course-content-summary',
1164 - LP()->template( 'course' )->func( 'course_extra_boxes' ),
1036 + LearnPress::instance()->template( 'course' )->func( 'course_extra_boxes' ),
1165 1037 70
1166 1038 );
1167 1039 }
1168 1040 }