1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
<?php
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
class ORDDD_View_Disable_Time_Slots_Table extends WP_List_Table {
public $base_url;
public function __construct() {
global $status, $page;
parent::__construct( array(
'singular' => __( 'block_time_slot', 'order-delivery-date' ),
'plural' => __( 'block_time_slots', 'order-delivery-date' ),
'ajax' => false
) );
$this->process_bulk_action();
$this->base_url = admin_url( 'admin.php?page=order_delivery_date&action=general_settings§ion=block_time_slot_settings' );
}
public function get_bulk_actions() {
return array(
'orddd_delete' => __( 'Delete', 'order-delivery-date' )
);
}
function column_cb( $item ){
if( isset( $item->disable_dd ) && "" != $item->disable_dd ) {
$dd = $item->disable_dd;
return sprintf(
'<input type="checkbox" name="%1$s[]" value="%2$s" />',
'block_time_slot',
$dd . ',' . $item->disable_time_slot
);
}
}
public function orddd_prepare_items() {
$columns = $this->get_columns();
$hidden = array();
$data = $this->orddd_disable_time_slot_data();
$sortable = array();
$status = isset( $_GET['status'] ) ? $_GET['status'] : 'any';
$this->_column_headers = array( $columns, $hidden, $sortable );
$this->items = $data;
}
public function get_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'disable_delivery_days_dates' => __( 'Delivery Days/Dates', 'order-delivery-date' ),
'disable_time_slot' => __( 'Time Slot', 'order-delivery-date' ),
);
return apply_filters( 'orddd_disable_time_slot_table_columns', $columns );
}
public function orddd_disable_time_slot_data() {
global $wpdb, $woocommerce, $orddd_weekdays;
$existing_timeslots_str = get_option( 'orddd_disable_time_slot_log' );
$existing_timeslots_arr = $return_disable_time_slot = array();
if ( $existing_timeslots_str == 'null' || $existing_timeslots_str == '' || $existing_timeslots_str == '{}' || $existing_timeslots_str == '[]' ) {
$existing_timeslots_arr = array();
} else {
$existing_timeslots_arr = json_decode( $existing_timeslots_str );
}
if ( count( $existing_timeslots_arr ) > 0 ) {
if( $existing_timeslots_arr == 'null' ) {
$existing_timeslots_arr = array();
}
$i = 0;
foreach ( $existing_timeslots_arr as $k => $v ) {
$time_format = get_option( 'orddd_delivery_time_format' );
if ( $time_format == '1' ) {
$time_format_to_show = 'h:i A';
} else {
$time_format_to_show = 'H:i';
}
$time_slots = json_decode( $v->ts );
foreach( $time_slots as $time_key => $time_value ) {
$return_disable_time_slot[ $i ] = new stdClass();
if ( isset( $v->dtv ) && $v->dtv == 'dates' ) {
$disable_date = explode( "-", $v->dd );
$delivery_disable_date = date( "m-d-Y", gmmktime( 0, 0, 0, $disable_date[0], $disable_date[1], $disable_date[2] ) );
$return_disable_time_slot[ $i ]->disable_delivery_days_dates = $delivery_disable_date;
$return_disable_time_slot[ $i ]->disable_dd = $v->dd;
$return_disable_time_slot[ $i ]->disable_time_slot = $time_value;
$return_disable_time_slot[ $i ]->date_type = $v->dtv;
} else {
if( isset( $orddd_weekdays[ $v->dd ] ) ) {
$return_disable_time_slot[ $i ]->disable_delivery_days_dates = $orddd_weekdays[ $v->dd ];
} else if ( $v->dd == 'all' ) {
$return_disable_time_slot[ $i ]->disable_delivery_days_dates = "All";
} else {
$return_disable_time_slot[ $i ]->disable_delivery_days_dates = "";
}
$return_disable_time_slot[ $i ]->disable_dd = $v->dd;
$return_disable_time_slot[ $i ]->disable_time_slot = $time_value;
$return_disable_time_slot[ $i ]->date_type = $v->dtv;
}
$i++;
}
}
}
return apply_filters( 'orddd_disable_time_slot_table_data', $return_disable_time_slot );
}
public function column_default( $disable_time_slot_settings, $column_name ) {
$value = isset( $disable_time_slot_settings->$column_name ) ? $disable_time_slot_settings->$column_name : '';
return apply_filters( 'orddd_disable_time_slot_table_column_default', $value, $disable_time_slot_settings, $column_name );
}
}
?>