| @@ -10,8 +10,11 @@ | ||
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Prevent loading this file directly |
| 13 | 13 | */ |
| 14 | + | |
| 15 | +use LearnPress\Models\UserItems\UserCourseModel; | |
| 16 | + | |
| 14 | 17 | defined( 'ABSPATH' ) || exit(); |
| 15 | 18 | |
| 16 | 19 | if ( ! class_exists( 'LP_Abstract_User' ) ) { |
| 17 | 20 | |
| @@ -79,9 +82,8 @@ | ||
| 79 | 82 | |
| 80 | 83 | if ( $this->get_id() > 0 ) { |
| 81 | 84 | $this->load(); |
| 82 | 85 | } |
| 83 | - | |
| 84 | 86 | } |
| 85 | 87 | |
| 86 | 88 | /** |
| 87 | 89 | * Load user data from curd |
| @@ -95,14 +97,14 @@ | ||
| 95 | 97 | * |
| 96 | 98 | * @param int $course_id . |
| 97 | 99 | * |
| 98 | 100 | * @return LP_User_Item_Course|bool |
| 99 | - * @version 3.1.3 | |
| 100 | - * @editor tungnx | |
| 101 | + * @version 3.1.4 | |
| 101 | 102 | * @modify 4.1.3 |
| 102 | 103 | */ |
| 103 | 104 | public function get_course_data( int $course_id = 0 ) { |
| 104 | - $lp_user_items_db = LP_User_Items_DB::getInstance(); | |
| 105 | + $lp_user_items_db = LP_User_Items_DB::getInstance(); | |
| 106 | + $object_course_data = false; | |
| 105 | 107 | |
| 106 | 108 | try { |
| 107 | 109 | if ( ! $course_id ) { |
| 108 | 110 | $course_id = get_the_ID(); |
| @@ -107,21 +109,14 @@ | ||
| 107 | 109 | if ( ! $course_id ) { |
| 108 | 110 | $course_id = get_the_ID(); |
| 109 | 111 | } |
| 110 | 112 | |
| 111 | - /*if ( $this instanceof LP_User_Guest ) { | |
| 112 | - throw new Exception( 'User is Guest' ); | |
| 113 | - }*/ | |
| 114 | - | |
| 115 | - $filter = new LP_User_Items_Filter(); | |
| 116 | - $filter->item_id = $course_id; | |
| 117 | - $filter->user_id = $this->get_id(); | |
| 118 | - $last_user_course = $lp_user_items_db->get_last_user_course( $filter ); | |
| 119 | - | |
| 120 | - if ( $last_user_course ) { | |
| 121 | - $object_course_data = new LP_User_Item_Course( $last_user_course ); | |
| 113 | + $userCourseModel = UserCourseModel::find( $this->get_id(), $course_id, true ); | |
| 114 | + if ( $userCourseModel ) { | |
| 115 | + $userCourseArr = (array) $userCourseModel; | |
| 116 | + $userCourseArr['user_item_id'] = $userCourseModel->get_user_item_id(); | |
| 117 | + $object_course_data = new LP_User_Item_Course( $userCourseArr ); | |
| 122 | 118 | } else { |
| 123 | - $object_course_data = false; | |
| 124 | 119 | /** |
| 125 | 120 | * Todo: some themes still not check false, so still use below code.\ |
| 126 | 121 | * @editor tungnx 4.1.6.9 |
| 127 | 122 | */ |
| @@ -134,8 +129,28 @@ | ||
| 134 | 129 | return $object_course_data; |
| 135 | 130 | } |
| 136 | 131 | |
| 137 | 132 | /** |
| 133 | + * Get course attend of user not Guest. | |
| 134 | + * Replace get_course_data method. | |
| 135 | + * | |
| 136 | + * @param int $course_id | |
| 137 | + * @return false|UserCourseModel | |
| 138 | + * @since 4.2.5 | |
| 139 | + * @version 1.0.1 | |
| 140 | + */ | |
| 141 | + public function get_course_attend( int $course_id = 0 ) { | |
| 142 | + if ( $this instanceof LP_User_Guest ) { | |
| 143 | + return false; | |
| 144 | + } | |
| 145 | + | |
| 146 | + $filter = new LP_User_Items_Filter(); | |
| 147 | + $filter->item_id = $course_id; | |
| 148 | + $filter->user_id = $this->get_id(); | |
| 149 | + return UserCourseModel::get_user_item_model_from_db( $filter ); | |
| 150 | + } | |
| 151 | + | |
| 152 | + /** | |
| 138 | 153 | * Get user course item. |
| 139 | 154 | * |
| 140 | 155 | * @param int $item_id |
| 141 | 156 | * @param int $course_id |
| @@ -450,18 +465,16 @@ | ||
| 450 | 465 | $status = ''; |
| 451 | 466 | |
| 452 | 467 | if ( ! $course_id ) { |
| 453 | 468 | $course_id = get_the_ID(); |
| 469 | + if ( ! $course_id ) { | |
| 470 | + return $status; | |
| 471 | + } | |
| 454 | 472 | } |
| 455 | 473 | |
| 456 | - if ( ! $course_id ) { | |
| 457 | - return $status; | |
| 458 | - } | |
| 459 | - | |
| 460 | 474 | $item = $this->get_item( $item_id, $course_id, true ); |
| 461 | - | |
| 462 | - if ( false !== $item ) { | |
| 463 | - $status = $item['status']; | |
| 475 | + if ( $item instanceof LP_User_Item ) { | |
| 476 | + $status = $item->get_status(); | |
| 464 | 477 | } |
| 465 | 478 | |
| 466 | 479 | return apply_filters( 'learn-press/user-item-status', $status, $item_id, $this->get_id(), $course_id ); |
| 467 | 480 | } |
| @@ -525,58 +538,8 @@ | ||
| 525 | 538 | return $result; |
| 526 | 539 | } |
| 527 | 540 | |
| 528 | 541 | /** |
| 529 | - * Mark question that user has checked. | |
| 530 | - * | |
| 531 | - * @param int $question_id | |
| 532 | - * @param int $quiz_id | |
| 533 | - * @param int $course_id | |
| 534 | - * | |
| 535 | - * @return WP_Error|mixed | |
| 536 | - * @since 3.0.0 | |
| 537 | - */ | |
| 538 | - public function hint( $question_id, $quiz_id, $course_id ) { | |
| 539 | - $course = learn_press_get_course( $course_id ); | |
| 540 | - if ( ! $course ) { | |
| 541 | - return false; | |
| 542 | - } | |
| 543 | - | |
| 544 | - if ( ! $course->has_item( $quiz_id ) ) { | |
| 545 | - return false; | |
| 546 | - } | |
| 547 | - | |
| 548 | - /** | |
| 549 | - * @var $quiz LP_Quiz | |
| 550 | - */ | |
| 551 | - $quiz = $course->get_item( $quiz_id ); | |
| 552 | - if ( ! $quiz instanceof LP_Course_Item_Quiz ) { | |
| 553 | - return false; | |
| 554 | - } | |
| 555 | - | |
| 556 | - if ( ! $quiz->has_question( $question_id ) ) { | |
| 557 | - return false; | |
| 558 | - } | |
| 559 | - | |
| 560 | - $quiz_data = $this->get_item_data( $quiz_id, $course_id ); | |
| 561 | - $remain = $quiz_data->hint( $question_id ); | |
| 562 | - if ( false === $remain ) { | |
| 563 | - return new WP_Error( 1001, __( 'You can not hint question.', 'learnpress' ) ); | |
| 564 | - } | |
| 565 | - | |
| 566 | - return $remain; | |
| 567 | - } | |
| 568 | - | |
| 569 | - public function get_quiz_last_results( $quiz_id ) { | |
| 570 | - $results = $this->get_course_info( $quiz_id ); | |
| 571 | - if ( $results ) { | |
| 572 | - $results = reset( $results ); | |
| 573 | - } | |
| 574 | - | |
| 575 | - return apply_filters( 'learn_press_user_quiz_last_results', $results, $quiz_id, $this ); | |
| 576 | - } | |
| 577 | - | |
| 578 | - /** | |
| 579 | 542 | * Check if user has at least one role. |
| 580 | 543 | * |
| 581 | 544 | * @param array|string $roles |
| 582 | 545 | * |
| @@ -608,30 +571,8 @@ | ||
| 608 | 571 | |
| 609 | 572 | return $is; |
| 610 | 573 | } |
| 611 | 574 | |
| 612 | - /** | |
| 613 | - * | |
| 614 | - * Check what the user can do | |
| 615 | - * | |
| 616 | - * @param $role | |
| 617 | - * | |
| 618 | - * @return mixed | |
| 619 | - * @throws Exception | |
| 620 | - */ | |
| 621 | - public function can( $role ) { | |
| 622 | - _deprecated_function( __FUNCTION__, '3.0.8' ); | |
| 623 | - $args = func_get_args(); | |
| 624 | - unset( $args[0] ); | |
| 625 | - $method = 'can_' . preg_replace( '!-!', '_', $role ); | |
| 626 | - $callback = array( $this, $method ); | |
| 627 | - if ( is_callable( $callback ) ) { | |
| 628 | - return call_user_func_array( $callback, $args ); | |
| 629 | - } else { | |
| 630 | - throw new Exception( sprintf( __( 'The role %s for user doesn\'t exist', 'learnpress' ), $role ) ); | |
| 631 | - } | |
| 632 | - } | |
| 633 | - | |
| 634 | 575 | public function can_edit_item( $item_id, $course_id = 0 ) { |
| 635 | 576 | $return = $this->is_admin(); |
| 636 | 577 | |
| 637 | 578 | if ( ! $return ) { |
| @@ -646,24 +587,8 @@ | ||
| 646 | 587 | return apply_filters( 'learn_press_user_can_edit_item', $return, $item_id, $course_id, $this->get_id() ); |
| 647 | 588 | } |
| 648 | 589 | |
| 649 | 590 | /** |
| 650 | - * Check if user can finish course by getting current progress | |
| 651 | - * and compares with course passing condition. | |
| 652 | - * | |
| 653 | - * @param int $course_id | |
| 654 | - * | |
| 655 | - * @return bool | |
| 656 | - * @editor tungnx | |
| 657 | - * @modify 4.1.3 | |
| 658 | - */ | |
| 659 | - public function can_finish_course( int $course_id ) { | |
| 660 | - _deprecated_function( __FUNCTION__, '4.1.3', 'is_course_finished' ); | |
| 661 | - | |
| 662 | - return true; | |
| 663 | - } | |
| 664 | - | |
| 665 | - /** | |
| 666 | 591 | * Check if course has any passed status for an user. |
| 667 | 592 | * Statuses: depending on value of column `status` in user_items. |
| 668 | 593 | * - purchased: bought and order is completed, `start_date` and `end_date` is null |
| 669 | 594 | * - enrolled: value of column `status` in user_items is enrolled |
| @@ -700,8 +625,11 @@ | ||
| 700 | 625 | $course = learn_press_get_course( $course_id ); |
| 701 | 626 | |
| 702 | 627 | if ( $course ) { |
| 703 | 628 | $user_course = $this->get_course_data( $course_id ); |
| 629 | + if ( ! $user_course ) { | |
| 630 | + return $return; | |
| 631 | + } | |
| 704 | 632 | |
| 705 | 633 | $result = $user_course->calculate_course_results(); |
| 706 | 634 | |
| 707 | 635 | // Save result for course |
| @@ -713,13 +641,24 @@ | ||
| 713 | 641 | $graduation = LP_COURSE_GRADUATION_FAILED; |
| 714 | 642 | } |
| 715 | 643 | |
| 716 | 644 | $user_course->set_graduation( $graduation ); |
| 717 | - $user_course->save(); | |
| 645 | + //$user_course->save(); | |
| 646 | + $return = $user_course->complete( LP_COURSE_FINISHED ); | |
| 718 | 647 | |
| 719 | - $return = $user_course->complete( 'finished' ); | |
| 648 | + if ( $return ) { | |
| 649 | + /** | |
| 650 | + * LP_User_Item::complete() writes straight to the table, so it never runs | |
| 651 | + * UserCourseModel::clean_caches() the way UserItemModel::save() does. The | |
| 652 | + * cached model still reports the enrollment as in progress, and that cache | |
| 653 | + * outlives the request wherever a persistent object cache is installed - the | |
| 654 | + * course then reads back unfinished and keeps offering "Finish course". | |
| 655 | + */ | |
| 656 | + $userCourseModel = UserCourseModel::find( $this->get_id(), $course_id ); | |
| 657 | + if ( $userCourseModel instanceof UserCourseModel ) { | |
| 658 | + $userCourseModel->clean_caches(); | |
| 659 | + } | |
| 720 | 660 | |
| 721 | - if ( $return ) { | |
| 722 | 661 | do_action( 'learn-press/user-course-finished', $course_id, $this->get_id(), $return ); |
| 723 | 662 | } |
| 724 | 663 | } |
| 725 | 664 | |
| @@ -765,22 +704,8 @@ | ||
| 765 | 704 | public function is_author_of( $post_id ) { |
| 766 | 705 | return absint( get_post_field( 'post_author', $post_id ) ) === $this->get_id(); |
| 767 | 706 | } |
| 768 | 707 | |
| 769 | - public function has( $role ) { | |
| 770 | - _deprecated_function( __FUNCTION__, '3.0.8' ); | |
| 771 | - | |
| 772 | - $args = func_get_args(); | |
| 773 | - unset( $args[0] ); | |
| 774 | - $method = 'has_' . preg_replace( '!-!', '_', $role ); | |
| 775 | - $callback = array( $this, $method ); | |
| 776 | - if ( is_callable( $callback ) ) { | |
| 777 | - return call_user_func_array( $callback, $args ); | |
| 778 | - } else { | |
| 779 | - throw new Exception( sprintf( __( 'The role %s for user doesn\'t exist', 'learnpress' ), $role ) ); | |
| 780 | - } | |
| 781 | - } | |
| 782 | - | |
| 783 | 708 | public function get( $role ) { |
| 784 | 709 | $args = func_get_args(); |
| 785 | 710 | unset( $args[0] ); |
| 786 | 711 | $method = 'get_' . preg_replace( '!-!', '_', $role ); |
| @@ -787,9 +712,9 @@ | ||
| 787 | 712 | $callback = array( $this, $method ); |
| 788 | 713 | if ( is_callable( $callback ) ) { |
| 789 | 714 | return call_user_func_array( $callback, $args ); |
| 790 | 715 | } else { |
| 791 | - throw new Exception( sprintf( __( 'The role %s for user doesn\'t exist', 'learnpress' ), $role ) ); | |
| 716 | + throw new Exception( sprintf( __( 'The role %s for the user doesn\'t exist', 'learnpress' ), $role ) ); | |
| 792 | 717 | } |
| 793 | 718 | } |
| 794 | 719 | |
| 795 | 720 | /** |
| @@ -829,9 +754,9 @@ | ||
| 829 | 754 | * @param int $quiz_id |
| 830 | 755 | * @param int $course_id |
| 831 | 756 | * |
| 832 | 757 | * @return bool |
| 833 | - * @depecated 4.1.6.9 | |
| 758 | + * @deprecated 4.1.6.9 | |
| 834 | 759 | */ |
| 835 | 760 | /*public function has_completed_quiz( $quiz_id, $course_id = 0 ): bool { |
| 836 | 761 | return $this->get_item_status( $quiz_id, $course_id ) == 'completed'; |
| 837 | 762 | }*/ |
| @@ -869,14 +794,11 @@ | ||
| 869 | 794 | if ( $item->is_completed() ) { |
| 870 | 795 | throw new Exception( __( 'You have already completed this lesson.', 'learnpress' ) ); |
| 871 | 796 | } |
| 872 | 797 | |
| 873 | - $item->set_end_time( time() ); | |
| 874 | - $item->set_status( 'completed' ); | |
| 875 | 798 | $item->set_graduation( 'passed' ); |
| 799 | + $updated = $item->complete(); | |
| 876 | 800 | |
| 877 | - $updated = $item->update(); | |
| 878 | - | |
| 879 | 801 | do_action( 'learn-press/user-completed-lesson', $lesson_id, $course_id, $this->get_id() ); |
| 880 | 802 | } catch ( Throwable $e ) { |
| 881 | 803 | $result = new WP_Error( 'error_lesson_complete', $e->getMessage() ); |
| 882 | 804 | } |
| @@ -890,9 +812,9 @@ | ||
| 890 | 812 | * @param int $lesson_id Lesson id. |
| 891 | 813 | * @param null $course_id Course id. |
| 892 | 814 | * |
| 893 | 815 | * @return bool |
| 894 | - * @depecated 4.1.6.9 | |
| 816 | + * @deprecated 4.1.6.9 | |
| 895 | 817 | */ |
| 896 | 818 | public function has_completed_lesson( $lesson_id = 0, $course_id = null ): bool { |
| 897 | 819 | return 'completed' === $this->get_item_status( $lesson_id, $course_id ); |
| 898 | 820 | } |
| @@ -918,9 +840,9 @@ | ||
| 918 | 840 | /** |
| 919 | 841 | * @param $course_id |
| 920 | 842 | * |
| 921 | 843 | * @return int |
| 922 | - * @depecated 4.1.6.9 | |
| 844 | + * @deprecated 4.1.6.9 | |
| 923 | 845 | */ |
| 924 | 846 | public function get_course_history_id( $course_id ) { |
| 925 | 847 | $history = $this->get_course_info( $course_id ); |
| 926 | 848 | |
| @@ -1015,29 +937,8 @@ | ||
| 1015 | 937 | return apply_filters( 'learn_press_user_has_completed_item', $return, $item ); |
| 1016 | 938 | } |
| 1017 | 939 | |
| 1018 | 940 | /** |
| 1019 | - * Get the remaining time of a course for the user. | |
| 1020 | - * | |
| 1021 | - * @param int $course_id | |
| 1022 | - * | |
| 1023 | - * @return bool|int|string | |
| 1024 | - */ | |
| 1025 | - public function get_course_remaining_time( $course_id ) { | |
| 1026 | - $course = learn_press_get_course( $course_id ); | |
| 1027 | - $remain = false; | |
| 1028 | - | |
| 1029 | - if ( $course && $course->get_id() ) { | |
| 1030 | - $course_data = $this->get_course_data( $course_id, true ); | |
| 1031 | - if ( $course_data ) { | |
| 1032 | - $remain = $course_data->is_exceeded(); | |
| 1033 | - } | |
| 1034 | - } | |
| 1035 | - | |
| 1036 | - return $remain > 0 ? learn_press_seconds_to_weeks( $remain ) : false; | |
| 1037 | - } | |
| 1038 | - | |
| 1039 | - /** | |
| 1040 | 941 | * Get the order that contains the course. |
| 1041 | 942 | * |
| 1042 | 943 | * @param int $course_id |
| 1043 | 944 | * |
| @@ -1079,60 +980,8 @@ | ||
| 1079 | 980 | return $wpdb->get_var( $query ); |
| 1080 | 981 | } |
| 1081 | 982 | |
| 1082 | 983 | /** |
| 1083 | - * @param $question_id | |
| 1084 | - * @param null $quiz_id | |
| 1085 | - * | |
| 1086 | - * @return bool | |
| 1087 | - */ | |
| 1088 | - public function get_answer_results( $question_id, $quiz_id = null ) { | |
| 1089 | - | |
| 1090 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, '3.0.0' ); | |
| 1091 | - | |
| 1092 | - $data = false; | |
| 1093 | - if ( ! $quiz_id ) { | |
| 1094 | - $quiz_id = $this->get_quiz_by_question( $question_id ); | |
| 1095 | - } | |
| 1096 | - if ( $quiz_id ) { | |
| 1097 | - $question = LP_Question::get_question( $question_id ); | |
| 1098 | - | |
| 1099 | - if ( $question ) { | |
| 1100 | - $quiz_results = $this->get_quiz_results( $quiz_id ); | |
| 1101 | - if ( ! empty( $quiz_results->question_answers ) ) { | |
| 1102 | - $question_answer = array_key_exists( | |
| 1103 | - $question_id, | |
| 1104 | - $quiz_results->question_answers | |
| 1105 | - ) ? $quiz_results->question_answers[ $question_id ] : null; | |
| 1106 | - $data = $question->check( $question_answer ); | |
| 1107 | - } | |
| 1108 | - } | |
| 1109 | - } | |
| 1110 | - | |
| 1111 | - return $data; | |
| 1112 | - } | |
| 1113 | - | |
| 1114 | - /** | |
| 1115 | - * @param $question_id | |
| 1116 | - * @param null $quiz_id | |
| 1117 | - * | |
| 1118 | - * @return bool | |
| 1119 | - */ | |
| 1120 | - public function is_answered_question( $question_id, $quiz_id = null ) { | |
| 1121 | - if ( empty( $this->answered_questions ) ) { | |
| 1122 | - $this->answered_questions = array(); | |
| 1123 | - } | |
| 1124 | - if ( ! $quiz_id ) { | |
| 1125 | - $quiz_id = $this->get_quiz_by_question( $question_id ); | |
| 1126 | - } | |
| 1127 | - | |
| 1128 | - $results = $this->get_quiz_results( $quiz_id ); | |
| 1129 | - $answered = ! empty( $results->question_answers ) ? $results->question_answers : array(); | |
| 1130 | - | |
| 1131 | - return $answered ? array_key_exists( $question_id, $answered ) : false; | |
| 1132 | - } | |
| 1133 | - | |
| 1134 | - /** | |
| 1135 | 984 | * @return array |
| 1136 | 985 | */ |
| 1137 | 986 | public function get_roles() { |
| 1138 | 987 | return (array) $this->get_data( 'roles' ); |
| @@ -1155,25 +1004,8 @@ | ||
| 1155 | 1004 | return $quiz_data ? $quiz_data->has_checked_question( $question_id ) : false; |
| 1156 | 1005 | } |
| 1157 | 1006 | |
| 1158 | 1007 | /** |
| 1159 | - * @param $question_id | |
| 1160 | - * @param $quiz_id | |
| 1161 | - * @param int $course_id | |
| 1162 | - * | |
| 1163 | - * @return bool | |
| 1164 | - */ | |
| 1165 | - public function has_hinted_answer( $question_id, $quiz_id, $course_id = 0 ) { | |
| 1166 | - if ( ! $course_id ) { | |
| 1167 | - $course_id = get_the_ID(); | |
| 1168 | - } | |
| 1169 | - | |
| 1170 | - $quiz_data = $this->get_item_data( $quiz_id, $course_id ); | |
| 1171 | - | |
| 1172 | - return $quiz_data ? $quiz_data->has_hinted_question( $question_id ) : false; | |
| 1173 | - } | |
| 1174 | - | |
| 1175 | - /** | |
| 1176 | 1008 | * Return TRUE if user is already exists. |
| 1177 | 1009 | * |
| 1178 | 1010 | * @return bool |
| 1179 | 1011 | */ |
| @@ -1197,13 +1029,33 @@ | ||
| 1197 | 1029 | * @param mixed $size |
| 1198 | 1030 | * |
| 1199 | 1031 | * @return string |
| 1200 | 1032 | */ |
| 1201 | - public function get_upload_profile_src( $size = '' ) { | |
| 1202 | - return LP_Profile::instance( $this->get_id() )->get_upload_profile_src( $size ); | |
| 1033 | + public function get_upload_profile_src() { | |
| 1034 | + return LP_Profile::instance( $this->get_id() )->get_upload_profile_src(); | |
| 1203 | 1035 | } |
| 1204 | 1036 | |
| 1205 | 1037 | /** |
| 1038 | + * Get profile avatar url | |
| 1039 | + * | |
| 1040 | + * @return string | |
| 1041 | + * @since 4.2.7.2 | |
| 1042 | + * @version 1.0.0 | |
| 1043 | + */ | |
| 1044 | + public function get_profile_avatar_url(): string { | |
| 1045 | + $avatar_url = $this->get_upload_profile_src(); | |
| 1046 | + if ( empty( $avatar_url ) ) { | |
| 1047 | + $args = learn_press_get_avatar_thumb_size(); | |
| 1048 | + $avatar_url = get_avatar_url( $this->get_id(), $args ); | |
| 1049 | + if ( empty( $avatar_url ) ) { | |
| 1050 | + $avatar_url = LP_PLUGIN_URL . 'assets/images/avatar-default.png'; | |
| 1051 | + } | |
| 1052 | + } | |
| 1053 | + | |
| 1054 | + return $avatar_url; | |
| 1055 | + } | |
| 1056 | + | |
| 1057 | + /** | |
| 1206 | 1058 | * @param string $type |
| 1207 | 1059 | * @param int $size |
| 1208 | 1060 | * @param bool $src_only |
| 1209 | 1061 | * |
| @@ -1214,11 +1066,13 @@ | ||
| 1214 | 1066 | } |
| 1215 | 1067 | |
| 1216 | 1068 | /** |
| 1217 | 1069 | * Get links socials of use on Profile page |
| 1070 | + * Icon is font awesome | |
| 1218 | 1071 | * |
| 1219 | 1072 | * @param int $user_id |
| 1220 | 1073 | * @return array |
| 1074 | + * @deprecated 4.2.3 | |
| 1221 | 1075 | */ |
| 1222 | 1076 | public function get_profile_socials( int $user_id = 0 ): array { |
| 1223 | 1077 | $socials = array(); |
| 1224 | 1078 | $extra_info = learn_press_get_user_extra_profile_info( $user_id ); |
| @@ -1230,21 +1084,24 @@ | ||
| 1230 | 1084 | } |
| 1231 | 1085 | |
| 1232 | 1086 | switch ( $k ) { |
| 1233 | 1087 | case 'facebook': |
| 1234 | - $i = '<i class="fab fa-facebook-f"></i>'; | |
| 1088 | + $i = '<i class="lp-icon-facebook-f"></i>'; | |
| 1235 | 1089 | break; |
| 1236 | 1090 | case 'twitter': |
| 1237 | - $i = '<i class="fab fa-twitter"></i>'; | |
| 1091 | + $i = '<i class="lp-icon-twitter"></i>'; | |
| 1238 | 1092 | break; |
| 1239 | 1093 | case 'googleplus': |
| 1240 | - $i = '<i class="fab fa-google-plus-g"></i>'; | |
| 1094 | + $i = '<i class="lp-icon-google-plus"></i>'; | |
| 1241 | 1095 | break; |
| 1242 | 1096 | case 'youtube': |
| 1243 | - $i = '<i class="fab fa-youtube"></i>'; | |
| 1097 | + $i = '<i class="lp-icon-youtube-play"></i>'; | |
| 1244 | 1098 | break; |
| 1099 | + case 'linkedin': | |
| 1100 | + $i = '<i class="lp-icon-linkedin"></i>'; | |
| 1101 | + break; | |
| 1245 | 1102 | default: |
| 1246 | - $i = sprintf( '<i class="fab fa-%s"></i>', $k ); | |
| 1103 | + $i = sprintf( '<i class="lp-icon-%s"></i>', $k ); | |
| 1247 | 1104 | } |
| 1248 | 1105 | |
| 1249 | 1106 | $icon = apply_filters( |
| 1250 | 1107 | 'learn-press/user-profile-social-icon', |
| @@ -1260,8 +1117,58 @@ | ||
| 1260 | 1117 | return apply_filters( 'learn-press/user-profile-socials', $socials, $this->get_id(), $this ); |
| 1261 | 1118 | } |
| 1262 | 1119 | |
| 1263 | 1120 | /** |
| 1121 | + * Get links socials of use on Profile page | |
| 1122 | + * Icon is svg | |
| 1123 | + * | |
| 1124 | + * @param int $user_id | |
| 1125 | + * @return array | |
| 1126 | + * @since 4.2.3 | |
| 1127 | + * @version 1.0.0 | |
| 1128 | + */ | |
| 1129 | + public function get_profile_social( int $user_id = 0 ): array { | |
| 1130 | + $socials = array(); | |
| 1131 | + $extra_info = learn_press_get_user_extra_profile_info( $user_id ); | |
| 1132 | + | |
| 1133 | + if ( $extra_info ) { | |
| 1134 | + foreach ( $extra_info as $k => $v ) { | |
| 1135 | + if ( empty( $v ) ) { | |
| 1136 | + continue; | |
| 1137 | + } | |
| 1138 | + | |
| 1139 | + switch ( $k ) { | |
| 1140 | + case 'facebook': | |
| 1141 | + $i = '<i class="lp-user-ico lp-icon-facebook"></i>'; | |
| 1142 | + break; | |
| 1143 | + case 'twitter': | |
| 1144 | + $i = '<i class="lp-user-ico lp-icon-twitter"></i>'; | |
| 1145 | + break; | |
| 1146 | + case 'linkedin': | |
| 1147 | + $i = '<i class="lp-user-ico lp-icon-linkedin"></i>'; | |
| 1148 | + break; | |
| 1149 | + case 'youtube': | |
| 1150 | + $i = '<i class="lp-user-ico lp-icon-youtube-play"></i>'; | |
| 1151 | + break; | |
| 1152 | + default: | |
| 1153 | + $i = sprintf( '<i class="lp-user-ico lp-icon-%s"></i>', esc_attr( $k ) ); | |
| 1154 | + } | |
| 1155 | + | |
| 1156 | + $icon = apply_filters( | |
| 1157 | + 'learn-press/user-profile-social-icon', | |
| 1158 | + $i, | |
| 1159 | + $k, | |
| 1160 | + $this->get_id(), | |
| 1161 | + $this | |
| 1162 | + ); | |
| 1163 | + $socials[ $k ] = sprintf( '<a href="%s">%s</a>', esc_url_raw( $v ), $icon ); | |
| 1164 | + } | |
| 1165 | + } | |
| 1166 | + | |
| 1167 | + return apply_filters( 'learn-press/user-profile-socials', $socials, $this->get_id(), $this ); | |
| 1168 | + } | |
| 1169 | + | |
| 1170 | + /** | |
| 1264 | 1171 | * Check course of user has graduation is in-progress |
| 1265 | 1172 | * |
| 1266 | 1173 | * @param $course_id |
| 1267 | 1174 | * @return bool |
| @@ -1270,9 +1177,9 @@ | ||
| 1270 | 1177 | public function is_course_in_progress( $course_id ): bool { |
| 1271 | 1178 | $user = learn_press_get_user( $this->get_id() ); |
| 1272 | 1179 | $user_course = $user->get_course_data( $course_id ); |
| 1273 | 1180 | |
| 1274 | - return $user_course && LP_COURSE_GRADUATION_IN_PROGRESS === $user_course->get_graduation(); | |
| 1181 | + return $user_course && LP_COURSE_GRADUATION_IN_PROGRESS === $user_course->get_graduation(); | |
| 1275 | 1182 | } |
| 1276 | 1183 | |
| 1277 | 1184 | /** |
| 1278 | 1185 | * Return TRUE if user can do a quiz |
| @@ -1314,10 +1221,17 @@ | ||
| 1314 | 1221 | |
| 1315 | 1222 | return $course_results['completed_items'] >= $course->count_items(); |
| 1316 | 1223 | } |
| 1317 | 1224 | |
| 1225 | + /** | |
| 1226 | + * Get role of user. | |
| 1227 | + * | |
| 1228 | + * @return string | |
| 1229 | + * @since 3.0.0 | |
| 1230 | + * @version 1.0.1 | |
| 1231 | + */ | |
| 1318 | 1232 | public function get_role() { |
| 1319 | - return $this->is_admin() ? 'admin' : ( $this->is_instructor() ? 'instructor' : 'user' ); | |
| 1233 | + return $this->get_data( 'role' ); | |
| 1320 | 1234 | } |
| 1321 | 1235 | |
| 1322 | 1236 | /** |
| 1323 | 1237 | * Get user course's grade. |
| @@ -1346,9 +1260,9 @@ | ||
| 1346 | 1260 | * |
| 1347 | 1261 | * @return bool |
| 1348 | 1262 | */ |
| 1349 | 1263 | public function is_guest(): bool { |
| 1350 | - return ! $this->get_id() || ! get_user_by( 'id', $this->get_id() ); | |
| 1264 | + return $this instanceof LP_User_Guest; | |
| 1351 | 1265 | } |
| 1352 | 1266 | |
| 1353 | 1267 | /** |
| 1354 | 1268 | * Check if user can edit a post. |
| @@ -1388,9 +1302,9 @@ | ||
| 1388 | 1302 | * |
| 1389 | 1303 | * @return string |
| 1390 | 1304 | */ |
| 1391 | 1305 | public function get_description(): string { |
| 1392 | - return $this->get_data( 'description', '' ); | |
| 1306 | + return get_the_author_meta( 'description', $this->get_id() ); | |
| 1393 | 1307 | } |
| 1394 | 1308 | |
| 1395 | 1309 | /** |
| 1396 | 1310 | * Return user first name. |