Esempio n. 1
0
 public function testCreateRecurringEvent()
 {
     $event = new BasicEvent('My Event', 'Testing the new calendar', new \DateTime('now'), new \DateTime('tomorrow'));
     $event->repeats()->daily()->every(2)->endsOn(new \DateTime('2015-12-31'));
     $calendar = new Calendar('test');
     $calendar->add($event);
 }
Esempio n. 2
0
 /**
  * @param Calendar $calendar
  * @return AbstractEvent[]
  */
 public function run(Calendar $calendar)
 {
     $start = $this->start;
     $end = $this->end;
     return array_filter($calendar->getEvents(), function (AbstractEvent $event) use($start, $end) {
         return $event->getFrom() >= $start && $event->getTo() <= $end || $event->isRecurring() && $event->getSchedule()->nextOccurrence($start) <= $end;
     });
 }
Esempio n. 3
0
 public function setUp()
 {
     $this->calendar = new Calendar('test');
     $event = new BasicEvent('My First Event', 'Testing the new calendar', new \DateTime('2015-03-05 00:00:00'), new \DateTime('2015-03-05 23:59:59'));
     $event->repeats()->daily()->every(2)->forever();
     $this->calendar->add($event);
     $this->events[] = $event;
     $event = new BasicEvent('My Second Event', 'Testing the new calendar', new \DateTime('2015-07-15 00:00:00'), new \DateTime('2015-07-15 23:59:59'));
     $event->repeats()->weekly()->endsAfter(2);
     $this->calendar->add($event);
     $this->events[] = $event;
     $event = new BasicEvent('My Third Event', 'Testing the new calendar', new \DateTime('2015-07-15 00:00:00'), new \DateTime('2015-07-15 23:59:59'));
     $event->repeats()->monthly()->endsOn(new \DateTime('2015-06-01'));
     $this->calendar->add($event);
     $this->events[] = $event;
 }
Esempio n. 4
0
 public function slice(CalendarInterface $calendar)
 {
     $sliced = new Calendar();
     $current = $calendar->current();
     if (!$current instanceof EquatablePeriodInterface) {
         throw new UnexpectedValueException('Each period must implement Calender\\EquatablePeriodInterface.');
     }
     while ($period = $calendar->next()) {
         if (!$period instanceof EquatablePeriodInterface) {
             throw new UnexpectedValueException('Each period must implement Calender\\EquatablePeriodInterface.');
         }
         if ($current->equals($period)) {
             $current = $current->endingOn($period->getEnd());
         } else {
             $sliced->add($current);
             $current = $period;
         }
     }
     $sliced->add($current);
     if (isset($this->maxPeriodLength)) {
         $tmp = clone $sliced;
         $sliced->clear();
         foreach ($tmp as $period) {
             if ($period->getDuration()->d > $this->maxPeriodLength->d) {
                 $range = $period->getRange($this->maxPeriodLength);
                 $range = iterator_to_array($range);
                 $startDate = current($range);
                 while ($date = next($range)) {
                     $endDate = $date;
                     $subPeriod = clone $period;
                     $subPeriod->setPeriod(new BasePeriod($startDate, $endDate));
                     $sliced->add($subPeriod);
                     $startDate = $endDate;
                 }
                 $lastPeriod = clone $period;
                 $lastPeriod->setPeriod(new BasePeriod($startDate, $period->getEnd()));
                 $sliced->add($lastPeriod);
             } else {
                 $sliced->add($period);
             }
         }
     }
     return $sliced;
 }
 function getUpcomingEvents(Calendar &$calendar, $options = array())
 {
     $events = $this->cache->get($calendar->getId());
     if (is_null($events) || CACHE_BREAK_OVERRIDE) {
         $optParams = array('maxResults' => 10, 'orderBy' => 'startTime', 'singleEvents' => TRUE, 'timeMin' => date('c'));
         $options = array_merge($optParams, $options);
         $events = [];
         try {
             $results = $this->googleService->events->listEvents($calendar->getId(), $options);
             foreach ($results->getItems() as $googleEvent) {
                 array_push($events, $this->createEventFromGoogleEvent($googleEvent));
             }
         } catch (\Exception $e) {
             if (DEBUG) {
                 //                    pr($e);
             }
         }
         $events = $this->sortByFeatured($events);
         $this->cache->set($calendar->getId(), $events);
     }
     $calendar->setEvents($events);
     return $events;
 }