File: /var/www/html/shootinschool/wp-content/plugins/shootin-school-plugin/supervisors/my_players.php
<?php
function ins_render_my_players(){
// 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(
'session_name'=>'Instruction Type',
'location_name' => 'Location',
'child_id_name' => 'Child Name',
'appointment_date' => 'Appointment date',
'appointment_time' => 'Appointment Time',
'is_cancelled' => 'Status',
'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('child_id_name' => array('child_id_name', false),'location_name' => array('location_name', false),'session_name' => array('session_name', false),'appointment_date' => array('appointment_date', false));
}
/**
* Get the table data
*
* @return Array
*/
private function table_data()
{
$cust_name ='';
if (!empty($_GET['search'])) {
$cust_name = $_GET['search'];
}
global $wpdb;
$date = date("Y-m-d");
if (!empty($_GET['search']))
{
$query = "SELECT *,".DB_APPOINTMENTS.".id as appointment_id, cl.name as location_name FROM "
.DB_APPOINTMENTS." JOIN ".DB_USERS."
as us ON us.ID = ".DB_APPOINTMENTS.".customer_id JOIN ".DB_PACKAGE_SESSIONS." as ps
ON ps.id = ".DB_APPOINTMENTS.".session_id JOIN ".DB_COACHING_LOCATIONS." as cl ON ".DB_APPOINTMENTS.".location_id = cl.id JOIN ".DB_APPOINTMENT_INSTRUCTORS."
as ins ON ins.appt_id = ".DB_APPOINTMENTS.".id WHERE
ins.instructor_id = ".get_current_user_id()." AND ins.has_attended = 1 AND ".DB_APPOINTMENTS.".child_id_name LIKE '%".$cust_name."%' GROUP BY ".DB_APPOINTMENTS.".child_id ORDER BY " . DB_APPOINTMENTS . ".id DESC";
}else{
$query = "SELECT *,".DB_APPOINTMENTS.".id as appointment_id, cl.name as location_name FROM "
.DB_APPOINTMENTS." JOIN ".DB_USERS."
as us ON us.ID = ".DB_APPOINTMENTS.".customer_id JOIN ".DB_PACKAGE_SESSIONS." as ps
ON ps.id = ".DB_APPOINTMENTS.".session_id JOIN ".DB_COACHING_LOCATIONS." as cl ON ".DB_APPOINTMENTS.".location_id = cl.id JOIN ".DB_APPOINTMENT_INSTRUCTORS."
as ins ON ins.appt_id = ".DB_APPOINTMENTS.".id WHERE
ins.instructor_id = ".get_current_user_id()." AND ins.has_attended = 1 GROUP BY ".DB_APPOINTMENTS.".child_id ORDER BY " . DB_APPOINTMENTS . ".id DESC";
}
$data = $wpdb->get_results($query, ARRAY_A);
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 'session_name':
case 'location_name':
case 'child_id_name':
case 'display_name':
return $item[$column_name];
case 'appointment_date':
return date('l, F d Y ', strtotime($item[$column_name]));
case 'appointment_time':
$split_time = explode(' - ',$item['appointment_time']);
$current_app_time = date('g:i A',strtotime($split_time[0]))." - ".date('g:i A',strtotime($split_time[1]));
return $current_app_time;
// return $item[$column_name];
case 'is_cancelled':
if($item['is_approved'] == 0 && $item['is_cancelled'] == 0){
return "Approval pending ";
}else if ($item['is_approved'] == 1 && $item[' is_cancelled'] == 0){
if($item['instructor_id'] == NULL ){
return "Booked";
} else if($item['has_attended'] != NULL && $item['has_attended'] == 1){
return "Attended";
} else if($item['has_attended'] != NULL && $item['has_attended'] == 0){
return "Not Attended";
} else{
return " Instructor Assigned";
}
}else {
return "Cancelled";
}
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_playerforum&id='.$item['child_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 = 'appointment_date';
$order = 'desc';
// 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 Players </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_players"> Reset</a>
<?php $all_appointments->display(); } ?>