0

我有一个会议室预订系统,一个人预订会议室,并且公司员工可以在网络上看到预订。目前,如果当天有一个预订,它会正确绘制。

有几个会议室,任何一个都可以在 8:00 到 17:00 之间的任何时间预订。

如果有一个会议室预订,它看起来像这样:

在此处输入图像描述

但是当有另一个会议室预订时,在同一天,它看起来像这样:

在此处输入图像描述

我创建网格的 for 循环如下所示:

for($h = 8; $h < 17; $h++) { // hours
    for($m = 0; $m < 4; $m++) { // 15 minutes
        echo '<tr><td>' . $h . ':' . str_pad(($m*15),2,"0") . '</td>'; //plots the timeslot
        foreach($boardrooms as $boardroom) { // array of boardrooms
            foreach($boardroomBookings as $booking) { // array of boardroom bookings
                if(date('H:i',strtotime($h . ':' . str_pad(($m*15),2,"0"))) >= date('H:i',strtotime($booking['BoardroomBooking']['start_time'])) &&
                date('H:i',strtotime($h . ':' . str_pad(($m*15),2,"0"))) < date('H:i',strtotime($booking['BoardroomBooking']['end_time'])) &&
                $boardroom['Boardroom']['name'] == $booking['Boardroom']['name']) {
                    echo '<td rowspan="0" style="background-color:#8cc63f; border-bottom:none">' . $this->Html->link($booking['BoardroomBooking']['name'], array('action' => 'view', $booking['BoardroomBooking']['id'])) . '</td>'; // writes the name into the timeslot
                } else {
                    echo '<td></td>'; // writes an empty block
                }
            }
        }
        echo '</tr>'; // closes the row
    }
}

我究竟做错了什么?

更新

这是淡化的数组(仅显示使用的数据);

$boardrooms = array(
    (int) 0 => array(
        'Boardroom' => array(
            'name' => 'Big Boardroom (Pretoria)'
        )
    ),
    (int) 1 => array(
        'Boardroom' => array(
            'name' => 'Small Boardroom (Pretoria)'
        )
    ),
    (int) 2 => array(
        'Boardroom' => array(
            'name' => 'Medium Boardroom (No Screen) (Pretoria)'
        )
    ),
    (int) 3 => array(
        'Boardroom' => array(
            'name' => 'Big Boardroom (Floor 3) (Pretoria)'
        )
    ),
    (int) 4 => array(
        'Boardroom' => array(
            'name' => 'Big Boardroom (Durban)'
        )
    ),
    (int) 5 => array(
        'Boardroom' => array(
            'name' => 'Big Boardroom (Cape Town)'
        )
    )
)

$boardroomBookings = array(
    (int) 0 => array(
        'BoardroomBooking' => array(
            'id' => '1206',
            'name' => 'asdfasdf',
            'boardroom_id' => '1',
            'date' => '2013-05-21',
            'start_time' => '08:15:00',
            'end_time' => '10:00:00'
        ),
        'Boardroom' => array(
            'id' => '1',
            'name' => 'Big Boardroom (Pretoria)'
        )
    ),
    (int) 1 => array(
        'BoardroomBooking' => array(
            'id' => '1208',
            'name' => 'Test 2',
            'boardroom_id' => '4',
            'date' => '2013-05-21',
            'start_time' => '09:00:00',
            'end_time' => '12:00:00'
        ),
        'Boardroom' => array(
            'id' => '4',
            'name' => 'Big Boardroom (Floor 3) (Pretoria)'
        )
    )
)
4

1 回答 1

1

所以我修好了。

我想这可能是因为 $boardroomBookings 循环以及预订会议室和循环会议室之间的比较,所以我使用了一些微调来让它工作。

for($h = 8; $h < 17; $h++) {
    for($m = 0; $m < 4; $m++) {
        echo '<tr><td>' . $h . ':' . str_pad(($m*15),2,"0") . '</td>';
        foreach($boardrooms as $boardroom) {
            foreach($boardroomBookings as $booking) {
                if(date('H:i',strtotime($h . ':' . str_pad(($m*15),2,"0"))) >= date('H:i',strtotime($booking['BoardroomBooking']['start_time'])) &&
                date('H:i',strtotime($h . ':' . str_pad(($m*15),2,"0"))) < date('H:i',strtotime($booking['BoardroomBooking']['end_time'])) &&
                $boardroom['Boardroom']['name'] == $booking['Boardroom']['name']) {
                    $writerow = true;
                    $rowspan = (strtotime($booking['BoardroomBooking']['end_time']) - strtotime($booking['BoardroomBooking']['start_time']))/900;
                    echo '<td style="background-color:#8cc63f; border-bottom:none">' . $this->Html->link($booking['BoardroomBooking']['name'], array('action' => 'view', $booking['BoardroomBooking']['id'])) . '</td>';
                    break;
                } else {
                    $writerow = false;
                }
            }
            if(!$writerow) {
                echo '<td></td>';
            }
        }
        echo '</tr>';
    }
}
于 2013-05-16T08:00:01.920 回答