PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.6.9.2
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.6.9.2
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 4.2.0 All 139 releases
learnpress / inc / external-plugin / elementor / widgets / list-courses.php

list-courses.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.1.6.9.2, at inc/external-plugin/elementor/widgets/list-courses.php

211 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 class LP_Elementor_Widget_List_Courses extends LP_Elementor_Widget_Base {
5
6 public function get_name() {
7 return 'learnpress_list_courses';
8 }
9
10 public function get_title() {
11 return esc_html__( 'List Courses', 'learnpress' );
12 }
13
14 public function get_keywords() {
15 return array( 'learnpress', 'list courses' );
16 }
17
18 public function get_icon() {
19 return 'eicon-post-list';
20 }
21
22 protected function register_controls() {
23
24 $this->_register_control_content();
25
26 }
27
28 protected function _register_control_content() {
29 $this->start_controls_section(
30 'section_content',
31 array(
32 'label' => esc_html__( 'Content', 'learnpress' ),
33 )
34 );
35 $this->add_control(
36 'grid_list_type',
37 array(
38 'label' => esc_html__( 'Layout Type', 'learnpress' ),
39 'type' => Controls_Manager::SELECT,
40 'options' => array(
41 'list' => esc_html__( 'List', 'learnpress' ),
42 'grid' => esc_html__( 'Grid', 'learnpress' ),
43 ),
44 'default' => 'grid',
45 )
46 );
47 $this->add_control(
48 'post_id',
49 array(
50 'label' => esc_html__( 'Select Course', 'learnpress' ),
51 'type' => Controls_Manager::SELECT,
52 'options' => $this->get_all_courses( array( '0' => esc_html__( 'All', 'learnpress' ) ) ),
53 'default' => '0',
54 )
55 );
56 $this->add_control(
57 'cat_id',
58 array(
59 'label' => esc_html__( 'Select Category', 'learnpress' ),
60 'type' => Controls_Manager::SELECT,
61 'options' => $this->get_cat_taxonomy( array( '0' => esc_html__( 'All', 'learnpress' ) ) ),
62 'default' => '0',
63 )
64 );
65 $this->add_control(
66 'course_type',
67 array(
68 'label' => esc_html__( 'Course Type', 'learnpress' ),
69 'type' => Controls_Manager::SELECT,
70 'options' => array(
71 '' => esc_html__( 'Default', 'learnpress' ),
72 'recent' => esc_html__( 'Recent', 'learnpress' ),
73 'popular' => esc_html__( 'Popular', 'learnpress' ),
74 'featured' => esc_html__( 'Featured', 'learnpress' ),
75 ),
76 'default' => '',
77 )
78 );
79 $this->add_control(
80 'order_by',
81 array(
82 'label' => esc_html__( 'Order By', 'learnpress' ),
83 'type' => Controls_Manager::SELECT,
84 'options' => array(
85 'desc' => esc_html__( 'DESC', 'learnpress' ),
86 'asc' => esc_html__( 'ASC', 'learnpress' ),
87 ),
88 'default' => 'desc',
89 'condition' => array(
90 'course_type!' => 'popular',
91 ),
92 )
93 );
94 $this->add_control(
95 'number_posts',
96 array(
97 'label' => esc_html__( 'Number Post', 'learnpress' ),
98 'default' => '4',
99 'type' => Controls_Manager::NUMBER,
100 )
101 );
102
103 $this->end_controls_section();
104 }
105
106 protected function get_cat_taxonomy( $cats = array() ) {
107
108 $terms = new \WP_Term_Query(
109 array(
110 'taxonomy' => 'course_category',
111 'pad_counts' => 1,
112 'hierarchical' => 1,
113 'hide_empty' => 1,
114 'orderby' => 'name',
115 'menu_order' => true,
116 )
117 );
118
119 if ( is_wp_error( $terms ) ) {
120 return $cats;
121 } else {
122 if ( empty( $terms->terms ) ) {
123 } else {
124 foreach ( $terms->terms as $term ) {
125 $prefix = '';
126 if ( $term->parent > 0 ) {
127 $prefix = '--';
128 }
129 $cats[ $term->term_id ] = $prefix . $term->name;
130 }
131 }
132 }
133
134 return $cats;
135 }
136
137 protected function get_all_courses( $data = array() ) {
138 $args = array(
139 'post_type' => LP_COURSE_CPT,
140 'posts_per_page' => -1,
141 );
142 $courses = get_posts( $args );
143 if ( is_wp_error( $courses ) ) {
144 return $data;
145 }
146 foreach ( $courses as $course ) {
147 $data[ $course->ID ] = $course->post_title;
148 }
149
150 return $data;
151 }
152
153 public function render() {
154 $settings = $this->get_settings_for_display();
155 $filter = new \LP_Course_Filter();
156 $filter->limit = $settings['number_posts'];
157 $course_type = $settings['course_type'];
158 $courses = array();
159
160 if ( $settings['cat_id'] ) {
161 $filter->term_ids = array( $settings['cat_id'] );
162 }
163
164 if ( $settings['order_by'] ) {
165 $filter->order .= $settings['order_by'];
166 }
167
168 if ( $settings['post_id'] ) {
169 $filter->post_ids = array( $settings['post_id'] );
170 }
171
172 switch ( $course_type ) {
173 case 'recent':
174 $filter->order_by .= 'p.post_date';
175 $courses = \LP_Course::get_courses( $filter );
176 break;
177 case 'popular':
178 $filter->order_by = 'popular';
179 $courses = \LP_Course::get_courses( $filter );
180 break;
181 case 'featured':
182 $filter->sort_by = 'on_feature';
183 $courses = \LP_Course::get_courses( $filter );
184 break;
185 default:
186 $courses = \LP_Course::get_courses( $filter );
187 }
188
189 if ( empty( $courses ) ) {
190 LP()->template( 'course' )->no_courses_found();
191 }
192 ?>
193 <div class="lp-archive-courses">
194 <ul class="learn-press-courses" data-layout="<?php echo esc_attr( $settings['grid_list_type'] ); ?>"
195 data-size="<?php echo absint( $settings['number_posts'] ); ?>">
196 <?php
197 global $post;
198 foreach ( $courses as $course ) {
199 $post = $course;
200 setup_postdata( $course );
201 learn_press_get_template( 'content-course.php' );
202 }
203 wp_reset_postdata();
204 ?>
205 </ul>
206 </div>
207 <?php
208 }
209
210 }
211