3

私が望むのは、私の営業時間に従ってタイムスロットリストを計算し、予定によって予約されたタイムスロットをブロックまたは無効にすることです。

私は自分の問題でこれらのことを行い、最後のタスクに固執しました。以下に言及します。

My Service Duration = 60min.
My Today Busines Hours:
start time - 10:00 AM
end time - 3:00 PM

今日の営業時間に従って、15分のタイムスロットリストを生成しました。

$start = strtotime('10:00 AM');
$end = strtotime('3:00 PM');
for( $i = $start; $i <= $end; $i += (60*15)) 
{
    $slotlist[] = date('g:iA', $i);
}

//output
10:00AM
10:15AM
10:30AM
10:45AM
11:00AM
11:15AM
11:30AM
11:45AM
12:00PM
12:15PM
12:30PM
12:45PM
1:00PM
1:15PM
1:30PM
1:45PM
2:00PM
2:15PM
2:30PM
2:45PM
3:00PM

今私は3つの予定を予約しました

予定| 開始時間から終了時間


アポイントメント-1:10:00 AM〜11:00AM(私のサービス期間60分による)
アポイントメント-2:11:15AM〜12:15PM
アポイントメント-3:1:00PM〜2:00PM


//array of all appointment start_time
$appointment_start_time = array('10:00AM','11:15AM','1:00PM');

次に、予定ですでに予約されているタイムスロットを無効にします

foreach($slotlist as $single)
{
    if(in_array($single, $appointment_start_time))
    {
        echo "<input name=start_time type='radio' disabled  value='$single' />".$single; echo "<br>";

        $time = $single;                                                
        $event_length = 60-15;          // 60 is time duration                              
        $timestamp = strtotime("$time");                                
        $endtime = strtotime("+$event_length minutes", $timestamp);     
        $next_time = date('g:i A', $endtime);                       

        //calculate between slots (start-end time)
        $start = strtotime($single);
        $end = strtotime($next_time);
            for( $i = $start; $i <= $end; $i += (60*15)) 
            {
                $list2[] = date('g:iA', $i);
            }
    }
    else
    {   
        if(in_array($single, $list2))
        {
            echo "<input name=start_time type='radio' disabled  value='$single' />".$single; echo "<br>";
        }
        else
        {   

            echo "<input name=start_time type='radio'  value='$single' />".$single; echo "<br>";
        }
    }

}

//output
10:00AM -disabled
10:15AM -disabled
10:30AM -disabled
10:45AM -disabled
11:00AM
11:15AM -disabled
11:30AM -disabled
11:45AM -disabled
12:00PM -disabled
12:15PM
12:30PM
12:45PM
1:00PM -disabled
1:15PM -disabled
1:30PM -disabled
1:45PM -disabled
2:00PM
2:15PM
2:30PM
2:45PM
3:00PM

最後に行うタスクは、次のようにサービス期間の対象とならないタイムスロットを削除する方法です。

11:00AM (single slot b/w 2 appointment, cover only 15min)

12:15PM -
12:30PM -(3 slot b/w 2 appointment, cover only 45min)
12:45PM -
4

2 に答える 2

2

2日が経ち、私はこのことを可能にしました

$slottimes = 15;
$duration = 60; 
$business_start = '10:00AM';
$business_end = '3:00PM';
echo "<b>Today's Wroking Hours $business_start to $business_end</b><br>";
echo "<b>Calendar Slot(s) Time:</b> $slottimes<br>";
echo "<b>Service Duration Time:</b> $duration<br><br>";
$start = strtotime($business_start);
$end = strtotime($business_end);
/*$endtimestamp = strtotime($business_end);
$end = strtotime("-$slottimes minutes", $endtimestamp);*/
    for( $i = $start; $i <= $end; $i += (60*$slottimes)) 
    {
        $slotlist[] = date('g:iA', $i);
    }

echo "<b>Generate Today's Available Appointment Time(s)</b><br>";
echo "<pre>"; print_r($slotlist); echo "</pre>";

echo "<b>Today's Booked Appointment(s)</b>";
$appstarttime = array('11:00AM', '11:15AM', '1:00PM', $business_end );          //business end-time always be in array
$previoustime = NULL;
$nexttime = array($business_end);

foreach($slotlist as $single)
{
    if(in_array($single, $appstarttime))
    {
        //calculate next time
        $time = $single;                                                
        $event_length = $duration-$slottimes;           // 60min Service duration time  - 15 slot time                          
        $timestamp = strtotime("$time");                                
        $endtime = strtotime("+$event_length minutes", $timestamp);     
        $next_time = date('g:i A', $endtime);                       

        //calculate between slots (start-end time)
        $start = strtotime($single);
        $end = strtotime($next_time);
            for( $i = $start; $i <= $end; $i += (60*$slottimes)) 
            {
                $nexttime[] = date('g:iA', $i);
            }



        //calculate previous time
        $time1 = $single;                                               
        $event_length1 = $duration-$slottimes;          // 60min Service duration time - 15 slot time                               
        $timestamp1 = strtotime("$time1");                              
        $endtime1 = strtotime("-$event_length1 minutes", $timestamp1);  
        $next_time1 = date('g:i A', $endtime1);                         

        //calculate between slots (start-end time)
        $start1 = strtotime($next_time1);
        $end1 = strtotime($single);
            for( $i = $start1; $i <= $end1; $i += (60*$slottimes)) 
            {
                $previoustime[] = date('g:iA', $i);
            }


    }
}
echo "<br>Appointment Start Time: ";
print_r($appstarttime);
echo "<br>";

echo "<br><strong>Previous Time: </strong>";
print_r($previoustime);
echo "<br>";

echo "<br><strong>Next Time: </strong>";
print_r($nexttime);
echo "<br>";

echo "<br><strong>Merge Both Time:</strong> ";
if($previoustime && $nexttime)
{
    $merge = array_merge($previoustime, $nexttime);
    print_r($merge);
}
echo "<br>";echo "<br>";

$flag1 = 0;
$flag2 = 0;
echo "<hr><b>Today's Available Time For Appointment:</b><hr>";
foreach($slotlist as $single)
{
    if(in_array($single, $merge))
    {
        echo "<input name=start_time type='radio' disabled  value='$single' />".$single; echo "<br>";
    }
    else
    {
        echo "<input name=start_time type='radio'  value='$single' />".$single; echo "<br>";
    }

    if(in_array($single, $merge))
    {
        $flag1 = 1;
    }
    else
    {
        $flag2 = 2;
    }

}

if($flag2 != 2)
{   echo "Sorry ! Today's all appointments has been booked."; }

echo "<hr>";
于 2012-07-13T06:22:49.473 に答える
0

これを試してみてください: 1. 最初のタイムスロットを $appointment_start_time[0] と比較します。最初のタイムスロット > $appointment_start_time[0]-60min の場合、$appointment_start_time[0] までタイムスロットを無効にします。

2. $appointment_start_time[1] を $appointment_start_time[0] と比較し、継続時間が 2 時間 (サービス継続時間 X 2) を超える場合、$appointment_start_time[0] と $appointment_start_time[1] の間の時間帯を無効にします

3. $appointment_start_time[2] を end-time と比較し、end-time-120 < $appointment_start_time[2] の場合も無効にします

于 2012-07-11T09:15:00.923 に答える