function __construct(ImportedEventModel $importedEvent)
 {
     $reoccur = $importedEvent->getReoccur();
     if (isset($reoccur) && isset($reoccur['ical_rrule']) && $reoccur['ical_rrule']) {
         $icaldata = new ICalData(clone $importedEvent->getStartAt(), clone $importedEvent->getEndAt(), $reoccur['ical_rrule'], $importedEvent->getTimezone());
         if (isset($reoccur['ical_exdates']) && is_array($reoccur['ical_exdates'])) {
             foreach ($reoccur['ical_exdates'] as $exdate) {
                 $icaldata->addExDateByString($exdate['values'], $exdate['properties']);
             }
         }
         $unraveler = new Unraveler($icaldata);
         $unraveler->setIncludeOriginalEvent(true);
         $unraveler->process();
         $results = $unraveler->getResults();
         foreach ($results as $wantedTimes) {
             $newImportedOccurrenceEvent = new ImportedEventOccurrenceModel();
             $newImportedOccurrenceEvent->setFromImportedEventModel($importedEvent);
             $newImportedOccurrenceEvent->setStartAt($wantedTimes->getStart());
             $newImportedOccurrenceEvent->setEndAt($wantedTimes->getEnd());
             $this->importedEventOccurrences[] = $newImportedOccurrenceEvent;
         }
         $this->toMultiples = true;
     } else {
         // If not a reoccuring event, there will still be 1 occurence .....
         $newImportedOccurrenceEvent = new ImportedEventOccurrenceModel();
         $newImportedOccurrenceEvent->setFromImportedEventModel($importedEvent);
         $this->importedEventOccurrences[] = $newImportedOccurrenceEvent;
         $this->toMultiples = false;
     }
 }
 public function run(ImportedEventOccurrenceModel $importedEventOccurrenceModel)
 {
     $eventRepo = new EventRepository();
     $eventRecurSetRepo = new EventRecurSetRepository();
     if ($importedEventOccurrenceModel->hasReoccurence()) {
         // Have to load it looking for the right time to!
         $event = $this->loadEventForImportedReoccurredEvent($importedEventOccurrenceModel);
     } else {
         // just load it.
         $event = $this->loadEventForImportedEvent($importedEventOccurrenceModel);
     }
     if ($event) {
         $this->eventsSeenIDs[] = $event->getId();
         // Set Existing Event From Import Event URL
         if ($importedEventOccurrenceModel->getIsDeleted()) {
             if (!$event->getIsDeleted()) {
                 $eventRepo->delete($event);
                 return true;
             }
         } else {
             if ($event->setFromImportedEventModel($importedEventOccurrenceModel) || $event->getIsDeleted()) {
                 $event->setIsDeleted(false);
                 $eventRepo->edit($event);
                 return true;
             }
         }
     } else {
         if (!$this->importURL->getIsManualEventsCreation()) {
             // New Event From Import Event URL
             $event = $this->newEventFromImportedEventModel($importedEventOccurrenceModel);
             if ($this->eventRecurSet) {
                 $event->setEventRecurSetId($this->eventRecurSet->getId());
             }
             $eventRepo->create($event, $this->site, null, $this->group, null, $importedEventOccurrenceModel);
             $this->eventsSeenIDs[] = $event->getId();
             if (!$this->eventRecurSet && $this->makeEventRecurSetIfNone) {
                 $this->eventRecurSet = $eventRecurSetRepo->getForEvent($event);
             }
             return true;
         } else {
             return false;
         }
     }
     return false;
 }