Addons.php
5 years ago
Admin.php
5 years ago
Ajax.php
5 years ago
Assets.php
5 years ago
Course.php
5 years ago
Course_Filter.php
5 years ago
Course_Settings_Tabs.php
5 years ago
Course_Widget.php
5 years ago
Custom_Validation.php
5 years ago
Dashboard.php
5 years ago
Delete_Enrollment_With_Order.php
5 years ago
Email.php
5 years ago
FormHandler.php
5 years ago
Frontend.php
5 years ago
Gutenberg.php
5 years ago
Instructor.php
5 years ago
Instructors_List.php
5 years ago
Lesson.php
5 years ago
Options.php
5 years ago
Post_types.php
5 years ago
Private_Course_Access.php
5 years ago
Q_and_A.php
5 years ago
Question_Answers_List.php
5 years ago
Quiz.php
5 years ago
Quiz_Attempts_List.php
5 years ago
RestAPI.php
5 years ago
Rewrite_Rules.php
5 years ago
Shortcode.php
5 years ago
Student.php
5 years ago
Students_List.php
5 years ago
Taxonomies.php
5 years ago
Template.php
5 years ago
Theme_Compatibility.php
5 years ago
Tools.php
5 years ago
Tutor.php
5 years ago
TutorEDD.php
5 years ago
Tutor_Base.php
5 years ago
Tutor_List_Table.php
5 years ago
Tutor_Setup.php
5 years ago
Upgrader.php
5 years ago
User.php
5 years ago
Utils.php
5 years ago
Video_Stream.php
5 years ago
Withdraw.php
5 years ago
Withdraw_Requests_List.php
5 years ago
WooCommerce.php
5 years ago
Course_Filter.php
119 lines
| 1 | <?php |
| 2 | namespace TUTOR; |
| 3 | |
| 4 | if ( ! defined( 'ABSPATH' ) ) |
| 5 | exit; |
| 6 | |
| 7 | class Course_Filter{ |
| 8 | private $category = 'course-category'; |
| 9 | private $tag = 'course-tag'; |
| 10 | private $current_term_id = null; |
| 11 | |
| 12 | function __construct(){ |
| 13 | add_action('wp_ajax_tutor_course_filter_ajax', array($this, 'load_listing')); |
| 14 | add_action('wp_ajax_nopriv_tutor_course_filter_ajax', array($this, 'load_listing')); |
| 15 | } |
| 16 | |
| 17 | public function load_listing(){ |
| 18 | $courses_per_page = isset($_POST['course_per_page']) ? $_POST['course_per_page'] : tutils()->get_option('courses_per_page', 6); |
| 19 | $page = (isset($_POST['page']) && is_numeric($_POST['page']) && $_POST['page']>0) ? $_POST['page'] : 1; |
| 20 | |
| 21 | // Prepare taxonomy |
| 22 | $tax_query = array(); |
| 23 | foreach(['category', 'tag'] as $taxonomy){ |
| 24 | if(isset($_POST['tutor-course-filter-'.$taxonomy]) && count($_POST['tutor-course-filter-'.$taxonomy])>0){ |
| 25 | $tax_query[]=array( |
| 26 | 'taxonomy' => $this->$taxonomy, |
| 27 | 'field' => 'term_id', |
| 28 | 'terms' => $_POST['tutor-course-filter-'.$taxonomy], |
| 29 | 'operator' => 'IN' |
| 30 | ); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | // Prepare level and price type |
| 35 | $is_membership = get_tutor_option('monetize_by')=='pmpro' && tutils()->has_pmpro(); |
| 36 | $level_price=array(); |
| 37 | foreach(['level', 'price'] as $type){ |
| 38 | |
| 39 | if($is_membership && $type=='price'){ |
| 40 | continue; |
| 41 | } |
| 42 | |
| 43 | if(isset($_POST['tutor-course-filter-'.$type]) && count($_POST['tutor-course-filter-'.$type])>0){ |
| 44 | $level_price[]=array( |
| 45 | 'key' => $type=='level' ? '_tutor_course_level' : '_tutor_course_price_type', |
| 46 | 'value' => $_POST['tutor-course-filter-'.$type], |
| 47 | 'compare' => 'IN' |
| 48 | ); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | $args = array( |
| 53 | 'post_type' => 'courses', |
| 54 | 'posts_per_page' => $courses_per_page, |
| 55 | 'paged' => $page |
| 56 | ); |
| 57 | |
| 58 | count($tax_query) ? $args['tax_query']=$tax_query : 0; |
| 59 | count($level_price) ? $args['meta_query']=$level_price : 0; |
| 60 | isset($_POST['keyword']) ? $args['s']=$_POST['keyword'] : 0; |
| 61 | |
| 62 | if(isset($_POST['tutor_course_filter'])){ |
| 63 | switch ($_POST['tutor_course_filter']){ |
| 64 | case 'newest_first': |
| 65 | $args['orderby']='ID'; |
| 66 | $args['order']='desc'; |
| 67 | break; |
| 68 | case 'oldest_first': |
| 69 | $args['orderby']='ID'; |
| 70 | $args['order']='asc'; |
| 71 | break; |
| 72 | case 'course_title_az': |
| 73 | $args['orderby']='post_title'; |
| 74 | $args['order']='asc'; |
| 75 | break; |
| 76 | case 'course_title_za': |
| 77 | $args['orderby']='post_title'; |
| 78 | $args['order']='desc'; |
| 79 | break; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | query_posts($args); |
| 84 | |
| 85 | |
| 86 | $GLOBALS['tutor_shortcode_arg']=array( |
| 87 | 'column_per_row' => $_POST['column_per_row'], |
| 88 | 'course_per_page' => $courses_per_page |
| 89 | ); |
| 90 | |
| 91 | tutor_load_template('archive-course-init'); |
| 92 | exit; |
| 93 | } |
| 94 | |
| 95 | private function get_current_term_id(){ |
| 96 | |
| 97 | if($this->current_term_id===null){ |
| 98 | $queried = get_queried_object(); |
| 99 | $this->current_term_id = (is_object($queried) && property_exists($queried, 'term_id')) ? $queried->term_id : false; |
| 100 | } |
| 101 | |
| 102 | return $this->current_term_id; |
| 103 | } |
| 104 | |
| 105 | public function render_terms($taxonomy){ |
| 106 | |
| 107 | $term_id = $this->get_current_term_id(); |
| 108 | $terms = get_terms( array('taxonomy' => $this->$taxonomy, 'hide_empty' => true)); |
| 109 | |
| 110 | foreach($terms as $term){ |
| 111 | ?> |
| 112 | <label> |
| 113 | <input type="checkbox" name="tutor-course-filter-<?php echo $taxonomy; ?>" value="<?php echo $term->term_id; ?>" <?php echo $term->term_id==$term_id ? 'checked="checked"' : ''; ?>/> |
| 114 | <?php echo $term->name; ?> |
| 115 | </label> |
| 116 | <?php |
| 117 | } |
| 118 | } |
| 119 | } |