Ejemplo n.º 1
0
 public function testCalendarRelation()
 {
     $calendar = new Calendar();
     $event = $this->createEvent();
     $this->assertCount(0, $calendar->getEvents());
     $this->assertNull($event->getCalendar());
     $event->setCalendar($calendar);
     $this->assertSame($calendar, $event->getCalendar());
     $this->assertSame($event, $calendar->getEvents()[0]);
 }
Ejemplo n.º 2
0
 private function importEvents(Calendar $calendar, VCalendar $document)
 {
     // Prepare by deleting all existing events
     foreach ($calendar->getEvents() as $event) {
         $this->getEntityManager()->remove($event);
     }
     $calendar->getEvents()->clear();
     // Abort if there is no events at all
     if (!$document->VEVENT) {
         return;
     }
     // First, import only originals, because we want to save RRULE before it is destroyed when expanding
     $originals = [];
     foreach ($document->VEVENT as $vevent) {
         if (!$vevent->__get('RECURRENCE-ID')) {
             $event = $this->importEvent($calendar, $vevent);
             $originals[$event->getUid()] = $event;
         }
     }
     // Expand repetitions 2 month in the past and 1 year in the future
     $now = Utility::getNow();
     $start = $now->sub(new \DateInterval('P2M'));
     $end = $now->add(new \DateInterval('P1Y'));
     // Then we expand recurent rules
     $expandedDocument = $document->expand($start, $end);
     // Abort if there is no repetitions at all
     if (!$expandedDocument->VEVENT) {
         return;
     }
     // Finally re-import, but this time only the recurrent things
     foreach ($expandedDocument->VEVENT as $vevent) {
         $original = $this->findOriginal($originals, $vevent);
         if ($original) {
             $repetition = $this->importEvent($calendar, $vevent);
             $repetition->setOriginal($original);
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * @param string $filename
  * @param string $expectedName
  * @return Event[]
  */
 private function import($filename, $expectedName)
 {
     $entityManagerMock = $this->getMock(\Doctrine\ORM\EntityManager::class, ['persist', 'flush'], [], '', false);
     $importer = new Importer();
     $importer->setEntityManager($entityManagerMock);
     $calendar = new Calendar();
     $calendar->setUrl(realpath($filename));
     $this->assertEmpty($calendar->getEvents());
     $importer->import($calendar);
     $this->assertSame($expectedName, $calendar->getName());
     // Sort events
     $events = $calendar->getEvents()->toArray();
     usort($events, function ($event1, $event2) {
         return $event1->compare($event2);
     });
     return $events;
 }