2009/12/3 Merlin Morgenstern <[email protected]>:
> That is what I thought first, too! But this does not work correct as there
> might be a booking starting for example tomorrow. There needs to be free
> place for the entire booking period.
Ah, of course. I see the problem now. It's an odd situation, because
you don't seem to care if room A is available for the first half of
the period, and room B is available for the second half - as long as
the number of rooms never goes above 3. Checking for a single room
being available continuously for that entire period would be a lot
simpler.
If your resolution is 1 minute, then I'd run the query for every
minute of the event. 5 minute or 15 minute resolution would mean doing
far fewer queries. If the event count ever goes above 3, you can
short-circuit. Something like (pseudo-code)...
function is_room_available($start, $end, $resolution, $max) {
for($i = $start; $i < $end; $i+=$resolution)
{
$count = SELECT COUNT(*) FROM `event` WHERE `start` <= $i AND
`end` >= $i
if($count => $max) {
return false;
}
}
return true;
}
But I think turning it around might be simpler. Think:
I have three rooms. For each room, can it accept a 4 hour booking
starting at time $time?
Then the number of queries is a function of the number of rooms,
rather than the length of the meeting.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php