HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/shootinschool/wp-content/plugins/shootin-school-plugin/instructors/my_instructors.php
<?php

function ins_render_my_instructors(){
    // die("ddd");
    $user_id = get_current_user_id();
    global $wpdb;
    $instructor = $wpdb->get_row("SELECT display_name FROM ".DB_USERS." WHERE ID = $user_id");
   
    /**
     * Display the list table page
     *
     * @return Void
     */
    class Appointment_Table extends WP_List_Table
    {

        // die("ddd");
        /**
         * Prepare the items for the table to process
         *
         * @return Void
         */

         function __construct() {
            parent::__construct( array(
                'singular'=> 'appointment',
                'plural' => 'table-nw',
                'ajax'   => false
            ) );
        }
        public function prepare_items()
        {
            $columns = $this->get_columns();
            $hidden = $this->get_hidden_columns();
            $sortable = $this->get_sortable_columns();

            $data = $this->table_data();
            usort($data, array(&$this, 'sort_data'));

            $perPage = 10;
            $currentPage = $this->get_pagenum();
            $totalItems = count($data);

            $this->set_pagination_args(array(
                'total_items' => $totalItems,
                'per_page'    => $perPage
            ));

            $data = array_slice($data, (($currentPage - 1) * $perPage), $perPage);

            $this->_column_headers = array($columns, $hidden, $sortable);
            $this->items = $data;
        }

        /**
         * Override the parent columns method. Defines the columns to use in your listing table
         *
         * @return Array
         */
        public function get_columns()
        {
            $columns = array(
                // 'sl' => 'Sl No',
                'display_name'	=> 'Name',
                'user_email' => 'Email ID',
                // 'user_registered' => 'Registration Date',
                'actions' => 'Actions',

            );

            return $columns;
        }

        /**
         * Define which columns are hidden
         *
         * @return Array
         */
        public function get_hidden_columns()
        {
            return array();
        }

        /**
         * Define the sortable columns
         *
         * @return Array
         */
        public function get_sortable_columns()
        {
            return array('display_name' => array('display_name', false));   
        }

        /**
         * Get the table data
         *
         * @return Array
         */
        // private function table_data()
        // { 
        //     global $wpdb;
        //     $cust_name ='';

        //     if (!empty($_GET['search'])) {
        //         $cust_name = $_GET['search'];
        //     }
        //     global $wpdb;
        //     $date = date("Y-m-d");
        //     if (!empty($_GET['search'])) 
        //     {

        //     }
		// 			$users_table = $wpdb->prefix . "users";

		// 			$args = array(
		// 			    'role'    => 'siab_instructor',
		// 			    'orderby' => 'created_at',
		// 			    'order'   => 'DESC',
		// 			    'fields' => array( 'ID' ),
		// 				'meta_query' => array(
		// 					array(
		// 						'key'     => 'issupervisor',
		// 						'value'   => 1,
		// 						'compare' => '!=' // You can change this if necessary (e.g., '!=' for not equal)
		// 					)
		// 				)
		// 			);
        //             $userIds = get_users( $args );
		// 			$temp = array();
		// 			foreach ($userIds as $single) {
		// 				$temp[] = $single->ID;
		// 			}

		// 			if(count($temp) > 0){
		// 				$data = $wpdb->get_results("SELECT * FROM " .$users_table." WHERE ID IN (" .implode(',', $temp). ")", ARRAY_A);
		// 			} else{
		// 				$data = array();
		// 			}

		// 			return $data;
        // }

        private function table_data() { 
            global $wpdb;
        
            $cust_name = '';
            if (!empty($_GET['search'])) {
                $cust_name = $_GET['search'];
            }
        
            $users_table = $wpdb->prefix . "users";
            $date = date("Y-m-d");
        
            // Base arguments for getting users
            $args = array(
                'role'    => 'siab_instructor',
                'orderby' => 'created_at',
                'order'   => 'DESC',
                'fields'  => array('ID'),
                'meta_query' => array(
                    array(
                        'key'     => 'issupervisor',
                        'value'   => 1,
                        'compare' => '!=' // Adjust if needed
                    )
                )
            );
        
            // Add a search condition if a search term is provided
            if (!empty($cust_name)) {
                $args['search'] = '*' . esc_attr($cust_name) . '*';
                $args['search_columns'] = array('user_login', 'user_nicename', 'user_email'); // Search in these fields
            }
        
            // Get users based on the arguments
            $userIds = get_users($args);
            $temp = array();
        
            foreach ($userIds as $single) {
                $temp[] = $single->ID;
            }
        
            // Perform the query if there are matching users
            if (count($temp) > 0) {
                $data = $wpdb->get_results("SELECT * FROM " . $users_table . " WHERE ID IN (" . implode(',', $temp) . ")", ARRAY_A);
            } else {
                $data = array();
            }
        
            return $data;
        }
        

        /**
         * Define what data to show on each column of the table
         *
         * @param  Array $item        Data
         * @param  String $column_name - Current column name
         *
         * @return Mixed
         */
        public function column_default($item, $column_name)
        {

            switch ($column_name) {
                case 'ID':
                case 'display_name':
                case 'user_email':
                // case 'user_registered':
                    return $item[$column_name];
                default:
                    return print_r($item, true);
            }
        }

        function column_actions($item){

                $actions = array(
                    
                   'Comments' => sprintf('<a style="margin-top: 8px;" class="btn btn-success btn-xs" href="admin.php?page=siab-instructor_forum&id='.$item['ID'].'" >Comments</a>'),
                );
          

            return sprintf(
                // '%1$s <span style="color:silver">(Edit:%2$s)</span>%3$s',
                /*$1%s*/
                // $item['title'],
                /*$2%s*/
                // $item['id'],
                /*$3%s*/
                $this->row_actions($actions)
            );
        }

        /**
         * Allows you to sort the data by the variables set in the $_GET
         *
         * @return Mixed
         */
        private function sort_data($a, $b)
        {
            // Set defaults
					$orderby = 'directorName';
					$order = 'asc';

					// If orderby is set, use this as the sort column
					if (!empty($_GET['orderby'])) {
						$orderby = $_GET['orderby'];
					}

					// If order is set use this as the order
					if (!empty($_GET['order'])) {
						$order = $_GET['order'];
					}

					$result = strcmp($a[$orderby], $b[$orderby]);

					if ($order === 'asc') {
						return $result;
					}

					return -$result;
        }

        // function display() {
        //     // Add your custom class to the table
        //     echo '<table class="wp-list-table widefat fixed striped table-view-list toplevel_page_siab-instructor_players table-nw table">';
        //     parent::display();
        //     echo '</table>';
        // }
    }
  
   

    /**
     * Display the list table page
     *
     * @return Void
     */
    $cust_name ='';

    if (!empty($_GET['search'])) {
        $cust_name = $_GET['search'];
    }
    $all_appointments = new Appointment_Table();
    $all_appointments->prepare_items();
   
    

?>
<div class="wrap cover-main-nw myplyr-wrp">
      

        
<div class="wrap alert-nw">
					<div class="css_loader">Loading…</div>
					<div class="alert alert-info" role="alert">
						<h3> My Instructors </h3>
					</div>
				</div>
        
            <input type="text" value="<?php echo $cust_name;?>" name="cust_name" id="cust_name" placeholder="Search by name">
            
            <button class="btn btn-primary btn-sm" type="button" onclick="ApplyPlayerNameFilter()">Search</button>
            <a class="btn btn-default btn-sm" href="admin.php?page=siab-instructor-instructor"> Reset</a>
   
    <?php  $all_appointments->display();   } ?>