public function isFree(Kronolith_Event $event)
{
if (is_array($event)) {
$start = $event['start'];
$end = $event['end'];
} else {
$start = $event->start;
$end = $event->end;
}
/* Get all resources that are included in this category */
$resources = $this->get('members');
/* Iterate over all resources until one with no conflicts is found */
foreach ($resources as $resource_id) {
$conflict = false;
try {
$resource = $this->_driver->getResource($resource_id);
} catch (Horde_Exception_NotFound $e) {
continue;
}
$busy = Kronolith::getDriver('Resource', $resource->get('calendar'))->listEvents($start, $end, array('show_recurrence' => true));
/* No events at all during time period for requested event */
if (!count($busy)) {
$this->_selectedResource = $resource;
return true;
}
/* Check for conflicts, ignoring the conflict if it's for the
* same event that is passed. */
if (!is_array($event)) {
$uid = $event->uid;
} else {
$uid = 0;
}
foreach ($busy as $events) {
foreach ($events as $e) {
if (!($e->status == Kronolith::STATUS_CANCELLED || $e->status == Kronolith::STATUS_FREE) && $e->uid !== $uid) {
if (!($e->start->compareDateTime($end) >= 0) && !($e->end->compareDateTime($start) <= 0)) {
// Not free, continue to the next resource
$conflict = true;
break 2;
}
}
}
}
if (!$conflict) {
/* No conflict detected for this resource */
$this->_selectedResource = $resource;
return true;
}
}
/* No resource found without conflicts */
return false;
}