private function _checkConflicts(&$response, \GO\Calendar\Model\Event &$event, &$params) { if (!empty($params["check_conflicts"]) && $event->busy) { $exception_for_event_id = empty($params['exception_for_event_id']) ? 0 : $params['exception_for_event_id']; if (count($event->getConflictingEvents($exception_for_event_id))) { throw new \Exception('Ask permission'); } } // // /* Check for conflicts with other events in the calendar */ // $findParams = \GO\Base\Db\FindParams::newInstance(); // $findParams->getCriteria()->addCondition("calendar_id", $event->calendar_id); // if(!$event->isNew) // $findParams->getCriteria()->addCondition("resource_event_id", $event->id, '<>'); // // $conflictingEvents = \GO\Calendar\Model\Event::model()->findCalculatedForPeriod($findParams, $event->start_time, $event->end_time, true); // // while($conflictEvent = array_shift($conflictingEvents)) { // // \GO::debug("Conflict: ".$event->id." ".$event->name); // // if($conflictEvent["id"]!=$event->id && (empty($params['exception_for_event_id']) || $params['exception_for_event_id']!=$conflictEvent["id"])){ // throw new \Exception('Ask permission'); // } // } /* Check for conflicts regarding resources */ if (!$event->isResource() && isset($params['resources'])) { //TODO code does not work right. Should be refactored in 4.1 $resources = array(); foreach ($params['resources'] as $resource_calendar_id => $enabled) { if ($enabled == 'on') { $resources[] = $resource_calendar_id; } } if (count($resources) > 0) { $findParams = \GO\Base\Db\FindParams::newInstance(); $findParams->getCriteria()->addInCondition("calendar_id", $resources); if (!$event->isNew) { $findParams->getCriteria()->addCondition("resource_event_id", $event->id, '<>'); } $conflictingEvents = \GO\Calendar\Model\Event::model()->findCalculatedForPeriod($findParams, $event->start_time, $event->end_time, true); $resourceConlictsFound = false; foreach ($conflictingEvents as $conflictEvent) { if ($conflictEvent->getEvent()->id != $event->id) { $resourceCalendar = $conflictEvent->getEvent()->calendar; $resourceConlictsFound = true; $response['resources'][] = $resourceCalendar->name; } } if ($resourceConlictsFound) { $response["feedback"] = "Resource conflict"; $response["success"] = false; return false; } } } return true; }