I am working on an appointment booking system, and there is a form that collects start date and end date from the user to check the consultant availability, lets suppose if you select start date as March 27 and end date as March 29 which are three days then i am displaying three rows and each row contains the operating hours of an office with half hour interval to book a meeting and this is how it looks like.
The timings that appear are supposed to hide the time slot already booked.
I am able to display the hours available for each day perfectly fine except that if a meeting has been booked for lets say march 28 for time 02:00PM - 02-30PM then this time is being hidden for all days except for only march 28.
Following is the code i am using for this purpose
<?php
$start = new DateTime('09:00:00');
$end = new DateTime('16:00:01'); // add 1 second because last one is not included in the loop
$interval = new DateInterval('PT30M');
$period = new DatePeriod($start, $interval, $end);
$existing_time = array(
array(
'start_time' => '2014-03-28T14:00:00+1100',
'end_time' => '2014-03-28T14:30:00+1100'
),
array(
'start_time' => '2014-03-28T15:00:00+1100',
'end_time' => '2014-03-28T15:30:00+1100'
)
);
?>
<div id="accordion2" class="accordion">
<?php for ($i = 0; $i < 3; $i++) {
?>
<div class="accordion-group">
<div class="accordion-heading">
<a href="#collapse<?php echo $i ?>" data-parent="#accordion2" data-toggle="collapse"
class="accordion-toggle collapsed">
<?php echo date('Y-m-d', strtotime('2014-03-27' . ' + ' . $i . ' day')) ?>
</a>
</div>
<div class="accordion-body collapse" id="collapse<?php echo $i ?>" style="height: 0px;">
<div class="accordion-inner">
<?php
$booked = array();
foreach ($existing_time as $ex) {
$dt = new DateTime($ex['start_time']);
$booked[] = $dt->format('h:ia');
}
$previous = '';
foreach ($period as $dt) {
$current = $dt->format("h:ia");
if (!empty($previous) && !in_array($previous, $booked)) {
echo "<input name='time' type='radio' value='{$previous}|{$current}'> {$previous}-{$current}<br/>";
}
$previous = $current;
}
?>
</div>
</div>
</div>
<?php } ?>
</div>
I will really appreciate any help on this.