Addons.php
4 years ago
Admin.php
4 years ago
Ajax.php
4 years ago
Assets.php
4 years ago
Course.php
4 years ago
Course_Filter.php
4 years ago
Course_Settings_Tabs.php
4 years ago
Course_Widget.php
4 years ago
Custom_Validation.php
5 years ago
Dashboard.php
4 years ago
Email.php
5 years ago
FormHandler.php
4 years ago
Frontend.php
5 years ago
Gutenberg.php
4 years ago
Instructor.php
5 years ago
Instructors_List.php
4 years ago
Lesson.php
4 years ago
Options.php
4 years ago
Post_types.php
4 years ago
Private_Course_Access.php
5 years ago
Q_and_A.php
5 years ago
Question_Answers_List.php
4 years ago
Quiz.php
4 years ago
Quiz_Attempts_List.php
4 years ago
RestAPI.php
4 years ago
Rewrite_Rules.php
4 years ago
Shortcode.php
4 years ago
Student.php
4 years ago
Students_List.php
4 years ago
Taxonomies.php
4 years ago
Template.php
4 years ago
Theme_Compatibility.php
5 years ago
Tools.php
4 years ago
Tutor.php
4 years ago
TutorEDD.php
4 years ago
Tutor_Base.php
5 years ago
Tutor_List_Table.php
4 years ago
Tutor_Setup.php
4 years ago
Upgrader.php
4 years ago
User.php
4 years ago
Utils.php
4 years ago
Video_Stream.php
4 years ago
Withdraw.php
4 years ago
Withdraw_Requests_List.php
4 years ago
WooCommerce.php
4 years ago
Students_List.php
121 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 Students_List extends \Tutor_List_Table { |
| 12 | |
| 13 | const STUDENTS_LIST_PAGE = 'tutor-students'; |
| 14 | |
| 15 | function __construct() { |
| 16 | global $status, $page; |
| 17 | |
| 18 | //Set parent defaults |
| 19 | parent::__construct( array( |
| 20 | 'singular' => 'student', //singular name of the listed records |
| 21 | 'plural' => 'students', //plural name of the listed records |
| 22 | 'ajax' => false //does this table support ajax? |
| 23 | ) ); |
| 24 | } |
| 25 | |
| 26 | function column_default( $item, $column_name ) { |
| 27 | switch( $column_name ) { |
| 28 | case 'user_email': |
| 29 | case 'display_name': |
| 30 | return $item->$column_name; |
| 31 | case 'course_taken': |
| 32 | $course_taken = tutor_utils()->get_enrolled_courses_ids_by_user($item->ID); |
| 33 | return is_array( $course_taken ) ? count( $course_taken) : 0; |
| 34 | default: |
| 35 | return print_r( $item, true ); //Show the whole array for troubleshooting purposes |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @param $item |
| 41 | * |
| 42 | * Completed Course by User |
| 43 | */ |
| 44 | function column_completed_course( $item ) { |
| 45 | $user_id = $item->ID; |
| 46 | |
| 47 | $courses = tutor_utils()->get_courses_by_user( $user_id ); |
| 48 | if ( $courses && is_array( $courses->posts ) && count( $courses->posts ) ) { |
| 49 | foreach ( $courses->posts as $course ) { |
| 50 | echo '<a href="' . get_the_permalink( $course->ID ) . '" target="_blank">' . $course->post_title . '</a> '; |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | function column_cb( $item ) { |
| 56 | return sprintf( |
| 57 | '<input type="checkbox" name="%1$s[]" value="%2$s" />', |
| 58 | /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("student") |
| 59 | /*$2%s*/ $item->ID //The value of the checkbox should be the record's id |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | function get_columns() { |
| 64 | $columns = array( |
| 65 | 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
| 66 | 'display_name' => __('Name', 'tutor'), |
| 67 | 'user_email' => __('E-Mail', 'tutor'), |
| 68 | 'course_taken' => __( 'Course Taken', 'tutor' ), |
| 69 | 'completed_course' => __('Completed Course', 'tutor'), |
| 70 | ); |
| 71 | return $columns; |
| 72 | } |
| 73 | |
| 74 | function get_sortable_columns() { |
| 75 | $sortable_columns = array( |
| 76 | //'display_name' => array('title',false), //true means it's already sorted |
| 77 | ); |
| 78 | return $sortable_columns; |
| 79 | } |
| 80 | |
| 81 | function get_bulk_actions() { |
| 82 | $actions = array( |
| 83 | //'delete' => 'Delete' |
| 84 | ); |
| 85 | return $actions; |
| 86 | } |
| 87 | |
| 88 | function process_bulk_action() { |
| 89 | //Detect when a bulk action is being triggered... |
| 90 | if( 'delete' === $this->current_action() ) { |
| 91 | wp_die('Items deleted (or they would be if we had items to delete)!'); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | function prepare_items() { |
| 96 | $per_page = 20; |
| 97 | |
| 98 | $search_term = ''; |
| 99 | if ( isset( $_REQUEST['s'] ) ) { |
| 100 | $search_term = sanitize_text_field( $_REQUEST['s'] ); |
| 101 | } |
| 102 | |
| 103 | $columns = $this->get_columns(); |
| 104 | $hidden = array(); |
| 105 | $sortable = $this->get_sortable_columns(); |
| 106 | |
| 107 | $this->_column_headers = array( $columns, $hidden, $sortable ); |
| 108 | //$this->process_bulk_action(); |
| 109 | |
| 110 | $current_page = $this->get_pagenum(); |
| 111 | |
| 112 | $total_items = tutor_utils()->get_total_students( $search_term ); |
| 113 | $this->items = tutor_utils()->get_students( ($current_page-1) * $per_page, $per_page, $search_term ); |
| 114 | |
| 115 | $this->set_pagination_args( array( |
| 116 | 'total_items' => $total_items, //WE have to calculate the total number of items |
| 117 | 'per_page' => $per_page, //WE have to determine how many items to show on a page |
| 118 | 'total_pages' => ceil($total_items/$per_page) //WE have to calculate the total number of pages |
| 119 | ) ); |
| 120 | } |
| 121 | } |