I am working on a php mysql project that need a booking app, I have however ran into a challenge of pulling out all booked time slots and only displaying available time around this.
So basically if someone booked from 09:15:00 to 09:30:00, it should show time available from 08:00:00 (date start time) to 09:15:00 (booking start time), then again next time slot from 09:30:00 to 18:00:00 (date end time).
function createForAvailableHrs($FirstStartTime, $lastEndTime, $date)
{
$connector = new DbConnector();
$this_date = date("Y-m-d", strtotime($date[1]));
$result = $connector->query("SELECT * FROM GPC_appointments WHERE deletedBy = ? AND appointmentDate = ?", array(0,$this_date));
$rowCount = $connector->num_results($result);
if($rowCount > 0) {
$count = $connector->num_results($result);
$c = 0;
$show = '';
$newStartTime = '';
$lastNewEndTime = '';
while ($row = $connector->fetchArray($result))
{
//Set New check time points
if ($row['appointmentTimeFrom'] !== '') {
//IF BOOKING IS LESS THAN START TIME
$endTime = $row['appointmentTimeTo'];
$startTime = $row['appointmentTimeFrom'];
if($newStartTime == '') { $newStartTime = $FirstStartTime; }
//IF BOOKING IS LESS THAN START TIME
if ($this->dateDiffInterval($endTime, $startTime, 'H') < 2) { $endTime = $this->AdjustEndTime($startTime); }
//IF BOOKING END TIME IS GREATER THAN 2 HOURS
if (abs($this->dateDiffInterval($endTime, $startTime, 'H')) >= 2) { $startTime = $this->AdjustEndTime($startTime); }
if($this->getNextEndTime($startTime,$date) !== FALSE && $this->getNextEndTime($startTime,$date) !== null) { //next startTime is > "15 min", newEndTime = nextStartTime
//$newEndTime = $endTime;// + strtotime($this->getNextEndTime($startTime,$date));
$newEndTime = $this->AdjustEndTime($endTime, $this->getNextEndTime($startTime,$date));
}
else {
$newEndTime = $this->AdjustEndTime($endTime, '');
}
if ($endTime > $FirstStartTime) {
$newEndTime = $startTime;//date("H:i:s",strtotime("+ 15 minutes",$startTime))$endTime;
$endTime = $FirstStartTime;
}
if (date("H:i:s", strtotime($newStartTime)) > date("H:i:s", strtotime($FirstStartTime))) { $startTime = $FirstStartTime; }
$show .= "<div class='bookingSlots' data-bookingFromHours='".$endTime."' "
. "data-timeDiff='".abs($this->dateDiffInterval($endTime, $newEndTime, 'H'))."' "
. "data-bookingToHours='".$newEndTime."' data-bookdate='$date[1]'>".
$endTime. " am to ".$newEndTime." </div>";
}
$c++;
if ($c == $count) {
$show .= $this->createForStandardWorkHrs($date, $newEndTime);
}
}
return $show;
}
else {
return FALSE;
}
}
Currently it all does not work as intended , Any help?