预订时间段php mysql

时间:2018-04-14 11:34:11

标签: php mysql

我正在开发一个需要预订应用程序的php mysql项目,但是我遇到了一个挑战,即拔出所有预订的时间段并且只显示可用时间。

所以基本上如果有人从09:15:00到09:30:00预订,它应该显示从08:00:00(日期开始时间)到09:15:00(预订开始时间)的时间,然后再次下一个时间段从09:30:00到18:00:00(日期结束时间)。

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;
    }

}

目前这一切都无法正常工作,有什么帮助吗?

0 个答案:

没有答案