function schedule($db, $scheduleId, $timeToSchedule, $startTime, $endTime) { $query = "SELECT startTime, endTime FROM scheduleEvent se JOIN event e WHERE scheduleId=:id AND eventId = e.id" . " ORDER BY startTime"; $query = $db->prepare($query); $query->execute(array(':id' => $scheduleId)); $eventEndTime = addTime($startTime, $timeToSchedule); $eventStartTime = $startTime; foreach ($query->fetchAll() as $event) { if (greaterThanOrEqualToTime($event['startTime'], $eventEndTime)) { break; } else { $eventStartTime = $event['endTime']; $eventEndTime = addTime($event['endTime'], $timeToSchedule); } } return array('startTime' => $eventStartTime, 'endTime' => $eventEndTime); }
function schedule($db, $scheduleId, $eventStartTime, $eventEndTime, $startTime, $endTime) { $query = "SELECT startTime, endTime FROM scheduleEvent se JOIN event e WHERE scheduleId=:id AND eventId = e.id"; $query = $db->prepare($query); $query->execute(array(':id' => $scheduleId)); $prevScheduledEnd; $isFull = false; foreach ($query->fetchAll() as $event) { if (isset($prevScheduledEnd) && greaterThanOrEqualToTime($eventStartTime, $prevScheduledEnd) && greaterThanOrEqualToTime($event['startTime'], $eventEndTime)) { return true; } $prevScheduledEnd = $event['endTime']; $isFull = true; } if (greaterThanOrEqualToTime($eventStartTime, $prevScheduledEnd)) { return true; } return !$isFull; }