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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
<?php
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
class ORDDD_View_Time_Slots_Table extends WP_List_Table {
public $base_url;
public function __construct() {
global $status, $page;
parent::__construct( array(
'singular' => __( 'time_slot', 'order-delivery-date' ),
'plural' => __( '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=time_slot' );
}
public function get_bulk_actions() {
return array(
'orddd_delete' => __( 'Delete', 'order-delivery-date' )
);
}
function column_cb( $item ){
$dd = '';
if( isset( $item->dd ) ) {
$dd = $item->dd;
return sprintf(
'<input type="checkbox" name="%1$s[]" value="%2$s" />',
'time_slot',
$dd . ',' . $item->fh . ',' . $item->fm . ',' . $item->th . ',' . $item->tm . ',' . $item->tv
);
}
}
public function orddd_prepare_items() {
$columns = $this->get_columns();
$hidden = array();
$data = $this->orddd_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" />',
'delivery_days_dates' => __( 'Delivery Days/Dates', 'order-delivery-date' ),
'time_slot' => __( 'Time Slot', 'order-delivery-date' ),
'maximum_order_deliveries_per_time_slot' => __( 'Maximum Order Deliveries per time slot', 'order-delivery-date' ),
'additional_charges_for_time_slot' => __( 'Additional Charges for time slot', 'order-delivery-date' ),
'time_slot_checkout_label' => __( 'Checkout label', 'order-delivery-date' ),
);
return apply_filters( 'orddd_shipping_settings_table_columns', $columns );
}
public function orddd_time_slot_data() {
global $wpdb, $woocommerce, $orddd_weekdays;
$return_time_slot = array();
if ( isset( $_POST[ 'current_date' ] ) ) {
$current_date = $_POST[ 'current_date' ];
}
$lockout_time = get_option( 'orddd_lockout_time_slot' );
$existing_timeslots_str = get_option( 'orddd_delivery_time_slot_log' );
$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';
}
$from_time = $v->fh.":".$v->fm;
$ft = date( $time_format_to_show, strtotime( $from_time ) );
if ( $v->th != 00 ){
$to_time = $v->th.":".$v->tm;
$tt = date( $time_format_to_show, strtotime( $to_time ) );
$key = $ft." - ".$tt;
} else {
$key = $ft;
}
$currency_symbol = get_woocommerce_currency_symbol();
if( isset( $v->additional_charges ) ) {
$additional_charges = $v->additional_charges;
} else {
$additional_charges = 0;
}
if( isset( $v->additional_charges_label ) ) {
$additional_charges_label = $v->additional_charges_label;
} else {
$additional_charges_label = "";
}
if ( gettype( json_decode( $v->dd ) ) == 'array' && count( json_decode( $v->dd ) ) > 0 ) {
$dd = json_decode( $v->dd );
foreach( $dd as $dkey => $dval ) {
$return_time_slot[ $i ] = new stdClass();
$return_time_slot[ $i ]->fh = $v->fh;
$return_time_slot[ $i ]->fm = $v->fm;
$return_time_slot[ $i ]->th = $v->th;
$return_time_slot[ $i ]->tm = $v->tm;
$return_time_slot[ $i ]->tv = $v->tv;
if ( isset( $v->tv ) && $v->tv == 'specific_dates' ) {
$date = explode( "-", $dval );
$date_to_display = date( "m-d-Y", gmmktime( 0, 0, 0, $date[0], $date[1], $date[2] ) );
$return_time_slot[ $i ]->delivery_days_dates = $date_to_display;
$return_time_slot[ $i ]->dd = $dval;
$return_time_slot[ $i ]->time_slot = $key;
$return_time_slot[ $i ]->maximum_order_deliveries_per_time_slot = $v->lockout;
if( $additional_charges != "" ) {
$return_time_slot[ $i ]->additional_charges_for_time_slot = $currency_symbol . '' . $additional_charges;
} else {
$return_time_slot[ $i ]->additional_charges_for_time_slot = '';
}
$return_time_slot[ $i ]->time_slot_checkout_label = $additional_charges_label;
} else {
if( isset( $orddd_weekdays[ $dval ] ) ) {
$return_time_slot[ $i ]->delivery_days_dates = $orddd_weekdays[ $dval ];
$return_time_slot[ $i ]->dd = $dval;
} else if ( $dval == 'all' ) {
$return_time_slot[ $i ]->delivery_days_dates = "All";
$return_time_slot[ $i ]->dd = $dval;
} else {
$return_time_slot[ $i ]->delivery_days_dates = "";
$return_time_slot[ $i ]->dd = "";
}
$return_time_slot[ $i ]->time_slot = $key;
$return_time_slot[ $i ]->maximum_order_deliveries_per_time_slot = $v->lockout;
if( $additional_charges != "" ) {
$return_time_slot[ $i ]->additional_charges_for_time_slot = $currency_symbol . '' . $additional_charges;
} else {
$return_time_slot[ $i ]->additional_charges_for_time_slot = '';
}
$return_time_slot[ $i ]->time_slot_checkout_label = $additional_charges_label;
}
$i++;
}
} else {
$return_time_slot[ $i ] = new stdClass();
$return_time_slot[ $i ]->fh = $v->fh;
$return_time_slot[ $i ]->fm = $v->fm;
$return_time_slot[ $i ]->th = $v->th;
$return_time_slot[ $i ]->tm = $v->tm;
$return_time_slot[ $i ]->tv = $v->tv;
$dd = $v->dd;
if( isset( $orddd_weekdays[ $dd ] ) ) {
$return_time_slot[ $i ]->delivery_days_dates = $orddd_weekdays[ $dd ];
$return_time_slot[ $i ]->dd = $dd;
} else if ( $dd == 'all' ) {
$return_time_slot[ $i ]->delivery_days_dates = "All";
$return_time_slot[ $i ]->dd = $dd;
} else {
$return_time_slot[ $i ]->delivery_days_dates = "";
$return_time_slot[ $i ]->dd = "";
}
$return_time_slot[ $i ]->time_slot = $key;
$return_time_slot[ $i ]->maximum_order_deliveries_per_time_slot = $v->lockout;
if( $additional_charges != "" ) {
$return_time_slot[ $i ]->additional_charges_for_time_slot = $currency_symbol . '' . $additional_charges;
} else {
$return_time_slot[ $i ]->additional_charges_for_time_slot = '';
}
$return_time_slot[ $i ]->time_slot_checkout_label = $additional_charges_label;
$i++;
}
}
}
return apply_filters( 'orddd_shipping_settings_table_data', $return_time_slot );
}
public function column_default( $timeslot_settings, $column_name ) {
$value = isset( $timeslot_settings->$column_name ) ? $timeslot_settings->$column_name : '';
return apply_filters( 'bkap_booking_table_column_default', $value, $timeslot_settings, $column_name );
}
}
?>