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
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
Instructors_List.php
197 lines
| 1 | <?php |
| 2 | namespace TUTOR; |
| 3 | |
| 4 | if ( ! defined( 'ABSPATH' ) ) |
| 5 | exit; |
| 6 | |
| 7 | if (! class_exists('Tutor_List_Table')){ |
| 8 | include_once tutor()->path.'classes/Tutor_List_Table.php'; |
| 9 | } |
| 10 | |
| 11 | class Instructors_List extends \Tutor_List_Table { |
| 12 | |
| 13 | const INSTRUCTOR_LIST_PAGE = 'tutor-instructors'; |
| 14 | |
| 15 | function __construct(){ |
| 16 | global $status, $page; |
| 17 | |
| 18 | //Set parent defaults |
| 19 | parent::__construct( array( |
| 20 | 'singular' => 'instructor', //singular name of the listed records |
| 21 | 'plural' => 'instructors', //plural name of the listed records |
| 22 | 'ajax' => false //does this table support ajax? |
| 23 | ) ); |
| 24 | |
| 25 | //$this->process_bulk_action(); |
| 26 | } |
| 27 | |
| 28 | function column_default($item, $column_name){ |
| 29 | switch($column_name){ |
| 30 | case 'user_email': |
| 31 | case 'display_name': |
| 32 | return $item->$column_name; |
| 33 | default: |
| 34 | return print_r($item,true); //Show the whole array for troubleshooting purposes |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | function column_total_course($item){ |
| 39 | global $wpdb; |
| 40 | $course_post_type = tutor()->course_post_type; |
| 41 | |
| 42 | $total_course = (int) $wpdb->get_var($wpdb->prepare("SELECT count(ID) from {$wpdb->posts} WHERE post_author=%d AND post_type=%s ", $item->ID, $course_post_type)); |
| 43 | |
| 44 | echo $total_course; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @param $item |
| 49 | * |
| 50 | * Completed Course by User |
| 51 | */ |
| 52 | function column_status($item){ |
| 53 | $status = tutor_utils()->instructor_status($item->ID, false); |
| 54 | $status_name = tutor_utils()->instructor_status($item->ID); |
| 55 | echo "<span class='tutor-status-context tutor-status-{$status}-context'>{$status_name}</span>"; |
| 56 | } |
| 57 | |
| 58 | function column_display_name($item) { |
| 59 | //Build row actions |
| 60 | $actions = array(); |
| 61 | |
| 62 | $status = tutor_utils()->instructor_status($item->ID, false); |
| 63 | |
| 64 | switch ($status){ |
| 65 | case 'pending': |
| 66 | $actions['approved'] = sprintf('<a class="instructor-action" data-action="approve" data-instructor-id="'.$item->ID.'" href="?page=%s&action=%s&instructor=%s">'.__('Approve', 'tutor').'</a>', self::INSTRUCTOR_LIST_PAGE, 'approve', $item->ID); |
| 67 | break; |
| 68 | case 'approved': |
| 69 | $actions['blocked'] = sprintf('<a data-prompt-message="'.__('Sure to Block?', 'tutor').'" class="instructor-action" data-action="blocked" data-instructor-id="'.$item->ID.'" href="?page=%s&action=%s&instructor=%s">'.__('Block', 'tutor').'</a>', self::INSTRUCTOR_LIST_PAGE, 'blocked', $item->ID); |
| 70 | break; |
| 71 | case 'blocked': |
| 72 | $actions['approved'] = sprintf('<a data-prompt-message="'.__('Sure to Un Block?', 'tutor').'" class="instructor-action" data-action="approve" data-instructor-id="'.$item->ID.'" href="?page=%s&action=%s&instructor=%s">'.__('Unblock', 'tutor').'</a>', self::INSTRUCTOR_LIST_PAGE, 'approve', $item->ID); |
| 73 | break; |
| 74 | } |
| 75 | |
| 76 | // Add user edit link |
| 77 | $edit_link = get_edit_user_link($item->ID); |
| 78 | $edit_link = '<a href="'.$edit_link.'">'.__('Edit').'</a>'; |
| 79 | $actions['tutor-instructor-edit-link']=$edit_link; |
| 80 | |
| 81 | // Add remove instructor action |
| 82 | $removal_title = $status=='pending' ? __('Reject', 'tutor') : __('Remove as Instructor', 'tutor'); |
| 83 | $removal_warning = $status=='pending' ? __('Sure to Reject?', 'tutor') : __('Sure to Remove as Instructor?', 'tutor'); |
| 84 | $actions['tutor-remove-instructor'] = sprintf('<a data-prompt-message="' . $removal_warning . '" class="instructor-action" data-action="remove-instructor" data-instructor-id="'.$item->ID.'" href="?page=%s&action=%s&instructor=%s">' . $removal_title . '</a>', self::INSTRUCTOR_LIST_PAGE, 'remove-instructor', $item->ID); |
| 85 | |
| 86 | //Return the title contents |
| 87 | return sprintf('%1$s <span style="color:silver">(id:%2$s)</span>%3$s', |
| 88 | $item->display_name, |
| 89 | $item->ID, |
| 90 | $this->row_actions($actions) |
| 91 | ); |
| 92 | } |
| 93 | |
| 94 | function column_cb($item){ |
| 95 | return sprintf( |
| 96 | '<input type="checkbox" name="%1$s[]" value="%2$s" />', |
| 97 | /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("instructor") |
| 98 | /*$2%s*/ $item->ID //The value of the checkbox should be the record's id |
| 99 | ); |
| 100 | } |
| 101 | |
| 102 | function column_instructor_commission($item){ |
| 103 | $commision = apply_filters('tutor_pro_instructor_commission_string', $item->ID); |
| 104 | |
| 105 | // If the return value is numeric, it means the filter was not executed. |
| 106 | // may be pro is not installed. So show N\A. The return value will something like '23 percent' |
| 107 | |
| 108 | return !is_numeric($commision) ? $commision : 'N\\A'; |
| 109 | } |
| 110 | |
| 111 | function get_columns(){ |
| 112 | $columns = array( |
| 113 | //'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
| 114 | 'display_name' => __('Name', 'tutor'), |
| 115 | 'user_email' => __('E-Mail', 'tutor'), |
| 116 | 'total_course' => __('Total Course', 'tutor'), |
| 117 | 'instructor_commission' => __('Instructor Commission', 'tutor'), |
| 118 | 'status' => __('Status', 'tutor'), |
| 119 | ); |
| 120 | return $columns; |
| 121 | } |
| 122 | |
| 123 | function get_sortable_columns() { |
| 124 | $sortable_columns = array( |
| 125 | //'display_name' => array('title',false), //true means it's already sorted |
| 126 | ); |
| 127 | return $sortable_columns; |
| 128 | } |
| 129 | |
| 130 | function get_bulk_actions() { |
| 131 | $actions = array( |
| 132 | //'delete' => 'Delete' |
| 133 | ); |
| 134 | return $actions; |
| 135 | } |
| 136 | |
| 137 | function process_bulk_action() { |
| 138 | if( 'approve' === $this->current_action() ) { |
| 139 | $instructor_id = (int) sanitize_text_field($_GET['instructor']); |
| 140 | |
| 141 | do_action('tutor_before_approved_instructor', $instructor_id); |
| 142 | |
| 143 | update_user_meta($instructor_id, '_tutor_instructor_status', 'approved'); |
| 144 | update_user_meta($instructor_id, '_tutor_instructor_approved', tutor_time()); |
| 145 | |
| 146 | $instructor = new \WP_User($instructor_id); |
| 147 | $instructor->add_role(tutor()->instructor_role); |
| 148 | |
| 149 | //TODO: send E-Mail to this user about instructor approval, should via hook |
| 150 | do_action('tutor_after_approved_instructor', $instructor_id); |
| 151 | } |
| 152 | |
| 153 | if( 'blocked' === $this->current_action() ) { |
| 154 | $instructor_id = (int) sanitize_text_field($_GET['instructor']); |
| 155 | |
| 156 | do_action('tutor_before_blocked_instructor', $instructor_id); |
| 157 | update_user_meta($instructor_id, '_tutor_instructor_status', 'blocked'); |
| 158 | |
| 159 | $instructor = new \WP_User($instructor_id); |
| 160 | $instructor->remove_role(tutor()->instructor_role); |
| 161 | do_action('tutor_after_blocked_instructor', $instructor_id); |
| 162 | |
| 163 | //TODO: send E-Mail to this user about instructor blocked, should via hook |
| 164 | } |
| 165 | |
| 166 | //Detect when a bulk action is being triggered... |
| 167 | if( 'delete'===$this->current_action() ) { |
| 168 | wp_die('Items deleted (or they would be if we had items to delete)!'); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | function prepare_items() { |
| 173 | $per_page = 20; |
| 174 | |
| 175 | $search_term = ''; |
| 176 | if (isset($_REQUEST['s'])){ |
| 177 | $search_term = sanitize_text_field($_REQUEST['s']); |
| 178 | } |
| 179 | |
| 180 | $columns = $this->get_columns(); |
| 181 | $hidden = array(); |
| 182 | $sortable = $this->get_sortable_columns(); |
| 183 | |
| 184 | $this->_column_headers = array($columns, $hidden, $sortable); |
| 185 | |
| 186 | $current_page = $this->get_pagenum(); |
| 187 | |
| 188 | $total_items = tutor_utils()->get_total_instructors($search_term); |
| 189 | $this->items = tutor_utils()->get_instructors(($current_page-1)*$per_page, $per_page, $search_term); |
| 190 | |
| 191 | $this->set_pagination_args( array( |
| 192 | 'total_items' => $total_items, |
| 193 | 'per_page' => $per_page, |
| 194 | 'total_pages' => ceil($total_items/$per_page) |
| 195 | ) ); |
| 196 | } |
| 197 | } |