PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.3.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.3.9
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 4.2.1 All 138 releases
learnpress / inc / TemplateHooks / Course / FilterCourseTemplate.php

FilterCourseTemplate.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.3.9, at inc/TemplateHooks/Course/FilterCourseTemplate.php

873 lines 23.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Template hooks Archive Package.
4 *
5 * @since 4.2.3.2
6 * @version 1.0.4
7 */
8
9 namespace LearnPress\TemplateHooks\Course;
10
11 defined( 'ABSPATH' ) || exit;
12
13 use Exception;
14 use LearnPress\Helpers\Singleton;
15 use LearnPress\Helpers\Template;
16 use LearnPress\Models\Courses;
17 use LearnPress\Models\ListCourseCategories;
18 use LearnPress\Models\UserModel;
19 use LP_Course_Filter;
20 use LP_Debug;
21 use LP_Request;
22 use Throwable;
23
24 class FilterCourseTemplate {
25 use Singleton;
26
27 public function init() {
28 add_action( 'learn-press/filter-courses/layout', [ $this, 'sections' ] );
29 //add_action( 'wp_head', [ $this, 'add_internal_scripts_to_head' ] );
30 }
31
32 /**
33 * Sections of template filter courses.
34 *
35 * @param array $data
36 *
37 * @return void
38 * @uses self::html_category
39 *
40 * @since 4.2.3.2
41 * @version 1.0.1
42 */
43 public function sections( array $data = [] ) {
44 wp_enqueue_script( 'lp-course-filter' );
45
46 try {
47 if ( ! isset( $data['fields'] ) ) {
48 $data['fields'] = [
49 'search',
50 'price',
51 'category',
52 'tag',
53 'author',
54 'level',
55 'type',
56 'btn_submit',
57 'btn_reset',
58 ];
59
60 $data = apply_filters( 'learn-press/filter-courses/data', $data );
61 } elseif ( is_string( $data['fields'] ) ) {
62 $data['fields'] = explode( ',', $data['fields'] );
63 }
64
65 if ( ! is_array( $data['fields'] ) ) {
66 throw new Exception( 'Fields must be array' );
67 }
68
69 if ( isset( $data['fields']['btn_submit'] ) ) {
70 $data['fields'][] = 'btn_submit';
71 }
72
73 $sections = [];
74 foreach ( $data['fields'] as $field ) {
75 if ( is_callable( [ $this, 'html_' . $field ] ) ) {
76 $sections[ $field ] = $this->{'html_' . $field}( $data );
77 } else { // For custom field.
78 do_action_ref_array(
79 'learn-press/filter-courses/sections/field/html',
80 [
81 &$sections,
82 $field,
83 $data,
84 ]
85 );
86 }
87 }
88 // Add button Done for mobile if not has btn submit.
89 if ( ! in_array( 'btn_submit', $data['fields'] ) ) {
90 $sections['btn_done'] = $this->html_btn_done( $data );
91 }
92
93 $class_wrapper_form = $data['class_wrapper_form'] ?? 'lp-form-course-filter';
94
95 $wrapper = apply_filters(
96 'lp/filter-courses/sections/wrapper',
97 [
98 'wrapper' => sprintf( '<form class="%s">', $class_wrapper_form ),
99 'sections' => Template::combine_components( $sections ),
100 'close' => sprintf(
101 '<div class="lp-form-course-filter__close">%s<i class="lp-icon-close"></i></div>',
102 esc_html__( 'Close', 'learnpress' )
103 ),
104 'wrapper_end' => '</form>',
105 ],
106 $data
107 );
108
109 echo Template::combine_components( $wrapper );
110 } catch ( Throwable $e ) {
111 error_log( __METHOD__ . ': ' . $e->getMessage() );
112 }
113 }
114
115 /**
116 * Get html item.
117 *
118 * @param string $title
119 * @param string $content
120 *
121 * @return string
122 */
123 public function html_item( string $title = '', string $content = '' ): string {
124 try {
125 $title_html = sprintf(
126 '<div class="lp-form-course-filter__title">%s</div>',
127 $title
128 );
129 $content_html = sprintf(
130 '<div class="lp-form-course-filter__content">%s</div>',
131 $content
132 );
133 $sections = apply_filters(
134 'lp/filter-courses/item/sections',
135 [
136 'title' => $title_html,
137 'content' => $content_html,
138 ],
139 $title,
140 $content
141 );
142
143 $wrapper = apply_filters(
144 'lp/filter-courses/item/wrapper',
145 [
146 'wrapper' => '<div class="lp-form-course-filter__item">',
147 'content' => Template::combine_components( $sections ),
148 'wrapper_end' => '</div>',
149 ]
150 );
151
152 $content = Template::combine_components( $wrapper );
153 } catch ( Throwable $e ) {
154 error_log( __METHOD__ . ': ' . $e->getMessage() );
155 }
156
157 return $content;
158 }
159
160 /**
161 * Get html search.
162 *
163 * @param array $data
164 *
165 * @return string
166 */
167 public function html_search( array $data = [] ): string {
168 $content = '';
169
170 try {
171 $this->check_param_url_has_lang( $data );
172 $value = LP_Request::get_param( 'c_search' );
173 $value = isset( $data['params_url'] ) ? ( $data['params_url']['c_search'] ?? $value ) : $value;
174 $content = sprintf(
175 '<input type="text" name="c_search" placeholder="%s" value="%s" class="%s" data-search-suggest="%d">',
176 esc_html__( 'Search Course', 'learnpress' ),
177 esc_attr( $value ),
178 esc_attr( 'lp-course-filter-search' ),
179 esc_attr( $data['search_suggestion'] ?? 1 )
180 );
181 $content .= '<span class="lp-loading-circle lp-loading-no-css hide"></span>';
182
183 $sections = [
184 'wrapper' => '<div class="lp-course-filter-search-field">',
185 'content' => $content,
186 'wrapper_end' => '</div>',
187 'result' => '<div class="lp-course-filter-search-result"></div>',
188 ];
189
190 $content = Template::combine_components( $sections );
191
192 $content = $this->html_item( esc_html__( 'Search', 'learnpress' ), $content );
193
194 $wrapper = apply_filters(
195 'lp/filter-courses/sections/search/wrapper',
196 [
197 'wrapper' => '<div class="lp-course-filter-search">',
198 'content' => $content,
199 'wrapper_end' => '</div>',
200 ],
201 $data
202 );
203
204 $content = Template::combine_components( $wrapper );
205 } catch ( Throwable $e ) {
206 error_log( __METHOD__ . ': ' . $e->getMessage() );
207 }
208
209 return $content;
210 }
211
212 /**
213 * Get html price.
214 *
215 * @param array $data
216 *
217 * @return string
218 * @since 4.2.3.2
219 * @version 1.0.3
220 */
221 public function html_price( array $data = [] ): string {
222 $content = '';
223
224 try {
225 $this->check_param_url_has_lang( $data );
226 $params_url = $data['params_url'] ?? [];
227 $data_selected = $params_url['sort_by'] ?? '';
228 $data_selected = explode( ',', $data_selected );
229 $hide_count_zero = $data['hide_count_zero'] ?? 1;
230
231 // Get number courses free
232 $filter_courses_free = new LP_Course_Filter();
233 $this->handle_filter_params_before_query( $filter_courses_free, $params_url );
234 // Not count include sort by price.
235 $filter_courses_free->sort_by = [];
236 $count_courses_free = Courses::count_course_free( $filter_courses_free );
237
238 // Get number courses has price
239 $filter_courses_price = new LP_Course_Filter();
240 $this->handle_filter_params_before_query( $filter_courses_price, $params_url );
241 $filter_courses_price->query_count = true;
242 $filter_courses_price->sort_by = [ 'on_paid' ];
243 $count_courses_paid = 0;
244 Courses::get_courses( $filter_courses_price, $count_courses_paid );
245
246 $fields = apply_filters(
247 'learn-press/filter-courses/price/fields',
248 [
249 'free' => [
250 'label' => __( 'Free', 'learnpress' ),
251 'count' => $count_courses_free,
252 ],
253 'paid' => [
254 'label' => __( 'Paid', 'learnpress' ),
255 'count' => $count_courses_paid,
256 ],
257 ]
258 );
259
260 foreach ( $fields as $key => $field ) {
261 $value = "on_{$key}";
262 $disabled = $field['count'] > 0 ? '' : 'disabled';
263 if ( ! empty( $disabled ) && $hide_count_zero ) {
264 continue;
265 }
266 $checked = in_array( $value, $data_selected ) && empty( $disabled ) ? 'checked' : '';
267 $input = sprintf(
268 '<input name="sort_by" type="checkbox" value="%1$s" %2$s %3$s>',
269 esc_attr( $value ),
270 esc_attr( $checked ),
271 esc_attr( $disabled )
272 );
273 $label = sprintf( '<label for="">%s</label>', wp_kses_post( $field['label'] ) );
274 $count = sprintf( '<span class="count">%s</span>', esc_html( $field['count'] ) );
275
276 $sections = apply_filters(
277 'lp/filter-courses/price/sections',
278 [
279 'input' => $input,
280 'label' => $label,
281 'count' => $count,
282 ],
283 $field,
284 $data
285 );
286
287 $wrapper = [
288 'wrapper' => '<div class="lp-course-filter__field">',
289 'content' => Template::combine_components( $sections ),
290 'wrapper_end' => '</div>',
291 ];
292
293 $content .= Template::combine_components( $wrapper );
294 }
295
296 $content = $this->html_item( esc_html__( 'Price', 'learnpress' ), $content );
297 } catch ( Throwable $e ) {
298 error_log( __METHOD__ . ': ' . $e->getMessage() );
299 }
300
301 return $content;
302 }
303
304 /**
305 * Get html course list categories.
306 *
307 * @param array $data
308 *
309 * @return string
310 * @since 4.2.3.2
311 * @version 1.0.4
312 */
313 public function html_category( array $data = [] ): string {
314 $content = '';
315
316 try {
317 $this->check_param_url_has_lang( $data );
318 $params_url = $data['params_url'] ?? [];
319 $data_selected = $params_url['term_id'] ?? '';
320 $data_selected = explode( ',', $data_selected );
321 $data['data_selected'] = $data_selected;
322 $parent_cat_id = 0;
323 if ( isset( $params_url['page_term_id_current'] ) ) {
324 $category_current_id = $params_url['page_term_id_current'];
325 $category_current = get_term_by( 'id', $category_current_id, LP_COURSE_CATEGORY_TAX );
326
327 if ( ! empty( $category_current ) ) {
328 $parent_cat_id = $category_current_id;
329 $content .= $this->html_field_category( $category_current->term_id, $category_current->name, $data );
330 }
331 }
332
333 // For subcategories.
334 ob_start();
335 $data['level_current'] = 0;
336 $data['parent_term_id'] = $parent_cat_id;
337 $this->html_struct_categories( $data );
338 $content .= ob_get_clean();
339
340 $content = $this->html_item( esc_html__( 'Categories', 'learnpress' ), $content );
341
342 $wrapper = apply_filters(
343 'lp/filter-courses/sections/category/wrapper',
344 [
345 'wrapper' => '<div class="lp-course-filter-category">',
346 'content' => $content,
347 'wrapper_end' => '</div>',
348 ],
349 $data
350 );
351
352 $content = Template::combine_components( $wrapper );
353 } catch ( Throwable $e ) {
354 error_log( __METHOD__ . ': ' . $e->getMessage() );
355 }
356
357 return $content;
358 }
359
360 /**
361 * Get list categories course.
362 *
363 * @param array $args
364 *
365 * @return void
366 * @since 4.2.6.5
367 * @version 1.0.0
368 */
369 public function html_struct_categories( array $args = [] ) {
370 $level_current = $args['level_current'] ?? 0;
371 $number_level_category = $args['number_level_category'] ?? 2;
372 $parent_term_id = $args['parent_term_id'] ?? 0;
373
374 if ( $level_current >= $number_level_category ) {
375 return;
376 }
377
378 $terms = ListCourseCategories::get_all_categories_id_name( [ 'parent' => $parent_term_id ] );
379 if ( empty( $terms ) ) {
380 return;
381 }
382
383 $class_wrapper = 'lp-cate-parent';
384 if ( $level_current > 0 ) {
385 $class_wrapper = 'lp-cate-child';
386 }
387
388 echo sprintf( '<div class="%s">', esc_attr( $class_wrapper ) );
389 foreach ( $terms as $term_id => $term_name ) {
390 echo sprintf( '<div class="lp-cat-%s">', esc_attr( $term_id ) );
391 echo $this->html_field_category( $term_id, $term_name, $args );
392
393 $args['level_current'] = $level_current + 1;
394 $args['parent_term_id'] = $term_id;
395 $this->html_struct_categories( $args );
396 echo '</div>';
397 }
398 echo '</div>';
399 }
400
401 /**
402 * Return string html a field category.
403 *
404 * @param int $category_id
405 * @param string $category_name
406 * @param array $args
407 *
408 * @return false|string
409 * @since 4.2.6.5
410 * @version 1.0.0
411 */
412 public function html_field_category( int $category_id, string $category_name, array $args = [] ) {
413 $count_courses = 0;
414 $filter = new LP_Course_Filter();
415 $filter->query_count = true;
416 $filter->only_fields = [ 'DISTINCT(ID)' ];
417 $this->handle_filter_params_before_query( $filter, $args['params_url'] ?? [] );
418 $filter->term_ids = [ $category_id ];
419 //$filter->debug_string_query = true;
420 Courses::get_courses( $filter, $count_courses );
421
422 $disabled = $count_courses > 0 ? '' : 'disabled';
423 if ( ! empty( $disabled ) && ( $args['hide_count_zero'] ?? 1 ) ) {
424 return '';
425 }
426
427 $checked = in_array( $category_id, $args['data_selected'] ?? [] ) && empty( $disabled ) ? 'checked' : '';
428 $input = sprintf(
429 '<input name="term_id" type="checkbox" value="%s" %s %s>',
430 esc_attr( $category_id ),
431 esc_attr( $checked ),
432 esc_attr( $disabled )
433 );
434 $label = sprintf( '<label for="">%s</label>', wp_kses_post( $category_name ) );
435 $count = sprintf( '<span class="count">%s</span>', esc_html( $count_courses ) );
436
437 $sections = apply_filters(
438 'lp/filter-courses/course-category/sections',
439 [
440 'start' => '<div class="lp-course-filter__field">',
441 'input' => $input,
442 'label' => $label,
443 'count' => $count,
444 'end' => '</div>',
445 ],
446 $category_id,
447 $category_name,
448 $args
449 );
450
451 return Template::combine_components( $sections );
452 }
453
454 /**
455 * Get html course tag.
456 *
457 * @param array $data
458 *
459 * @return string
460 * @since 4.2.3.2
461 * @version 1.0.3
462 */
463 public function html_tag( array $data = [] ): string {
464 $content = '';
465
466 try {
467 $this->check_param_url_has_lang( $data );
468 $params_url = $data['params_url'] ?? [];
469 $data_selected = $params_url['tag_id'] ?? '';
470 $data_selected = explode( ',', $data_selected );
471 $hide_count_zero = $data['hide_count_zero'] ?? 1;
472 // Check has in tag page.
473 if ( isset( $params_url['page_tag_id_current'] ) &&
474 empty( $params_url['tag_id'] ) ) {
475 $data_selected[] = $params_url['page_tag_id_current'];
476 }
477
478 $terms = get_terms(
479 [
480 'taxonomy' => LP_COURSE_TAXONOMY_TAG,
481 'hide_empty' => true,
482 'count' => false,
483 ]
484 );
485
486 if ( empty( $terms ) ) {
487 return $content;
488 }
489
490 foreach ( $terms as $term ) {
491 $value = $term->term_id;
492 $filter = new LP_Course_Filter();
493 $filter->query_count = true;
494 $this->handle_filter_params_before_query( $filter, $params_url );
495 $filter->tag_ids = [ $value ];
496
497 $count_courses = 0;
498 Courses::get_courses( $filter, $count_courses );
499 $disabled = $count_courses > 0 ? '' : 'disabled';
500 if ( ! empty( $disabled ) && $hide_count_zero ) {
501 continue;
502 }
503 $checked = in_array( $value, $data_selected ) && empty( $disabled ) ? 'checked' : '';
504 $input = sprintf(
505 '<input name="tag_id" type="checkbox" value="%s" %s %s>',
506 esc_attr( $value ),
507 esc_attr( $checked ),
508 esc_attr( $disabled )
509 );
510 $label = sprintf( '<label for="">%s</label>', wp_kses_post( $term->name ) );
511 $count = sprintf( '<span class="count">%s</span>', esc_html( $count_courses ) );
512
513 $sections = apply_filters(
514 'lp/filter-courses/course-tag/sections',
515 [
516 'input' => $input,
517 'label' => $label,
518 'count' => $count,
519 ],
520 $term,
521 $data
522 );
523
524 $wrapper = [
525 'wrapper' => '<div class="lp-course-filter__field">',
526 'content' => Template::combine_components( $sections ),
527 'wrapper_end' => '</div>',
528 ];
529
530 $content .= Template::combine_components( $wrapper );
531 }
532
533 $content = $this->html_item( esc_html__( 'Tags', 'learnpress' ), $content );
534 } catch ( Throwable $e ) {
535 error_log( __METHOD__ . ': ' . $e->getMessage() );
536 }
537
538 return $content;
539 }
540
541 /**
542 * Get html course tag.
543 *
544 * @param array $data
545 *
546 * @return string
547 * @since 4.2.3.2
548 * @version 1.0.4
549 */
550 public function html_author( array $data = [] ): string {
551 $content = '';
552
553 try {
554 $this->check_param_url_has_lang( $data );
555 $params_url = $data['params_url'] ?? [];
556 $data_selected = $params_url['c_authors'] ?? '';
557 $data_selected = explode( ',', $data_selected );
558 $hide_count_zero = $data['hide_count_zero'] ?? 1;
559 $instructors = get_users(
560 array(
561 'role__in' => [ LP_TEACHER_ROLE, ADMIN_ROLE ],
562 'fields' => array( 'ID' ),
563 )
564 );
565
566 foreach ( $instructors as $instructorObj ) {
567 $userModel = UserModel::find( $instructorObj->ID, true );
568 if ( ! $userModel instanceof UserModel ) {
569 continue;
570 }
571
572 $instructor_id = $userModel->get_id();
573 $total_course_of_instructor = 0;
574
575 $filter = new LP_Course_Filter();
576 $filter->query_count = true;
577 $filter->only_fields = [ 'DISTINCT(ID)' ];
578 $this->handle_filter_params_before_query( $filter, $params_url );
579 $filter->post_authors = [ $instructor_id ];
580 Courses::get_courses( $filter, $total_course_of_instructor );
581
582 $value = $instructor_id;
583 $disabled = $total_course_of_instructor > 0 ? '' : 'disabled';
584 if ( ! empty( $disabled ) && $hide_count_zero ) {
585 continue;
586 }
587 $checked = in_array( $value, $data_selected ) && empty( $disabled ) ? 'checked' : '';
588 $input = sprintf(
589 '<input name="c_authors" type="checkbox" value="%s" %s %s>',
590 esc_attr( $value ),
591 esc_attr( $checked ),
592 esc_attr( $disabled )
593 );
594 $label = sprintf( '<label for="">%s</label>', esc_html( $userModel->get_display_name() ) );
595 $count = sprintf( '<span class="count">%s</span>', esc_html( $total_course_of_instructor ) );
596
597 $sections = apply_filters(
598 'lp/filter-courses/author/sections',
599 [
600 'input' => $input,
601 'label' => $label,
602 'count' => $count,
603 ],
604 $userModel,
605 $total_course_of_instructor,
606 $data
607 );
608
609 $wrapper = [
610 'wrapper' => '<div class="lp-course-filter__field">',
611 'content' => Template::combine_components( $sections ),
612 'wrapper_end' => '</div>',
613 ];
614
615 $content .= Template::combine_components( $wrapper );
616 }
617
618 $content = $this->html_item( esc_html__( 'Author', 'learnpress' ), $content );
619 } catch ( Throwable $e ) {
620 LP_Debug::error_log( $e );
621 }
622
623 return $content;
624 }
625
626 /**
627 * Get html course tag.
628 *
629 * @param array $data
630 *
631 * @return string
632 * @since 4.2.3.2
633 * @version 1.0.4
634 */
635 public function html_level( array $data = [] ): string {
636 $content = '';
637
638 try {
639 $this->check_param_url_has_lang( $data );
640 $params_url = $data['params_url'] ?? [];
641 $data_selected = $params_url['c_level'] ?? '';
642 $data_selected = explode( ',', $data_selected );
643 $fields = lp_course_level();
644 $hide_count_zero = $data['hide_count_zero'] ?? 1;
645
646 foreach ( $fields as $key => $field ) {
647 $value = $key;
648 if ( empty( $key ) ) {
649 $value = 'all';
650 }
651
652 $filter = new LP_Course_Filter();
653 $this->handle_filter_params_before_query( $filter, $params_url );
654 $filter->only_fields = [ 'DISTINCT(ID)' ];
655 $filter->query_count = true;
656 $filter->levels = [ $key ];
657 if ( $key === 'all' ) {
658 $filter->levels[] = '';
659 }
660
661 $total_courses = 0;
662 Courses::get_courses( $filter, $total_courses );
663
664 $disabled = $total_courses > 0 ? '' : 'disabled';
665 if ( ! empty( $disabled ) && $hide_count_zero ) {
666 continue;
667 }
668 $checked = in_array( $value, $data_selected ) && empty( $disabled ) ? 'checked' : '';
669 $input = sprintf(
670 '<input name="c_level" type="checkbox" value="%1$s" %2$s %3$s>',
671 esc_attr( $value ),
672 esc_attr( $checked ),
673 esc_attr( $disabled )
674 );
675 $label = sprintf( '<label for="">%s</label>', esc_html( $field ) );
676 $count = sprintf( '<span class="count">%s</span>', esc_html( $total_courses ) );
677
678 $sections = apply_filters(
679 'lp/filter-courses/levels/sections',
680 [
681 'input' => $input,
682 'label' => $label,
683 'count' => $count,
684 ],
685 $field,
686 $value,
687 $data
688 );
689
690 $wrapper = [
691 'wrapper' => '<div class="lp-course-filter__field">',
692 'content' => Template::combine_components( $sections ),
693 'wrapper_end' => '</div>',
694 ];
695
696 $content .= Template::combine_components( $wrapper );
697 }
698
699 $content = $this->html_item( esc_html__( 'Levels', 'learnpress' ), $content );
700 } catch ( Throwable $e ) {
701 error_log( __METHOD__ . ': ' . $e->getMessage() );
702 }
703
704 return $content;
705 }
706
707 /**
708 * Get HTML fields type (online/offline)
709 *
710 * @param array $data
711 *
712 * @return string
713 * @since 4.2.8.2
714 * @version 1.0.0
715 */
716 public function html_type( array $data = [] ): string {
717 $content = '';
718 try {
719 $this->check_param_url_has_lang( $data );
720 $params_url = $data['params_url'] ?? [];
721 $data_selected = $params_url['c_type'] ?? '';
722 $data_selected = explode( ',', $data_selected );
723 $filter_types = apply_filters(
724 'learn-press/filter-courses/type/fields',
725 array(
726 'online' => __( 'Online', 'learnpress' ),
727 'offline' => __( 'Offline', 'learnpress' ),
728 )
729 );
730 foreach ( $filter_types as $key => $type ) {
731 $checked = in_array( $key, $data_selected ) ? 'checked' : '';
732 $input = sprintf(
733 '<input name="c_type" type="checkbox" value="%s" %s>',
734 esc_attr( $key ),
735 esc_attr( $checked )
736 );
737 $label = sprintf( '<label for="">%s</label>', esc_html( $type ) );
738 $sections = apply_filters(
739 'lp/filter-courses/type/sections',
740 [
741 'input' => $input,
742 'label' => $label,
743 ],
744 $type,
745 $key,
746 $data
747 );
748
749 $wrapper = [
750 'wrapper' => '<div class="lp-course-filter__field">',
751 'content' => Template::combine_components( $sections ),
752 'wrapper_end' => '</div>',
753 ];
754
755 $content .= Template::combine_components( $wrapper );
756 }
757
758 $content = $this->html_item( esc_html__( 'Type', 'learnpress' ), $content );
759 } catch ( Throwable $e ) {
760 LP_Debug::error_log( $e );
761 }
762
763 return $content;
764 }
765
766 /**
767 * Get html button submit filter.
768 *
769 * @param array $data
770 *
771 * @return string
772 */
773 public function html_btn_submit( array $data = [] ): string {
774 return sprintf(
775 '<button type="submit" class="course-filter-submit">%s</button>',
776 esc_html__( 'Apply', 'learnpress' )
777 );
778 }
779
780 /**
781 * Get html button Done - for mobile when not show btn submit.
782 *
783 * @param array $data
784 *
785 * @return string
786 */
787 public function html_btn_done( array $data = [] ): string {
788 return sprintf(
789 '<button type="submit" class="course-filter-submit lp-btn-done lp-hidden">%s</button>',
790 esc_html__( 'Done', 'learnpress' )
791 );
792 }
793
794 /**
795 * Get html button reset filter.
796 *
797 * @param array $data
798 *
799 * @return string
800 */
801 public function html_btn_reset( array $data = [] ): string {
802 return sprintf(
803 '<button class="course-filter-reset">%s</button>',
804 esc_html__( 'Reset', 'learnpress' )
805 );
806 }
807
808 /**
809 * Get html button reset filter.
810 *
811 * @param array $data
812 *
813 * @return string
814 * @since 4.2.7.6
815 * @version 1.0.0
816 */
817 public function html_btn_filter_mobile( array $data = [] ): string {
818 $count = $data['count_fields_selected'] ?? '';
819 if ( $count === '(0)' ) {
820 $count = '';
821 }
822
823 $section = [
824 'wrapper' => '<div class="course-filter-btn-mobile">',
825 'icon' => '<span class="lp-icon lp-icon-filter"></span>',
826 'count_fields_selected' => sprintf(
827 '<span class="course-filter-count-fields-selected">%s</span>',
828 esc_html( $count )
829 ),
830 'wrapper_end' => '</div>',
831 ];
832
833 return Template::combine_components( $section );
834 }
835
836 /**
837 * Set params from url for filter.
838 *
839 * @param LP_Course_Filter $filter
840 * @param array $params_url
841 *
842 * @return void
843 */
844 public function handle_filter_params_before_query( LP_Course_Filter &$filter, array $params_url = [] ) {
845 Courses::handle_params_for_query_courses( $filter, $params_url );
846
847 // Check has in category page.
848 if ( isset( $params_url['page_term_id_current'] ) &&
849 empty( $params_url['term_id'] ) ) {
850 $filter->term_ids[] = $params_url['page_term_id_current'];
851 } elseif ( isset( $params_url['page_tag_id_current'] )
852 && empty( $params_url['tag_id'] ) ) {
853 $filter->tag_ids[] = $params_url['page_tag_id_current'];
854 }
855 }
856
857 /**
858 * Check param url has lang for multiple lang.
859 *
860 * @param array $data
861 *
862 * @return void
863 * @since 4.2.5.7
864 * @version 1.0.0
865 */
866 public function check_param_url_has_lang( array $data = [] ) {
867 $params_url = $data['params_url'] ?? [];
868 if ( isset( $params_url['lang'] ) ) {
869 $_REQUEST['lang'] = sanitize_text_field( $params_url['lang'] );
870 }
871 }
872 }
873