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/course/class-lp-course-item.php +40 -227 4.1.6.9 → 4.4.9 View file →
@@ -6,8 +6,13 @@
6 6 * @package LearnPress/Classes
7 7 * @version 3.0.0
8 8 */
9 9
10 +use LearnPress\Models\CourseModel;
11 +use LearnPress\Models\UserItems\UserCourseModel;
12 +use LearnPress\Models\UserItems\UserItemModel;
13 +use LearnPress\Models\UserModel;
14 +
10 15 defined( 'ABSPATH' ) || exit();
11 16
12 17 if ( ! class_exists( 'LP_Course_Item' ) ) {
13 18 /**
@@ -12,9 +17,9 @@
12 17 if ( ! class_exists( 'LP_Course_Item' ) ) {
13 18 /**
14 19 * Class LP_Course_Item.
15 20 */
16 - class LP_Course_Item extends LP_Abstract_Post_Data implements ArrayAccess {
21 + class LP_Course_Item extends LP_Abstract_Post_Data {
17 22
18 23 /**
19 24 * The icon maybe used somewhere.
20 25 *
@@ -149,49 +154,19 @@
149 154
150 155 /**
151 156 * Get class of item.
152 157 *
153 - * @param string $more
154 - * @param int $user_id
158 + * @param $course_id
159 + * @param $item_id
160 + * @param $can_view_item
161 + * @param $more
155 162 *
156 - * @return array
163 + * @return array|mixed|null
164 + * @since 4.1.4.2
165 + * @version 1.0.1
157 166 */
158 - public function get_class( $more = '', $user_id = 0 ) {
159 - $course_id = get_the_ID();
160 -
161 - if ( empty( $GLOBALS['get_class'] ) ) {
162 - $GLOBALS['get_class'] = 0;
163 - }
164 -
165 - $user_id = $user_id ? $user_id : get_current_user_id();
166 - $t = microtime( true );
167 - $classes = LP_Object_Cache::get( 'item-' . $user_id . '-' . $this->get_id(), 'learn-press/post-classes' );
168 -
169 - if ( false === $classes ) {
170 - $curd = new LP_User_Item_CURD();
171 - $all_items = $curd->parse_items_classes( $course_id, $user_id, $more );
172 -
173 - $classes = ! empty( $all_items[ $this->get_id() ] ) ? $all_items[ $this->get_id() ] : $defaults = array(
174 - 'course-item',
175 - 'course-item-' . $this->get_item_type(),
176 - 'course-item-' . $this->get_id(),
177 - );
178 - }
179 -
180 - $GLOBALS['get_class'] += microtime( true ) - $t;
181 -
182 - return apply_filters(
183 - 'learn-press/course-item-class-cached',
184 - $classes,
185 - $this->get_item_type(),
186 - $this->get_id(),
187 - $course_id
188 - );
189 - }
190 -
191 167 public function get_class_v2( $course_id, $item_id, $can_view_item, $more = array() ) {
192 - $course = learn_press_get_course( $course_id );
193 -
168 + $course = CourseModel::find( $course_id, true );
194 169 if ( ! $course ) {
195 170 return $more;
196 171 }
197 172
@@ -203,18 +178,15 @@
203 178 ),
204 179 (array) $more
205 180 );
206 181
207 - $user = learn_press_get_user( get_current_user_id() );
182 + $user_id = get_current_user_id();
183 + $user = UserModel::find( $user_id, true );
208 184
209 - if ( ! $user ) {
210 - return $defaults;
211 - }
185 + $userCourseModel = UserCourseModel::find( $user_id, $course_id, true );
186 + $enrolled = $user && $userCourseModel && $userCourseModel->has_enrolled_or_finished();
187 + $no_required_enroll = $course->has_no_enroll_requirement();
212 188
213 - $is_free = $course->is_free();
214 - $enrolled = $user->has_enrolled_or_finished( $course_id );
215 - $no_required_enroll = $course->is_no_required_enroll();
216 -
217 189 $post_format = $this->get_format();
218 190 if ( 'standard' !== $post_format && $post_format ) {
219 191 $defaults[] = 'course-item-type-' . $post_format;
220 192 }
@@ -220,9 +192,11 @@
220 192 }
221 193
222 194 if ( $no_required_enroll ) {
223 195 $defaults[] = 'item-free';
224 - } elseif ( ! $enrolled ) {
196 + }
197 +
198 + if ( ! $enrolled ) {
225 199 $defaults['item-locked'] = 'item-locked';
226 200
227 201 if ( $this->is_preview() ) {
228 202 $defaults['item-preview'] = 'item-preview';
@@ -231,10 +205,18 @@
231 205 }
232 206 } elseif ( ! $can_view_item->flag ) {
233 207 $defaults[] = 'item-locked';
234 208 } else {
235 - $item_status = $user->get_item_status( $item_id, $course_id );
236 - $item_grade = $user->get_item_grade( $item_id, $course_id );
209 + $userItemModel = UserItemModel::find_user_item(
210 + $user_id,
211 + $item_id,
212 + get_post_type( $item_id ),
213 + $course_id,
214 + LP_COURSE_CPT,
215 + true
216 + );
217 + $item_status = $userItemModel ? $userItemModel->get_status() : '';
218 + $item_grade = $userItemModel ? $userItemModel->get_graduation() : '';
237 219
238 220 if ( $item_status ) {
239 221 $defaults[] = 'has-status';
240 222 $defaults[] = 'status-' . $item_status;
@@ -441,9 +423,9 @@
441 423 // $lp_course_cache->set_cache( $key_cache, $item );
442 424 }
443 425 }
444 426
445 - return apply_filters( 'learn-press/get-course-item', $item, $item_type, $item_id );
427 + return $item;
446 428 }
447 429
448 430 /**
449 431 * Get template name of item.
@@ -541,10 +523,11 @@
541 523 /**
542 524 * @param int $question_id
543 525 *
544 526 * @return mixed
527 + * @deprecated 4.1.7.2
545 528 */
546 - public function is_viewing_question( $question_id = 0 ) {
529 + /*public function is_viewing_question( $question_id = 0 ) {
547 530 global $lp_quiz_question;
548 531 if ( $question_id ) {
549 532 $viewing = $lp_quiz_question && $lp_quiz_question->get_id() == $question_id;
550 533 } else {
@@ -551,9 +534,9 @@
551 534 $viewing = $lp_quiz_question ? $lp_quiz_question->get_id() : false;
552 535 }
553 536
554 537 return apply_filters( 'learn-press/quiz/is-viewing-question', $viewing, $question_id, $this->get_id() );
555 - }
538 + }*/
556 539
557 540 /**
558 541 * @param int $user_id
559 542 * @param int $course_id
@@ -558,10 +541,11 @@
558 541 * @param int $user_id
559 542 * @param int $course_id
560 543 *
561 544 * @return mixed
545 + * @deprecated 4.1.7.2
562 546 */
563 - public function get_status_classes( $user_id = 0, $course_id = 0 ) {
547 + /*public function get_status_classes( $user_id = 0, $course_id = 0 ) {
564 548 $status_classes = array();
565 549 $course = learn_press_get_course( $course_id );
566 550 $user = learn_press_get_user( $user_id, ! $user_id );
567 551
@@ -567,9 +551,9 @@
567 551
568 552 if ( $course ) {
569 553 if ( $this->is_preview() ) {
570 554 $status_classes[] = 'item-preview';
571 - } elseif ( $course->is_free() && ! $course->is_required_enroll() ) {
555 + } elseif ( $course->is_free() && $course->is_no_required_enroll() ) {
572 556 $status_classes[] = 'item-free';
573 557 }
574 558 }
575 559
@@ -595,9 +579,9 @@
595 579 $this->get_id(),
596 580 $course_id,
597 581 $user_id
598 582 );
599 - }
583 + }*/
600 584
601 585 /**
602 586 * Get duration of quiz
603 587 *
@@ -619,179 +603,8 @@
619 603 }
620 604
621 605 return apply_filters( 'learn-press/course-item-duration', $duration, $this->get_id() );
622 606 }
623 -
624 - /**
625 - * @param int $course_id
626 - * @param int $user_id
627 - *
628 - * @return bool
629 - * @editor tungnx
630 - * @modify 4.1.3 - not use - comment
631 - * @deprecated
632 - */
633 - public function is_blocked( $course_id = 0, $user_id = 0 ) {
634 - _deprecated_function( __FUNCTION__, '4.1.3' );
635 -
636 - /*
637 - if ( ! $user_id ) {
638 - $user_id = get_current_user_id();
639 - }
640 -
641 - if ( ! $course_id ) {
642 - $course_id = get_the_ID();
643 - }
644 -
645 - $course_author = learn_press_get_course_user( $course_id );
646 -
647 - if ( $course_author ) {
648 - $author_id = $course_author->get_id();
649 -
650 - if ( $author_id == $user_id ) {
651 - // return false;
652 - }
653 - }
654 -
655 - $key = 'course-item-' . $user_id . '-' . $course_id;
656 - $blocked_items = LP_Object_Cache::get( $key, 'learn-press/blocked-items' );
657 -
658 - if ( false === $blocked_items ) {
659 - $blocked_items = $this->_parse_item_block_status( $course_id, $user_id, $key );
660 - }
661 -
662 - $is_blocked = isset( $blocked_items[ $this->get_id() ] ) ? $blocked_items[ $this->get_id() ] : false;
663 -
664 - if ( false === $is_blocked ) {
665 - if ( $course_id ) {
666 - $course = learn_press_get_course( $course_id );
667 - } else {
668 - $course = $this->get_course();
669 - $course_id = $course ? $course->get_id() : 0;
670 - }
671 -
672 - if ( ! $user_id ) {
673 - $user_id = get_current_user_id();
674 - }
675 -
676 - $user = learn_press_get_user( $user_id );
677 -
678 - if ( ! $course ) {
679 - $blocked = 'yes';
680 - } elseif ( ! $course->is_required_enroll() || $this->is_preview() ) {
681 - $blocked = 'no';
682 - } else {
683 - if ( $user ) {
684 - $blocked = $this->_item_is_blocked( $user, $course, $user->get_course_data( $course_id ) );
685 - } else {
686 - $blocked = 'yes';
687 - }
688 - }
689 -
690 - if ( ! is_array( $blocked_items ) ) {
691 - $blocked_items = array();
692 - }
693 - $blocked_items[ $this->get_id() ] = $blocked;
694 -
695 - LP_Object_Cache::set( $key, $blocked_items, 'learn-press/blocked-items' );
696 - $is_blocked = $blocked;
697 - }
698 -
699 - return apply_filters(
700 - 'learn-press/course-item/is-blocked',
701 - $is_blocked === 'yes' ? true : false,
702 - $this->get_id(),
703 - $course_id,
704 - $user_id
705 - );*/
706 - }
707 -
708 - /**
709 - * @editor tungnx
710 - * @modify 4.1.3
711 - */
712 - /*
713 - protected function _parse_item_block_status( $course_id, $user_id, $cache_key ) {
714 - $course = learn_press_get_course( $course_id );
715 -
716 - if ( ! $course ) {
717 - return false;
718 - }
719 -
720 - $user = learn_press_get_user( $user_id );
721 - $course_items = $course->get_item_ids();
722 - $course_item_data = $user->get_course_data( $course_id );
723 -
724 - if ( ! $course->is_required_enroll() ) {
725 - $blocked_items = array_fill_keys( $course_items, 'no' );
726 - } elseif ( ! $user || $user->is_guest() ) {
727 - $blocked_items = array_fill_keys( $course_items, 'yes' );
728 - } else {
729 - $blocked = $this->_item_is_blocked( $user, $course, $course_item_data );
730 - $blocked_items = array_fill_keys( $course_items, $blocked );
731 - }
732 - $block_item_types = learn_press_get_block_course_item_types();
733 -
734 - foreach ( $course_items as $course_item ) {
735 - $item = $course->get_item( $course_item );
736 -
737 - if ( $item ) {
738 - if ( $item->is_preview() ) {
739 - $blocked_items[ $course_item ] = 'no';
740 - } elseif ( ! $block_item_types || is_array( $block_item_types ) && ! in_array(
741 - $item->get_post_type(),
742 - $block_item_types
743 - ) ) {
744 - $blocked_items[ $course_item ] = 'no';
745 - }
746 - }
747 -
748 - $item_data = $course_item_data->get_item( $course_item );
749 - if ( $item_data ) {
750 - $access_level = $item_data->get_access_level();
751 - if ( $access_level > 0 && $access_level < 50 ) {
752 - $blocked_items[ $course_item ] = 'yes';
753 - }
754 - }
755 - }
756 -
757 - $blocked_items = apply_filters(
758 - 'learn-press/course-item/parse-block-statuses',
759 - $blocked_items,
760 - $course_id,
761 - $user_id
762 - );
763 -
764 - LP_Object_Cache::set( $cache_key, $blocked_items, 'learn-press/blocked-items' );
765 -
766 - return $blocked_items;
767 - }*/
768 -
769 - /**
770 - * @param LP_User $user
771 - * @param LP_Course $course
772 - * @param LP_User_Item_Course $course_item_data
773 - *
774 - * @return string
775 - * @editor tungnx
776 - * @modify 4.1.3
777 - */
778 - /*
779 - protected function _item_is_blocked( $user, $course, $course_item_data ) {
780 - if ( in_array( 'administrator', $user->get_roles() ) ) {
781 - $blocked = 'no';
782 - } elseif ( $user->has_course_status( $course->get_id(), learn_press_course_enrolled_slugs() ) ) {
783 - $blocked = 'no';
784 -
785 - if ( $course->is_block_item_content() && $course_item_data->get_finishing_type() !== 'click' ) {
786 - $blocked = 'yes';
787 - }
788 - } else {
789 - $blocked = 'yes';
790 - }
791 -
792 - return $blocked;
793 - }*/
794 607
795 608 public function offsetExists( $offset ) {
796 609 }
797 610