| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Class LP_Course_Template |
| 5 |
* |
| 6 |
* Groups templates related course and items |
| 7 |
* |
| 8 |
* @since 3.x.x |
| 9 |
*/ |
| 10 |
class LP_Template_Course extends LP_Abstract_Template { |
| 11 |
|
| 12 |
/** |
| 13 |
* @var LP_Course |
| 14 |
*/ |
| 15 |
public $course = null; |
| 16 |
|
| 17 |
/** |
| 18 |
* LP_Template_Course constructor. |
| 19 |
*/ |
| 20 |
public function __construct() { |
| 21 |
parent::__construct(); |
| 22 |
|
| 23 |
add_action( 'the_post', array( $this, 'get_course' ), 1000 ); |
| 24 |
} |
| 25 |
|
| 26 |
public function get_course() { |
| 27 |
// global $post; |
| 28 |
|
| 29 |
$this->course = learn_press_get_course(); |
| 30 |
} |
| 31 |
|
| 32 |
public function course_sidebar_preview() { |
| 33 |
learn_press_get_template( 'single-course/sidebar/preview' ); |
| 34 |
} |
| 35 |
|
| 36 |
public function course_buttons() { |
| 37 |
learn_press_get_template( 'single-course/buttons' ); |
| 38 |
} |
| 39 |
|
| 40 |
public function course_graduation() { |
| 41 |
$user = learn_press_get_current_user(); |
| 42 |
$course = learn_press_get_course(); |
| 43 |
|
| 44 |
if ( ! $user || ! $course ) { |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
if ( ! $user->has_finished_course( $course->get_id() ) ) { |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
$graduation = $user->get_course_grade( $course->get_id() ); |
| 53 |
|
| 54 |
learn_press_get_template( 'single-course/graduation', array( 'graduation' => $graduation ) ); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Show button retry course |
| 59 |
* |
| 60 |
* @throws Exception |
| 61 |
*/ |
| 62 |
public function button_retry() { |
| 63 |
$user = learn_press_get_current_user(); |
| 64 |
$course = learn_press_get_course(); |
| 65 |
|
| 66 |
if ( ! $user || ! $course ) { |
| 67 |
return; |
| 68 |
} |
| 69 |
|
| 70 |
$can_retake_times = $user->can_retry_course( $course->get_id() ); |
| 71 |
|
| 72 |
// Course has no items |
| 73 |
if ( empty( $course->count_items() ) ) { |
| 74 |
return; |
| 75 |
} |
| 76 |
|
| 77 |
if ( $can_retake_times ) { |
| 78 |
learn_press_get_template( |
| 79 |
'single-course/buttons/retry', |
| 80 |
array( 'can_retake_times' => $can_retake_times ) |
| 81 |
); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
public function course_media_preview() { |
| 86 |
$course = learn_press_get_course(); |
| 87 |
|
| 88 |
echo wp_kses_post( $course->get_image() ); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 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 |
* @param LP_Quiz $item |
| 111 |
*/ |
| 112 |
public function quiz_meta_questions( $item ) { |
| 113 |
$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>'; |
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* @param LP_Quiz|LP_Lesson $item |
| 130 |
*/ |
| 131 |
public function item_meta_duration( $item ) { |
| 132 |
$duration = learn_press_get_post_translated_duration( $item->get_id(), false ); |
| 133 |
|
| 134 |
if ( $duration ) { |
| 135 |
echo '<span class="item-meta duration">' . $duration . '</span>'; |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* @var LP_Course_Item $item |
| 141 |
*/ |
| 142 |
public function quiz_meta_final( $item ) { |
| 143 |
$course = $item->get_course(); |
| 144 |
|
| 145 |
if ( ! $course || ! $course->is_final_quiz( $item->get_id() ) ) { |
| 146 |
return; |
| 147 |
} |
| 148 |
|
| 149 |
echo '<span class="item-meta final-quiz">' . esc_html__( 'Final', 'learnpress' ) . '</span>'; |
| 150 |
} |
| 151 |
|
| 152 |
public function course_button() { |
| 153 |
echo '[COURSE BUTTON]'; |
| 154 |
} |
| 155 |
|
| 156 |
public function course_title() { |
| 157 |
echo '[COURSE TITLE]'; |
| 158 |
} |
| 159 |
|
| 160 |
public function courses_top_bar() { |
| 161 |
learn_press_get_template( 'courses-top-bar' ); |
| 162 |
} |
| 163 |
|
| 164 |
public function course_pricing() { |
| 165 |
$can_show = true; |
| 166 |
$course = learn_press_get_course(); |
| 167 |
$user = learn_press_get_current_user(); |
| 168 |
$price_html = ''; |
| 169 |
|
| 170 |
try { |
| 171 |
if ( $user && $user->has_enrolled_course( get_the_ID() ) ) { |
| 172 |
throw new Exception( 'User has enrolled course' ); |
| 173 |
} |
| 174 |
|
| 175 |
$price_html = $course->get_course_price_html(); |
| 176 |
} catch ( Throwable $e ) { |
| 177 |
$can_show = false; |
| 178 |
} |
| 179 |
|
| 180 |
$can_show = apply_filters( 'learnpress/course/template/price/can-show', $can_show, $user, $course ); |
| 181 |
|
| 182 |
if ( ! $can_show ) { |
| 183 |
return; |
| 184 |
} |
| 185 |
|
| 186 |
learn_press_get_template( 'single-course/price', compact( 'course', 'user', 'price_html' ) ); |
| 187 |
} |
| 188 |
|
| 189 |
/** |
| 190 |
* Template purchase course button |
| 191 |
* |
| 192 |
* @editor tungnx |
| 193 |
* @modify 4.1.3.1 |
| 194 |
* @version 4.0.1 |
| 195 |
* @throws Exception |
| 196 |
*/ |
| 197 |
public function course_purchase_button() { |
| 198 |
$can_show = true; |
| 199 |
$course = learn_press_get_course(); |
| 200 |
$user = learn_press_get_current_user(); |
| 201 |
|
| 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 |
); |
| 237 |
} |
| 238 |
|
| 239 |
/** |
| 240 |
* Show button enroll course |
| 241 |
* |
| 242 |
* @editor tungnx |
| 243 |
* @modify 4.1.3.1 |
| 244 |
* @throws Exception |
| 245 |
* @version 4.0.2 |
| 246 |
*/ |
| 247 |
public function course_enroll_button() { |
| 248 |
$can_show = true; |
| 249 |
$user = learn_press_get_current_user(); |
| 250 |
$course = learn_press_get_course(); |
| 251 |
|
| 252 |
try { |
| 253 |
if ( ! $course || ! $user ) { |
| 254 |
throw new Exception( 'User or Course is not exists' ); |
| 255 |
} |
| 256 |
|
| 257 |
// User can not enroll course. |
| 258 |
if ( ! $user->can_enroll_course( $course->get_id() ) ) { |
| 259 |
throw new Exception( 'You can not enroll course' ); |
| 260 |
} |
| 261 |
|
| 262 |
if ( $user->has_finished_course( $course->get_id() ) ) { |
| 263 |
throw new Exception( 'Course is finished' ); |
| 264 |
|
| 265 |
} |
| 266 |
} catch ( Throwable $e ) { |
| 267 |
$can_show = false; |
| 268 |
} |
| 269 |
|
| 270 |
$can_show = apply_filters( 'learnpress/course/template/button-enroll/can-show', $can_show, $user, $course ); |
| 271 |
|
| 272 |
if ( ! $can_show ) { |
| 273 |
return; |
| 274 |
} |
| 275 |
|
| 276 |
$args = array( |
| 277 |
'user' => $user, |
| 278 |
'course' => $course, |
| 279 |
); |
| 280 |
|
| 281 |
learn_press_get_template( 'single-course/buttons/enroll.php', $args ); |
| 282 |
} |
| 283 |
|
| 284 |
public function course_extra_requirements( $course_id ) { |
| 285 |
$course = LP_Course::get_course( $course_id ); |
| 286 |
|
| 287 |
$requirements = apply_filters( |
| 288 |
'learn-press/course-extra-requirements', |
| 289 |
$course->get_extra_info( 'requirements' ), |
| 290 |
$course_id |
| 291 |
); |
| 292 |
|
| 293 |
if ( ! $requirements ) { |
| 294 |
return; |
| 295 |
} |
| 296 |
|
| 297 |
learn_press_get_template( |
| 298 |
'single-course/sidebar/course-extra', |
| 299 |
array( |
| 300 |
'type' => 'requirements', |
| 301 |
'title' => esc_html__( 'Requirements', 'learnpress' ), |
| 302 |
'content' => $requirements, |
| 303 |
) |
| 304 |
); |
| 305 |
} |
| 306 |
|
| 307 |
public function course_extra_key_features( $course_id ) { |
| 308 |
$course = LP_Course::get_course( $course_id ); |
| 309 |
|
| 310 |
$key_features = apply_filters( |
| 311 |
'learn-press/course-extra-key-features', |
| 312 |
$course->get_extra_info( 'key_features' ), |
| 313 |
$course_id |
| 314 |
); |
| 315 |
|
| 316 |
if ( ! $key_features ) { |
| 317 |
return; |
| 318 |
} |
| 319 |
|
| 320 |
learn_press_get_template( |
| 321 |
'single-course/sidebar/course-extra', |
| 322 |
array( |
| 323 |
'type' => 'key-features', |
| 324 |
'title' => esc_html__( 'Key features', 'learnpress' ), |
| 325 |
'content' => $key_features, |
| 326 |
) |
| 327 |
); |
| 328 |
} |
| 329 |
|
| 330 |
public function course_extra_target_audiences( $course_id ) { |
| 331 |
$course = LP_Course::get_course( $course_id ); |
| 332 |
|
| 333 |
$target_audiences = apply_filters( |
| 334 |
'learn-press/course-extra-target-audiences', |
| 335 |
$course->get_extra_info( 'target_audiences' ), |
| 336 |
$course_id |
| 337 |
); |
| 338 |
|
| 339 |
if ( ! $target_audiences ) { |
| 340 |
return; |
| 341 |
} |
| 342 |
|
| 343 |
learn_press_get_template( |
| 344 |
'single-course/sidebar/course-extra', |
| 345 |
array( |
| 346 |
'type' => 'target-audiences', |
| 347 |
'title' => esc_html__( 'Target audiences', 'learnpress' ), |
| 348 |
'content' => $target_audiences, |
| 349 |
) |
| 350 |
); |
| 351 |
} |
| 352 |
|
| 353 |
/** |
| 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 |
* Show template "continue" button con single course |
| 384 |
* |
| 385 |
* @throws Exception |
| 386 |
* @editor tungnx |
| 387 |
* @modify 4.1.3.1 |
| 388 |
* @version 4.0.2 |
| 389 |
* @since 4.0.0 |
| 390 |
*/ |
| 391 |
public function course_continue_button() { |
| 392 |
$can_show = true; |
| 393 |
$user = learn_press_get_current_user(); |
| 394 |
$course = learn_press_get_course(); |
| 395 |
|
| 396 |
try { |
| 397 |
if ( ! $user || ! $course ) { |
| 398 |
throw new Exception( 'User or Course not exists!' ); |
| 399 |
} |
| 400 |
|
| 401 |
if ( ! $user->has_enrolled_course( $course->get_id() ) ) { |
| 402 |
throw new Exception( 'User has not enrolled course' ); |
| 403 |
} |
| 404 |
|
| 405 |
if ( $user->has_finished_course( $course->get_id() ) ) { |
| 406 |
throw new Exception( 'User has finished course' ); |
| 407 |
} |
| 408 |
|
| 409 |
// Course has no items |
| 410 |
if ( empty( $course->count_items() ) ) { |
| 411 |
throw new Exception( 'Course no any item' ); |
| 412 |
} |
| 413 |
|
| 414 |
// 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 ) { |
| 416 |
throw new Exception( 'Course is blocked' ); |
| 417 |
} |
| 418 |
} catch ( Throwable $e ) { |
| 419 |
$can_show = false; |
| 420 |
} |
| 421 |
|
| 422 |
$can_show = apply_filters( 'learnpress/course/template/button-continue/can-show', $can_show, $user, $course ); |
| 423 |
|
| 424 |
if ( ! $can_show ) { |
| 425 |
return; |
| 426 |
} |
| 427 |
|
| 428 |
$args = array( |
| 429 |
'user' => $user, |
| 430 |
'course' => $course, |
| 431 |
); |
| 432 |
|
| 433 |
learn_press_get_template( 'single-course/buttons/continue.php', $args ); |
| 434 |
} |
| 435 |
|
| 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 |
]; |
| 452 |
|
| 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(); |
| 495 |
} |
| 496 |
|
| 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 |
if ( ! $course ) { |
| 505 |
return; |
| 506 |
} |
| 507 |
|
| 508 |
// Course has no items |
| 509 |
if ( empty( $course->count_items() ) ) { |
| 510 |
return; |
| 511 |
} |
| 512 |
|
| 513 |
$check = $user->can_show_finish_course_btn( $course ); |
| 514 |
|
| 515 |
if ( 'success' !== $check['status'] ) { |
| 516 |
return; |
| 517 |
} |
| 518 |
|
| 519 |
learn_press_get_template( |
| 520 |
'single-course/buttons/finish.php', |
| 521 |
array( |
| 522 |
'course' => $course, |
| 523 |
'user' => $user, |
| 524 |
) |
| 525 |
); |
| 526 |
} |
| 527 |
|
| 528 |
/** |
| 529 |
* Button course external link |
| 530 |
* |
| 531 |
* @throws Exception |
| 532 |
* @editor tungnx |
| 533 |
* @modify 4.1.3 |
| 534 |
*/ |
| 535 |
public function course_external_button() { |
| 536 |
$course = learn_press_get_course(); |
| 537 |
$user = learn_press_get_current_user(); |
| 538 |
|
| 539 |
if ( ! $course ) { |
| 540 |
return; |
| 541 |
} |
| 542 |
|
| 543 |
$link = $course->get_external_link(); |
| 544 |
if ( empty( $link ) || $user->has_purchased_course( $course->get_id() ) ) { |
| 545 |
return; |
| 546 |
} |
| 547 |
|
| 548 |
$user = learn_press_get_current_user(); |
| 549 |
|
| 550 |
if ( $user && ! $user->has_enrolled_or_finished( $course->get_id() ) ) { |
| 551 |
// Remove all another buttons |
| 552 |
learn_press_remove_course_buttons(); |
| 553 |
learn_press_get_template( 'single-course/buttons/external-link.php' ); |
| 554 |
// Add back other buttons for other courses |
| 555 |
add_action( 'learn-press/after-course-buttons', 'learn_press_add_course_buttons' ); |
| 556 |
} |
| 557 |
} |
| 558 |
|
| 559 |
public function popup_header() { |
| 560 |
$user = learn_press_get_current_user(); |
| 561 |
$course = learn_press_get_course(); |
| 562 |
|
| 563 |
if ( ! $user || ! $course ) { |
| 564 |
return; |
| 565 |
} |
| 566 |
|
| 567 |
$percentage = 0; |
| 568 |
$total_items = 0; |
| 569 |
$completed_items = 0; |
| 570 |
$course_data = $user->get_course_data( $course->get_id() ); |
| 571 |
|
| 572 |
if ( $course_data && ! $course->is_no_required_enroll() ) { |
| 573 |
$course_results = $course_data->get_result(); |
| 574 |
$completed_items = $course_results['completed_items']; |
| 575 |
$total_items = $course_results['count_items']; |
| 576 |
$percentage = $course_results['count_items'] ? absint( $course_results['completed_items'] / $course_results['count_items'] * 100 ) : 0; |
| 577 |
} |
| 578 |
|
| 579 |
learn_press_get_template( 'single-course/content-item/popup-header', compact( 'user', 'course', 'total_items', 'completed_items', 'percentage' ) ); |
| 580 |
} |
| 581 |
|
| 582 |
public function popup_sidebar() { |
| 583 |
learn_press_get_template( 'single-course/content-item/popup-sidebar' ); |
| 584 |
} |
| 585 |
|
| 586 |
/** |
| 587 |
* Get single item's course |
| 588 |
*/ |
| 589 |
public function popup_content() { |
| 590 |
learn_press_get_template( 'single-course/content-item/popup-content' ); |
| 591 |
} |
| 592 |
|
| 593 |
public function popup_footer() { |
| 594 |
learn_press_get_template( 'single-course/content-item/popup-footer' ); |
| 595 |
} |
| 596 |
|
| 597 |
public function popup_footer_nav() { |
| 598 |
$course = learn_press_get_course(); |
| 599 |
if ( ! $course ) { |
| 600 |
return; |
| 601 |
} |
| 602 |
|
| 603 |
$next_item = false; |
| 604 |
$prev_item = false; |
| 605 |
|
| 606 |
$next_id = $course->get_next_item(); |
| 607 |
$prev_id = $course->get_prev_item(); |
| 608 |
|
| 609 |
if ( $next_id ) { |
| 610 |
$next_item = $course->get_item( $next_id ); |
| 611 |
if ( $next_item instanceof LP_Course_Item ) { |
| 612 |
$next_item->set_course( $course->get_id() ); |
| 613 |
} |
| 614 |
} |
| 615 |
|
| 616 |
if ( $prev_id ) { |
| 617 |
$prev_item = $course->get_item( $prev_id ); |
| 618 |
if ( $prev_item instanceof LP_Course_Item ) { |
| 619 |
$prev_item->set_course( $course->get_id() ); |
| 620 |
} |
| 621 |
} |
| 622 |
|
| 623 |
if ( ! $prev_item && ! $next_item ) { |
| 624 |
return; |
| 625 |
} |
| 626 |
|
| 627 |
learn_press_get_template( |
| 628 |
'single-course/content-item/nav.php', |
| 629 |
array( |
| 630 |
'next_item' => $next_item, |
| 631 |
'prev_item' => $prev_item, |
| 632 |
) |
| 633 |
); |
| 634 |
} |
| 635 |
|
| 636 |
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(); |
| 639 |
|
| 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 ) ); |
| 643 |
} |
| 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 |
|
| 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' ); |
| 661 |
} |
| 662 |
} |
| 663 |
|
| 664 |
/** |
| 665 |
* Get template content item's course |
| 666 |
*/ |
| 667 |
public function course_content_item() { |
| 668 |
learn_press_get_template( 'single-course/content-item' ); |
| 669 |
} |
| 670 |
|
| 671 |
public function courses_loop_item_meta() { |
| 672 |
learn_press_get_template( 'loop/course/meta' ); |
| 673 |
} |
| 674 |
|
| 675 |
public function courses_loop_item_info_begin() { |
| 676 |
learn_press_get_template( 'loop/course/info-begin' ); |
| 677 |
} |
| 678 |
|
| 679 |
public function courses_loop_item_info_end() { |
| 680 |
learn_press_get_template( 'loop/course/info-end' ); |
| 681 |
} |
| 682 |
|
| 683 |
public function courses_loop_item_price() { |
| 684 |
$course = learn_press_get_course(); |
| 685 |
if ( ! $course ) { |
| 686 |
return; |
| 687 |
} |
| 688 |
|
| 689 |
$price_html = $course->get_course_price_html(); |
| 690 |
learn_press_get_template( 'loop/course/price', compact( 'course', 'price_html' ) ); |
| 691 |
} |
| 692 |
|
| 693 |
public function begin_courses_loop() { |
| 694 |
learn_press_get_template( 'loop/course/loop-begin.php' ); |
| 695 |
} |
| 696 |
|
| 697 |
public function end_courses_loop() { |
| 698 |
learn_press_get_template( 'loop/course/loop-end.php' ); |
| 699 |
} |
| 700 |
|
| 701 |
public function course_item_content() { |
| 702 |
$course = learn_press_get_course(); |
| 703 |
$item = LP_Global::course_item(); |
| 704 |
|
| 705 |
// if ( $item->is_blocked() ) { |
| 706 |
// learn_press_get_template( 'global/block-content.php' ); |
| 707 |
// |
| 708 |
// return; |
| 709 |
// } |
| 710 |
|
| 711 |
/** |
| 712 |
* Fix only for WPBakery load style inline |
| 713 |
* custom CSS is provided, load inline style. |
| 714 |
* |
| 715 |
* @editor tuanta |
| 716 |
* @since 3.2.8.1 |
| 717 |
*/ |
| 718 |
$shortcodes_custom_css = get_post_meta( $item->get_id(), '_wpb_shortcodes_custom_css', true ); |
| 719 |
|
| 720 |
if ( ! empty( $shortcodes_custom_css ) ) { |
| 721 |
$shortcodes_custom_css = strip_tags( $shortcodes_custom_css ); |
| 722 |
echo '<style type="text/css" data-type="vc_shortcodes-custom-css">'; |
| 723 |
echo wp_kses_post( $shortcodes_custom_css ); |
| 724 |
echo '</style>'; |
| 725 |
} |
| 726 |
// End |
| 727 |
|
| 728 |
// Get timestamp remaining duration of course |
| 729 |
/*$course_item = $item->get_course(); |
| 730 |
if ( ! $course_item ) { |
| 731 |
return; |
| 732 |
}*/ |
| 733 |
|
| 734 |
$timestamp_remaining = $course->timestamp_remaining_duration(); |
| 735 |
|
| 736 |
if ( $timestamp_remaining > 0 ) { |
| 737 |
echo '<input type="hidden" name="lp-course-timestamp-remaining" value="' . esc_attr( $timestamp_remaining ) . '">'; |
| 738 |
} |
| 739 |
// End |
| 740 |
|
| 741 |
$item_template_name = learn_press_locate_template( 'single-course/content-item-' . $item->get_item_type() . '.php' ); |
| 742 |
|
| 743 |
if ( file_exists( $item_template_name ) ) { |
| 744 |
learn_press_get_template( 'single-course/content-item-' . $item->get_item_type() . '.php' ); |
| 745 |
} else { |
| 746 |
echo esc_html( sprintf( 'File %s not exists', $item_template_name ) ); |
| 747 |
} |
| 748 |
} |
| 749 |
|
| 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 |
public function item_lesson_title() { |
| 779 |
$item = LP_Global::course_item(); |
| 780 |
$format = $item->get_format(); |
| 781 |
$format_template = learn_press_locate_template( "content-lesson/{$format}/title.php" ); |
| 782 |
|
| 783 |
if ( 'standard' !== $format && file_exists( $format_template ) ) { |
| 784 |
include $format_template; |
| 785 |
|
| 786 |
return; |
| 787 |
} |
| 788 |
learn_press_get_template( 'content-lesson/title.php', array( 'lesson' => $item ) ); |
| 789 |
} |
| 790 |
|
| 791 |
public function item_lesson_content() { |
| 792 |
$item = LP_Global::course_item(); |
| 793 |
$format = $item->get_format(); |
| 794 |
$format_template = learn_press_locate_template( "content-lesson/{$format}/content.php" ); |
| 795 |
|
| 796 |
if ( 'standard' !== $format && file_exists( $format_template ) ) { |
| 797 |
include $format_template; |
| 798 |
|
| 799 |
return; |
| 800 |
} |
| 801 |
do_action( 'learn-press/lesson-start', $item ); |
| 802 |
|
| 803 |
learn_press_get_template( 'content-lesson/content.php', array( 'lesson' => $item ) ); |
| 804 |
} |
| 805 |
|
| 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 |
/** |
| 819 |
* Get template button complete lesson |
| 820 |
*/ |
| 821 |
public function item_lesson_complete_button() { |
| 822 |
$user = learn_press_get_current_user(); |
| 823 |
$course = learn_press_get_course(); |
| 824 |
$item = LP_Global::course_item(); |
| 825 |
|
| 826 |
if ( ! $user || ! $course || ! $user->is_course_in_progress( $course->get_id() ) ) { |
| 827 |
return; |
| 828 |
} |
| 829 |
|
| 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 |
} |
| 834 |
|
| 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 |
} |
| 844 |
|
| 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; |
| 852 |
} |
| 853 |
|
| 854 |
$lesson = LP_Global::course_item(); |
| 855 |
if ( ! $lesson ) { |
| 856 |
return; |
| 857 |
} |
| 858 |
|
| 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 |
/** |
| 871 |
* Template show count items |
| 872 |
* |
| 873 |
* @since 4.0.0 |
| 874 |
* @version 1.0.1 |
| 875 |
* @editor tungnx |
| 876 |
*/ |
| 877 |
public function count_object() { |
| 878 |
$course = learn_press_get_course(); |
| 879 |
|
| 880 |
if ( ! $course ) { |
| 881 |
return; |
| 882 |
} |
| 883 |
|
| 884 |
$lessons = $course->count_items( LP_LESSON_CPT ); |
| 885 |
$quizzes = $course->count_items( LP_QUIZ_CPT ); |
| 886 |
$students = $course->count_students(); |
| 887 |
|
| 888 |
$counts = apply_filters( |
| 889 |
'learnpress/course/count/items', |
| 890 |
array( |
| 891 |
'lesson' => sprintf( |
| 892 |
'<span class="meta-number">' . _n( '%d lesson', '%d lessons', $lessons, 'learnpress' ) . '</span>', |
| 893 |
$lessons |
| 894 |
), |
| 895 |
'quiz' => sprintf( |
| 896 |
'<span class="meta-number">' . _n( '%d quiz', '%d quizzes', $quizzes, 'learnpress' ) . '</span>', |
| 897 |
$quizzes |
| 898 |
), |
| 899 |
'student' => sprintf( |
| 900 |
'<span class="meta-number">' . _n( '%d student', '%d students', $students, 'learnpress' ) . '</span>', |
| 901 |
$students |
| 902 |
), |
| 903 |
), |
| 904 |
array( $lessons, $quizzes, $students ) |
| 905 |
); |
| 906 |
|
| 907 |
foreach ( $counts as $object => $count ) { |
| 908 |
learn_press_get_template( |
| 909 |
'single-course/meta/count', |
| 910 |
array( |
| 911 |
'count' => $count, |
| 912 |
'object' => $object, |
| 913 |
) |
| 914 |
); |
| 915 |
} |
| 916 |
} |
| 917 |
|
| 918 |
public function course_extra_boxes() { |
| 919 |
$course = LP_Course::get_course( get_the_ID() ); |
| 920 |
$boxes = apply_filters( |
| 921 |
'learn-press/course-extra-boxes-data', |
| 922 |
array( |
| 923 |
array( |
| 924 |
'title' => __( 'Requirements', 'learnpress' ), |
| 925 |
'items' => $course->get_extra_info( 'requirements' ), |
| 926 |
), |
| 927 |
array( |
| 928 |
'title' => __( 'Features', 'learnpress' ), |
| 929 |
'items' => $course->get_extra_info( 'key_features' ), |
| 930 |
), |
| 931 |
array( |
| 932 |
'title' => __( 'Target audiences', 'learnpress' ), |
| 933 |
'items' => $course->get_extra_info( 'target_audiences' ), |
| 934 |
), |
| 935 |
) |
| 936 |
); |
| 937 |
|
| 938 |
$is_checked = 0; |
| 939 |
foreach ( $boxes as $box ) { |
| 940 |
|
| 941 |
if ( ! isset( $box['items'] ) || ! $box['items'] ) { |
| 942 |
continue; |
| 943 |
} |
| 944 |
|
| 945 |
if ( ! $is_checked ) { |
| 946 |
$box['checked'] = true; |
| 947 |
$is_checked = true; |
| 948 |
} |
| 949 |
|
| 950 |
learn_press_get_template( 'single-course/extra-info', $box ); |
| 951 |
} |
| 952 |
|
| 953 |
} |
| 954 |
|
| 955 |
public function faqs() { |
| 956 |
$course = LP_Course::get_course( get_the_ID() ); |
| 957 |
$faqs = $course->get_faqs(); |
| 958 |
if ( ! $faqs ) { |
| 959 |
return; |
| 960 |
} |
| 961 |
|
| 962 |
foreach ( $faqs as $faq ) { |
| 963 |
learn_press_get_template( 'single-course/tabs/faqs', $faq ); |
| 964 |
} |
| 965 |
} |
| 966 |
|
| 967 |
public function sidebar() { |
| 968 |
} |
| 969 |
|
| 970 |
public function course_featured_review() { |
| 971 |
$review_content = get_post_meta( $this->course->get_id(), '_lp_featured_review', true ); |
| 972 |
|
| 973 |
if ( ! $review_content ) { |
| 974 |
return; |
| 975 |
} |
| 976 |
|
| 977 |
$user = learn_press_get_current_user(); |
| 978 |
|
| 979 |
if ( ! $user ) { |
| 980 |
return; |
| 981 |
} |
| 982 |
|
| 983 |
if ( $user->has_enrolled_or_finished( $this->course->get_id() ) ) { |
| 984 |
return; |
| 985 |
} |
| 986 |
|
| 987 |
learn_press_get_template( |
| 988 |
'single-course/featured-review', |
| 989 |
array( |
| 990 |
'review_content' => $review_content, |
| 991 |
'review_value' => 5, |
| 992 |
) |
| 993 |
); |
| 994 |
} |
| 995 |
|
| 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 |
public function has_sidebar() { |
| 1006 |
$actions = array( |
| 1007 |
'learn-press/before-course-summary-sidebar', |
| 1008 |
'learn-press/course-summary-sidebar', |
| 1009 |
'learn-press/after-course-summary-sidebar', |
| 1010 |
); |
| 1011 |
|
| 1012 |
foreach ( $actions as $action ) { |
| 1013 |
if ( has_action( $action ) ) { |
| 1014 |
return true; |
| 1015 |
} |
| 1016 |
} |
| 1017 |
|
| 1018 |
return false; |
| 1019 |
} |
| 1020 |
|
| 1021 |
// button readmore in archive courses |
| 1022 |
public function course_readmore() { |
| 1023 |
?> |
| 1024 |
<div class="course-readmore"> |
| 1025 |
<a href="<?php the_permalink(); ?>"><?php echo esc_html__( 'View More', 'learnpress' ); ?></a> |
| 1026 |
</div> |
| 1027 |
<?php |
| 1028 |
} |
| 1029 |
|
| 1030 |
public function course_item_comments() { |
| 1031 |
global $post; |
| 1032 |
$course = learn_press_get_course(); |
| 1033 |
if ( ! $course ) { |
| 1034 |
return; |
| 1035 |
} |
| 1036 |
|
| 1037 |
$item = LP_Global::course_item(); |
| 1038 |
if ( ! $item ) { |
| 1039 |
return; |
| 1040 |
} |
| 1041 |
|
| 1042 |
$user = learn_press_get_current_user(); |
| 1043 |
|
| 1044 |
// if ( ! $user->is_admin() && ! $user->has_course_status( $course->get_id(), array( 'enrolled', 'finished' ) ) ) { |
| 1045 |
// return; |
| 1046 |
// } |
| 1047 |
|
| 1048 |
if ( $item->setup_postdata() ) { |
| 1049 |
|
| 1050 |
if ( comments_open() || get_comments_number() ) { |
| 1051 |
learn_press_get_template( 'single-course/item-comments' ); |
| 1052 |
} |
| 1053 |
$item->reset_postdata(); |
| 1054 |
} |
| 1055 |
} |
| 1056 |
|
| 1057 |
public function course_comment_template() { |
| 1058 |
global $post; |
| 1059 |
|
| 1060 |
if ( comments_open() || get_comments_number() ) { |
| 1061 |
add_filter( 'deprecated_file_trigger_error', '__return_false' ); |
| 1062 |
comments_template(); |
| 1063 |
remove_filter( 'deprecated_file_trigger_error', '__return_false' ); |
| 1064 |
} |
| 1065 |
} |
| 1066 |
|
| 1067 |
/** |
| 1068 |
* Show info time handle of user |
| 1069 |
* |
| 1070 |
* @throws Exception |
| 1071 |
*/ |
| 1072 |
public function user_time() { |
| 1073 |
$user = learn_press_get_current_user(); |
| 1074 |
|
| 1075 |
if ( ! $user ) { |
| 1076 |
return; |
| 1077 |
} |
| 1078 |
|
| 1079 |
if ( ! $user->has_enrolled_or_finished( $this->course->get_id() ) ) { |
| 1080 |
return; |
| 1081 |
} |
| 1082 |
|
| 1083 |
/** |
| 1084 |
* @var LP_User_Item_Course |
| 1085 |
*/ |
| 1086 |
$user_course = $user->get_course_data( $this->course->get_id() ); |
| 1087 |
|
| 1088 |
if ( ! $user_course ) { |
| 1089 |
return; |
| 1090 |
} |
| 1091 |
|
| 1092 |
$status = $user_course->get_status(); |
| 1093 |
$start_time = $user_course->get_start_time(); |
| 1094 |
$end_time = $user_course->get_end_time(); |
| 1095 |
$expiration_time = $user_course->get_expiration_time(); |
| 1096 |
|
| 1097 |
learn_press_get_template( |
| 1098 |
'single-course/sidebar/user-time', |
| 1099 |
compact( 'status', 'start_time', 'end_time', 'expiration_time' ) |
| 1100 |
); |
| 1101 |
} |
| 1102 |
|
| 1103 |
/** |
| 1104 |
* Animation placholder in user-progress file. |
| 1105 |
* Content will show in class-rest-lazy-load-controller file. |
| 1106 |
* |
| 1107 |
* @return void |
| 1108 |
* @throws Exception |
| 1109 |
* @author Nhamdv. |
| 1110 |
*/ |
| 1111 |
public function user_progress() { |
| 1112 |
if ( ! is_user_logged_in() ) { |
| 1113 |
return; |
| 1114 |
} |
| 1115 |
|
| 1116 |
$course = learn_press_get_course(); |
| 1117 |
$user = learn_press_get_current_user(); |
| 1118 |
|
| 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 ) { |
| 1128 |
echo '<div class="lp-course-progress-wrapper">'; |
| 1129 |
echo lp_skeleton_animation_html( 3 ); |
| 1130 |
echo '</div>'; |
| 1131 |
} else { |
| 1132 |
$course_data = $user->get_course_data( $course->get_id() ); |
| 1133 |
if ( ! $course_data ) { |
| 1134 |
return; |
| 1135 |
} |
| 1136 |
|
| 1137 |
$course_results = $course_data->calculate_course_results(); |
| 1138 |
|
| 1139 |
learn_press_get_template( |
| 1140 |
'single-course/sidebar/user-progress', |
| 1141 |
compact( 'user', 'course', 'course_data', 'course_results' ) |
| 1142 |
); |
| 1143 |
} |
| 1144 |
} |
| 1145 |
|
| 1146 |
public function course_extra_boxes_position_control() { |
| 1147 |
$course = LP_Course::get_course( get_the_ID() ); |
| 1148 |
$user = learn_press_get_current_user(); |
| 1149 |
|
| 1150 |
if ( ! $user || ! $course ) { |
| 1151 |
return; |
| 1152 |
} |
| 1153 |
|
| 1154 |
$enrolled = $user->has_enrolled_course( $course->get_id() ); |
| 1155 |
if ( $enrolled ) { |
| 1156 |
remove_action( |
| 1157 |
'learn-press/course-content-summary', |
| 1158 |
LP()->template( 'course' )->func( 'course_extra_boxes' ), |
| 1159 |
40 |
| 1160 |
); |
| 1161 |
} else { |
| 1162 |
remove_action( |
| 1163 |
'learn-press/course-content-summary', |
| 1164 |
LP()->template( 'course' )->func( 'course_extra_boxes' ), |
| 1165 |
70 |
| 1166 |
); |
| 1167 |
} |
| 1168 |
} |
| 1169 |
|
| 1170 |
/** |
| 1171 |
* Template for case not any courses |
| 1172 |
* |
| 1173 |
* @author Nhamdv |
| 1174 |
* @since 4.1.2 |
| 1175 |
*/ |
| 1176 |
public function no_courses_found() { |
| 1177 |
learn_press_get_template( 'global/no-courses-found' ); |
| 1178 |
} |
| 1179 |
} |
| 1180 |
|
| 1181 |
return new LP_Template_Course(); |
| 1182 |
|