I am working with codeigniter,I have two tables (shop info and booking),and i want to fetch data with 30 minutes slot after shop open and want to check whether in that time shop is booked or not,I am fetching and make 30 minutes slot successfully,But how can i get upcoming 15 days record and match ? means i want to get and compare 15 days data after todays date,How can i do this ?
I want data like this (9:00 to 09:30 is booked)
"availability": [
{
"id": 1,
"date": "29-Apr-2019",
"arrTimeSlots": [
{
"id": 1,
"time": "09:00 AM",
"alreadyBooked": true
},
{
"id": 2,
"time": "09:30 AM",
"alreadyBooked": true
},
{
"id": 3,
"time": "10:00 AM",
"alreadyBooked": false
},
"date": "30-Apr-2019",
"arrTimeSlots": [
{
"id": 1,
"time": "09:00 AM",
"alreadyBooked": false
},
{
"id": 2,
"time": "09:30 AM",
"alreadyBooked": false
},
{
"id": 3,
"time": "10:00 AM",
"alreadyBooked": false
},
}
Here is my current code,How can i do this ?
$add_data['shop_id'] = ($this->input->post('shop_id') && !empty($this->input->post('shop_id'))) ? $this->input->post('shop_id') : NULL;
$this->db->select('*');
$this->db->from('additional_info');
$this->db->where('shop_id',$add_data['shop_id']);
$query = $this->db->get();
if ( $query->num_rows() > 0 )
{
$row = $query->row_array();
$start=$row['shop_open_time'];
$end=$row['shop_close_time'];
$start_time=substr($start, 0, -10);
$end_time=substr($end, 0, -10);
$start_time = new DateTime($start_time);
$close_time = new DateTime($end_time);
$periods = new DatePeriod($start_time, new DateInterval('PT30M'), $close_time);
foreach ($periods as $period) {
$times[] = $period->format('H:i');
}
$times[] = $close_time->format('H:i');
//print_r($times);
$availability = array_fill_keys($times, 'available');
function book(&$availability, $start, $end)
{
foreach($availability as $k => $v)
if(strtotime($k) >= strtotime($start) && strtotime($k) <= strtotime($end))
$availability[$k] = 'booked';
}
$this->db->select('*');
$this->db->from('usr_booking');
$this->db->where('shop_id',$add_data['shop_id']);
$queryc = $this->db->get();
foreach($queryc->result_array() as $results)
{
//print_R($results);
$s=$results['start_time'];
$e=$results['end_time'];
book($availability, $s, $e);
}
echo "<pre>";print_r($availability);