public function createEventSeries(CalendarEventInterface $event) { $reoccurance = $event->getCalendarReoccurance(); $reoccurance->setStartDate($event->getStartDatetime()); //$reoccurance->setEndDate($event->getEndDatetime()); $eventDuration = $event->getStartDatetime()->diff($event->getEndDatetime()); $eventDates = $this->getArrayOfStartDates($reoccurance); foreach ($eventDates as $startDate) { $this->processTime($startDate, $event->getStartDatetime()); $newEvent = clone $event; $newEvent->setStartDatetime($startDate)->setEndDatetime($startDate->add($eventDuration))->setCalendarReoccurance($reoccurance); $reoccurance->addCalendarEvent($newEvent); $this->entityManager->persist($newEvent); } // Get an array of all the StartDateTimes that the reoccurance requires // For each new date // Clone the event // Get the difference between the original event start and end date // Append the orgigonal start time to the new event start date // Add the differential to get an end date. // Add the new entity to the Reoccurance. // Save the entity. }
/** * Remove a CalendarEvent from the database. * * @param CalendarEventInterface $event */ public function deleteEventSeries(CalendarEventInterface $event) { $em = $this->entityManager; $reoccurance = $event->getCalendarReoccurance(); $deletedIdArray = []; foreach ($reoccurance->getCalendarEvents() as $eventToRemove) { $deletedIdArray[] = $eventToRemove->getId(); $em->remove($eventToRemove); } $em->remove($reoccurance); $em->flush(); return $deletedIdArray; }