php Sabre-VObject-Component-VCalendar类(方法)实例源码

下面列出了php Sabre-VObject-Component-VCalendar 类(方法)源码代码实例,从而了解它的用法。

作者:dstansb    项目:camdra   
public function render(Diary $diary)
 {
     $vcalendar = new VCalendar();
     $vcalendar->remove('PRODID');
     $vcalendar->add('PRODID', '-//Camdram//NONSGML Show Diary//EN');
     foreach ($diary->getEvents() as $event) {
         $start_time = null;
         $rrule = array();
         if ($event instanceof MultiDayEventInterface) {
             $start_time = new \DateTime($event->getStartDate()->format('Y-m-d') . ' ' . $event->getStartTime()->format('H:i:s'));
             $last_start_time = new \DateTime($event->getEndDate()->format('Y-m-d') . ' ' . $event->getStartTime()->format('H:i:s'));
             $rrule = 'FREQ=DAILY;UNTIL=' . $last_start_time->format('Ymd\\THis\\Z');
         } elseif ($event instanceof SingleDayEventInterface) {
             $start_time = new \DateTime($event->getDate() . ' ' . $event->getStartTime()->format('H:i:s'));
         }
         if ($start_time) {
             $utc = new \DateTimeZone('UTC');
             $start_time->setTimezone($utc);
             $end_time = clone $start_time;
             $end_time->modify('+2 hours');
             $dtstamp = clone $event->getUpdatedAt();
             $dtstamp->setTimezone($utc);
             $params = array('SUMMARY' => $event->getName(), 'LOCATION' => $event->getVenue(), 'UID' => $event->getUid(), 'DTSTAMP' => $dtstamp, 'DTSTART' => $start_time, 'DURATION' => 'PT2H00M00S', 'DESCRIPTION' => $event->getDescription());
             if ($rrule) {
                 $params['RRULE'] = $rrule;
             }
             $vcalendar->add('VEVENT', $params);
         }
     }
     return $vcalendar->serialize();
 }

作者:sahne12    项目:calendarplu   
/**
  *  create VObject
  * @param string VObject as string
  * @return Sabre_VObject or null
  */
 private function createVObject($vobject_or_name)
 {
     if (is_object($vobject_or_name)) {
         return $vobject_or_name;
     } else {
         $vcomponent = null;
         switch ($vobject_or_name) {
             case 'VCALENDAR':
             case 'VTODO':
             case 'VEVENT':
             case 'VALARM':
             case 'VFREEBUSY':
             case 'VJOURNAL':
             case 'VTIMEZONE':
                 $vcomponent = new VCalendar();
                 break;
             case 'VCARD':
                 $vcomponent = new VCard();
                 break;
             default:
                 $vcomponent = new VCalendar();
                 break;
         }
         if ($vcomponent !== null) {
             $vobject = $vcomponent->createComponent($vobject_or_name);
             return $vobject;
         } else {
             return null;
         }
     }
 }

作者:gnka    项目:agenda-etudian   
/**
  * @Route("/{id}.ics")
  * @Method({"GET"})
  */
 public function menuIdAction($id)
 {
     $api = new ApiController();
     $api->setContainer($this->container);
     $menu = $api->menuIdAction($id);
     if ($menu->getStatusCode() !== 200) {
         return new Response('Calendar not found', 404);
     }
     $json = json_decode($menu->getContent(), true);
     $headers = array('Content-Type' => 'text/calendar; charset=utf-8', 'Content-Disposition' => 'attachment; filename="' . $id . '.ics');
     $vCalendar = new VCalendar();
     foreach ($json['data'] as $event) {
         $vEvent = $vCalendar->add('VEVENT');
         # Timezone
         $timezone = new DateTimeZone('Europe/Paris');
         # Start and end
         $start = new DateTime();
         $start->setTimestamp($event['start']);
         $start->setTimezone($timezone);
         $end = new DateTime();
         $end->setTimestamp($event['end']);
         $end->setTimezone($timezone);
         $name = implode(', ', $event['meals']);
         $description = implode(', ', $event['meals']);
         $vEvent->add('UID', uniqid('menu_'));
         $vEvent->add('DTSTART', $start);
         $vEvent->add('DTEND', $end);
         $vEvent->add('SUMMARY', $name);
         $vEvent->add('DESCRIPTION', $description);
     }
     $calendar = $vCalendar->serialize();
     return new Response($calendar, 200, $headers);
 }

作者:bodu    项目:joran   
public function timeRangeTestData()
 {
     $tests = array();
     $calendar = new VCalendar();
     $vevent = $calendar->createComponent('VEVENT');
     $vevent->DTSTART = '20111223T120000Z';
     $tests[] = array($vevent, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vevent, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vevent2 = clone $vevent;
     $vevent2->DTEND = '20111225T120000Z';
     $tests[] = array($vevent2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vevent2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vevent3 = clone $vevent;
     $vevent3->DURATION = 'P1D';
     $tests[] = array($vevent3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vevent3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vevent4 = clone $vevent;
     $vevent4->DTSTART = '20111225';
     $vevent4->DTSTART['VALUE'] = 'DATE';
     $tests[] = array($vevent4, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vevent4, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     // Event with no end date should be treated as lasting the entire day.
     $tests[] = array($vevent4, new \DateTime('2011-12-25 16:00:00'), new \DateTime('2011-12-25 17:00:00'), true);
     // DTEND is non inclusive so all day events should not be returned on the next day.
     $tests[] = array($vevent4, new \DateTime('2011-12-26 00:00:00'), new \DateTime('2011-12-26 17:00:00'), false);
     // The timezone of timerange in question also needs to be considered.
     $tests[] = array($vevent4, new \DateTime('2011-12-26 00:00:00', new \DateTimeZone('Europe/Berlin')), new \DateTime('2011-12-26 17:00:00', new \DateTimeZone('Europe/Berlin')), false);
     $vevent5 = clone $vevent;
     $vevent5->DURATION = 'P1D';
     $vevent5->RRULE = 'FREQ=YEARLY';
     $tests[] = array($vevent5, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vevent5, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $tests[] = array($vevent5, new \DateTime('2013-12-01'), new \DateTime('2013-12-31'), true);
     $vevent6 = clone $vevent;
     $vevent6->DTSTART = '20111225';
     $vevent6->DTSTART['VALUE'] = 'DATE';
     $vevent6->DTEND = '20111225';
     $vevent6->DTEND['VALUE'] = 'DATE';
     $tests[] = array($vevent6, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vevent6, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     // Added this test to ensure that recurrence rules with no DTEND also
     // get checked for the entire day.
     $vevent7 = clone $vevent;
     $vevent7->DTSTART = '20120101';
     $vevent7->DTSTART['VALUE'] = 'DATE';
     $vevent7->RRULE = 'FREQ=MONTHLY';
     $tests[] = array($vevent7, new \DateTime('2012-02-01 15:00:00'), new \DateTime('2012-02-02'), true);
     // The timezone of timerange in question should also be considered.
     // Added this test to check recurring events that have no instances.
     $vevent8 = clone $vevent;
     $vevent8->DTSTART = '20130329T140000';
     $vevent8->DTEND = '20130329T153000';
     $vevent8->RRULE = array('FREQ' => 'WEEKLY', 'BYDAY' => array('FR'), 'UNTIL' => '20130412T115959Z');
     $vevent8->add('EXDATE', '20130405T140000');
     $vevent8->add('EXDATE', '20130329T140000');
     $tests[] = array($vevent8, new \DateTime('2013-03-01'), new \DateTime('2013-04-01'), false);
     return $tests;
 }

作者:samj191    项目:rep   
function testAlarmWayBefore()
 {
     $vcalendar = new VObject\Component\VCalendar();
     $vevent = $vcalendar->createComponent('VEVENT');
     $vevent->DTSTART = '20120101T120000Z';
     $vevent->UID = 'bla';
     $valarm = $vcalendar->createComponent('VALARM');
     $valarm->TRIGGER = '-P2W1D';
     $vevent->add($valarm);
     $vcalendar->add($vevent);
     $filter = array('name' => 'VCALENDAR', 'is-not-defined' => false, 'time-range' => null, 'prop-filters' => array(), 'comp-filters' => array(array('name' => 'VEVENT', 'is-not-defined' => false, 'time-range' => null, 'prop-filters' => array(), 'comp-filters' => array(array('name' => 'VALARM', 'is-not-defined' => false, 'prop-filters' => array(), 'comp-filters' => array(), 'time-range' => array('start' => new \DateTime('2011-12-10'), 'end' => new \DateTime('2011-12-20')))))));
     $validator = new CalendarQueryValidator();
     $this->assertTrue($validator->validate($vcalendar, $filter));
 }

作者:ChrisdAutum    项目:EtuUT   
/**
  * @Route("/schedule/export", name="user_schedule_export")
  * @Template()
  */
 public function exportAction()
 {
     if (!$this->getUserLayer()->isStudent()) {
         return $this->createAccessDeniedResponse();
     }
     /** @var $em EntityManager */
     $em = $this->getDoctrine()->getManager();
     /** @var $courses Course[] */
     $courses = $em->getRepository('EtuUserBundle:Course')->findByUser($this->getUser());
     $vcalendar = new VCalendar();
     $semesterEnd = SemesterManager::current()->getEnd()->format('Ymd\\THis');
     foreach ($courses as $course) {
         if ($course->getUv() == 'SPJE') {
             continue;
         }
         if ($course->getDay() == Course::DAY_SATHURDAY) {
             $day = 'saturday';
         } else {
             $day = $course->getDay();
         }
         $day = new \DateTime('last ' . $day);
         $start = clone $day;
         $time = explode(':', $course->getStart());
         $start->setTime($time[0], $time[1]);
         $end = clone $day;
         $time = explode(':', $course->getEnd());
         $end->setTime($time[0], $time[1]);
         $summary = $course->getWeek() != 'T' ? $course->getUv() . ' (' . $course->getWeek() . ')' : $course->getUv();
         $vcalendar->add('VEVENT', ['SUMMARY' => $summary . ' - ' . $course->getType(), 'DTSTART' => $start, 'DTEND' => $end, 'RRULE' => 'FREQ=WEEKLY;INTERVAL=1;UNTIL=' . $semesterEnd, 'LOCATION' => $course->getRoom(), 'CATEGORIES' => $course->getType()]);
     }
     $response = new Response($vcalendar->serialize());
     $response->headers->set('Content-Type', 'text/calendar; charset=utf-8');
     $response->headers->set('Content-Disposition', 'attachment; filename="etuutt_schedule.ics"');
     return $response;
 }

作者:MetallianFR6    项目:myroundcub   
public function timeRangeTestData()
 {
     $tests = array();
     $calendar = new VCalendar();
     $vevent = $calendar->createComponent('VEVENT');
     $vevent->DTSTART = '20111223T120000Z';
     $tests[] = array($vevent, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vevent, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vevent2 = clone $vevent;
     $vevent2->DTEND = '20111225T120000Z';
     $tests[] = array($vevent2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vevent2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vevent3 = clone $vevent;
     $vevent3->DURATION = 'P1D';
     $tests[] = array($vevent3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vevent3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vevent4 = clone $vevent;
     $vevent4->DTSTART = '20111225';
     $vevent4->DTSTART['VALUE'] = 'DATE';
     $tests[] = array($vevent4, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vevent4, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     // Event with no end date should be treated as lasting the entire day.
     $tests[] = array($vevent4, new \DateTime('2011-12-25 16:00:00'), new \DateTime('2011-12-25 17:00:00'), true);
     $vevent5 = clone $vevent;
     $vevent5->DURATION = 'P1D';
     $vevent5->RRULE = 'FREQ=YEARLY';
     $tests[] = array($vevent5, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vevent5, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $tests[] = array($vevent5, new \DateTime('2013-12-01'), new \DateTime('2013-12-31'), true);
     $vevent6 = clone $vevent;
     $vevent6->DTSTART = '20111225';
     $vevent6->DTSTART['VALUE'] = 'DATE';
     $vevent6->DTEND = '20111225';
     $vevent6->DTEND['VALUE'] = 'DATE';
     $tests[] = array($vevent6, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vevent6, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     // Added this test to ensure that recurrence rules with no DTEND also
     // get checked for the entire day.
     $vevent7 = clone $vevent;
     $vevent7->DTSTART = '20120101';
     $vevent7->DTSTART['VALUE'] = 'DATE';
     $vevent7->RRULE = 'FREQ=MONTHLY';
     $tests[] = array($vevent7, new \DateTime('2012-02-01 15:00:00'), new \DateTime('2012-02-02'), true);
     return $tests;
 }

作者:vernonlacerd    项目:joran   
public function timeRangeTestData()
 {
     $calendar = new VCalendar();
     $tests = array();
     $vjournal = $calendar->createComponent('VJOURNAL');
     $vjournal->DTSTART = '20111223T120000Z';
     $tests[] = array($vjournal, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vjournal, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vjournal2 = $calendar->createComponent('VJOURNAL');
     $vjournal2->DTSTART = '20111223';
     $vjournal2->DTSTART['VALUE'] = 'DATE';
     $tests[] = array($vjournal2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vjournal2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vjournal3 = $calendar->createComponent('VJOURNAL');
     $tests[] = array($vjournal3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), false);
     $tests[] = array($vjournal3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     return $tests;
 }

作者:heiglandrea    项目:callingallpapers-api_ol   
/**
  *
  * @param Response $response
  * @param array $data
  * @param int $status
  *
  * @return ResponseInterface
  */
 public function render(ResponseInterface $response, array $data = [], $status = 200)
 {
     $icalendar = new VCalendar();
     foreach ($data['cfps'] as $cfp) {
         $cfpStart = new \DateTime($cfp['dateCfpStart']);
         $cfpEnd = new \DateTime($cfp['dateCfpEnd']);
         $lastChange = new \DateTime($cfp['lastChange']);
         $lastChange->setTimezone(new \DateTimeZone('UTC'));
         if ($cfp['timezone']) {
             $cfpStart->setTimezone(new \DateTimeZone($cfp['timezone']));
             $cfpEnd->setTimezone(new \DateTimeZone($cfp['timezone']));
         }
         $icalendar->add('VEVENT', ['SUMMARY' => $cfp['name'], 'DTSTART' => $cfpStart, 'DTEND' => $cfpEnd, 'URL' => $cfp['uri'], 'DTSTAMP' => $lastChange, 'UID' => $cfp['_rel']['cfp_uri'], 'DESCRIPTION' => $cfp['description'], 'GEO' => round($cfp['latitude'], 6) . ';' . round($cfp['longitude'], 6), 'LOCATION' => $cfp['location']]);
     }
     $response = $response->withHeader('Content-Type', 'text/calendar');
     $stream = $response->getBody();
     $stream->write($icalendar->serialize());
     return $response->withBody($stream);
 }

作者:brainex    项目:php.u   
public function listAction()
 {
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     $result = $em->getRepository('Phpug\\Entity\\Cache')->findBy(array('type' => 'event'));
     $calendar = new VObject\Component\VCalendar();
     $affectedUGs = $this->findGroupsWithinRangeAndDistance();
     foreach ($result as $cal) {
         if (!$cal->getGRoup()) {
             continue;
         }
         if ($affectedUGs && !in_array($cal->getGroup()->getShortname(), $affectedUGs)) {
             continue;
         }
         try {
             $ical = VObject\Reader::read($cal->getCache());
             foreach ($ical->children as $event) {
                 if (!$event instanceof VObject\Component\VEvent) {
                     continue;
                 }
                 $result = $event->validate(VObject\Node::REPAIR);
                 if ($result) {
                     error_log(print_r($result, true));
                     continue;
                 }
                 $event->SUMMARY = '[' . $cal->getGroup()->getName() . '] ' . $event->SUMMARY;
                 $calendar->add($event);
             }
         } catch (\Exception $e) {
         }
     }
     $viewModel = $this->getViewModel();
     if ($viewModel instanceof ViewModel) {
         $viewModel->setVariable('location', $this->params()->fromQuery('latitude', 0) . ' ' . $this->params()->fromQuery('longitude', 0));
         $viewModel->setVariable('latitude', $this->params()->fromQuery('latitude', 0));
         $viewModel->setVariable('longitude', $this->params()->fromQuery('longitude', 0));
         $viewModel->setVariable('distance', $this->params()->fromQuery('distance', 100));
     }
     return $viewModel->setVariable('calendar', new \Phpug\Wrapper\SabreVCalendarWrapper($calendar));
 }

作者:Theodi    项目:theodia.or   
/**
  * Render an event as vevent
  * @param VCalendar $vcalendar
  * @param Event $event
  * @param Place $place
  */
 private function renderEvent(VCalendar $vcalendar, Event $event, Place $place = null)
 {
     $vevent = $vcalendar->add('VEVENT', [], false);
     $this->addDate($event, $vevent, 'DTSTART', $event->getStart());
     $this->addDate($event, $vevent, 'DTEND', $event->getEnd());
     $properties = [];
     $properties['DTSTAMP'] = ['type' => 'DATE-TIME', 'value' => Utility::getNow()];
     $properties['UID'] = ['type' => 'UNKNOWN', 'value' => $event->getUid()];
     $properties['DESCRIPTION'] = ['type' => 'UNKNOWN', 'value' => $event->getDescription()];
     $properties['SUMMARY'] = ['type' => 'UNKNOWN', 'value' => $event->getName()];
     if ($place) {
         $properties['LOCATION'] = ['type' => 'UNKNOWN', 'value' => $place->getName()];
         $properties['GEO'] = ['type' => 'UNKNOWN', 'value' => $place->getLocation()->getLatitude() . ';' . $place->getLocation()->getLongitude()];
     }
     $allProperties = array_merge($properties, $event->getExtra());
     foreach ($allProperties as $key => $val) {
         $prop = $vevent->add($key, $val['value']);
         if ($val['type'] === 'DATE') {
             $prop['VALUE'] = $val['type'];
         }
     }
 }

作者:Theodi    项目:theodia.or   
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);
         }
     }
 }

作者:kleit    项目:bjga-schedule   
public function fire($job, $data)
 {
     // Get the staff member
     $staff = StaffModel::find($data['staff']);
     // Set the calendar we're using
     $calendarName = str_replace(' ', '', $staff->user->name) . '.ics';
     // Get the calendar
     $calendar = new VCalendar();
     // Get a subset of the staff member's appointments
     $series = $staff->appointments->filter(function ($a) {
         // Get 14 days prior
         $targetDate = Date::now()->subDays(14)->startOfDay();
         return $a->start >= $targetDate;
     });
     foreach ($series as $a) {
         // Create a new event
         $event = [];
         // Set the summary
         $event['SUMMARY'] = $a->service->isLesson() ? "{$a->userAppointments->first()->user->name} ({$a->service->name})" : $a->service->name;
         // Set the start time and end time
         $event['DTSTART'] = $a->start;
         $event['DTEND'] = $a->end;
         if ($a->location) {
             $event['LOCATION'] = $a->location->present()->name;
         }
         if (!empty($a->notes)) {
             $event['DESCRIPTION'] = $a->notes;
         }
         // Add the event to the calendar
         $calendar->add('VEVENT', $event);
     }
     // Write the new output to the file
     File::put(App::make('path.public') . "/calendars/{$calendarName}", $calendar->serialize());
     // Delete the job from the queue
     $job->delete();
 }

作者:MetallianFR6    项目:myroundcub   
/**
  * Merges all calendar objects, and builds one big ics export
  *
  * @param array $nodes
  * @return string
  */
 public function generateICS(array $nodes)
 {
     $calendar = new VObject\Component\VCalendar();
     $calendar->version = '2.0';
     if (DAV\Server::$exposeVersion) {
         $calendar->prodid = '-//SabreDAV//SabreDAV ' . DAV\Version::VERSION . '//EN';
     } else {
         $calendar->prodid = '-//SabreDAV//SabreDAV//EN';
     }
     $calendar->calscale = 'GREGORIAN';
     $collectedTimezones = array();
     $timezones = array();
     $objects = array();
     foreach ($nodes as $node) {
         if (!isset($node[200]['{' . Plugin::NS_CALDAV . '}calendar-data'])) {
             continue;
         }
         $nodeData = $node[200]['{' . Plugin::NS_CALDAV . '}calendar-data'];
         $nodeComp = VObject\Reader::read($nodeData);
         foreach ($nodeComp->children() as $child) {
             switch ($child->name) {
                 case 'VEVENT':
                 case 'VTODO':
                 case 'VJOURNAL':
                     $objects[] = $child;
                     break;
                     // VTIMEZONE is special, because we need to filter out the duplicates
                 // VTIMEZONE is special, because we need to filter out the duplicates
                 case 'VTIMEZONE':
                     // Naively just checking tzid.
                     if (in_array((string) $child->TZID, $collectedTimezones)) {
                         continue;
                     }
                     $timezones[] = $child;
                     $collectedTimezones[] = $child->TZID;
                     break;
             }
         }
     }
     foreach ($timezones as $tz) {
         $calendar->add($tz);
     }
     foreach ($objects as $obj) {
         $calendar->add($obj);
     }
     return $calendar->serialize();
 }

作者:zamentu    项目:roundcube_yn   
public function timeRangeTestData()
 {
     $tests = array();
     $calendar = new VCalendar();
     $vtodo = $calendar->createComponent('VTODO');
     $vtodo->DTSTART = '20111223T120000Z';
     $tests[] = array($vtodo, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vtodo, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vtodo2 = clone $vtodo;
     $vtodo2->DURATION = 'P1D';
     $tests[] = array($vtodo2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vtodo2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vtodo3 = clone $vtodo;
     $vtodo3->DUE = '20111225';
     $tests[] = array($vtodo3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vtodo3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vtodo4 = $calendar->createComponent('VTODO');
     $vtodo4->DUE = '20111225';
     $tests[] = array($vtodo4, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vtodo4, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vtodo5 = $calendar->createComponent('VTODO');
     $vtodo5->COMPLETED = '20111225';
     $tests[] = array($vtodo5, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vtodo5, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vtodo6 = $calendar->createComponent('VTODO');
     $vtodo6->CREATED = '20111225';
     $tests[] = array($vtodo6, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vtodo6, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vtodo7 = $calendar->createComponent('VTODO');
     $vtodo7->CREATED = '20111225';
     $vtodo7->COMPLETED = '20111226';
     $tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vtodo7 = $calendar->createComponent('VTODO');
     $tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), true);
     return $tests;
 }

作者:linagor    项目:sabre-vobjec   
/**
  * This issue was discovered on the sabredav mailing list.
  */
 function testCreateDatePropertyThroughAdd()
 {
     $vcal = new VCalendar();
     $vevent = $vcal->add('VEVENT');
     $dtstart = $vevent->add('DTSTART', new \DateTime('2014-03-07'), ['VALUE' => 'DATE']);
     $this->assertEquals("DTSTART;VALUE=DATE:20140307\r\n", $dtstart->serialize());
 }

作者:pagee    项目:sabre-da   
/**
  * Merges all calendar objects, and builds one big iCalendar blob.
  *
  * @param array $properties Some CalDAV properties
  * @param array $inputObjects
  * @return VObject\Component\VCalendar
  */
 function mergeObjects(array $properties, array $inputObjects)
 {
     $calendar = new VObject\Component\VCalendar();
     $calendar->version = '2.0';
     if (DAV\Server::$exposeVersion) {
         $calendar->prodid = '-//SabreDAV//SabreDAV ' . DAV\Version::VERSION . '//EN';
     } else {
         $calendar->prodid = '-//SabreDAV//SabreDAV//EN';
     }
     if (isset($properties['{DAV:}displayname'])) {
         $calendar->{'X-WR-CALNAME'} = $properties['{DAV:}displayname'];
     }
     if (isset($properties['{http://apple.com/ns/ical/}calendar-color'])) {
         $calendar->{'X-APPLE-CALENDAR-COLOR'} = $properties['{http://apple.com/ns/ical/}calendar-color'];
     }
     $collectedTimezones = [];
     $timezones = [];
     $objects = [];
     foreach ($inputObjects as $href => $inputObject) {
         $nodeComp = VObject\Reader::read($inputObject);
         foreach ($nodeComp->children() as $child) {
             switch ($child->name) {
                 case 'VEVENT':
                 case 'VTODO':
                 case 'VJOURNAL':
                     $objects[] = clone $child;
                     break;
                     // VTIMEZONE is special, because we need to filter out the duplicates
                 // VTIMEZONE is special, because we need to filter out the duplicates
                 case 'VTIMEZONE':
                     // Naively just checking tzid.
                     if (in_array((string) $child->TZID, $collectedTimezones)) {
                         continue;
                     }
                     $timezones[] = clone $child;
                     $collectedTimezones[] = $child->TZID;
                     break;
             }
         }
         // Destroy circular references to PHP will GC the object.
         $nodeComp->destroy();
         unset($nodeComp);
     }
     foreach ($timezones as $tz) {
         $calendar->add($tz);
     }
     foreach ($objects as $obj) {
         $calendar->add($obj);
     }
     return $calendar;
 }

作者:bodu    项目:joran   
/**
  * @expectedException LogicException
  */
 public function testInTimeRangeInvalidComponent()
 {
     $calendar = new VCalendar();
     $valarm = $calendar->createComponent('VALARM');
     $valarm->TRIGGER = '-P1D';
     $valarm->TRIGGER['RELATED'] = 'END';
     $vjournal = $calendar->createComponent('VJOURNAL');
     $vjournal->add($valarm);
     $valarm->isInTimeRange(new DateTime('2012-02-25 01:00:00'), new DateTime('2012-03-05 01:00:00'));
 }

作者:Henn    项目:sabre-vobjec   
//.........这里部分代码省略.........
                         $maxRecurrences = 200;
                         while ($iterator->valid() && --$maxRecurrences) {
                             $startTime = $iterator->getDTStart();
                             if ($this->end && $startTime > $this->end) {
                                 break;
                             }
                             $times[] = [$iterator->getDTStart(), $iterator->getDTEnd()];
                             $iterator->next();
                         }
                     } else {
                         $startTime = $component->DTSTART->getDateTime($this->timeZone);
                         if ($this->end && $startTime > $this->end) {
                             break;
                         }
                         $endTime = null;
                         if (isset($component->DTEND)) {
                             $endTime = $component->DTEND->getDateTime($this->timeZone);
                         } elseif (isset($component->DURATION)) {
                             $duration = DateTimeParser::parseDuration((string) $component->DURATION);
                             $endTime = clone $startTime;
                             $endTime = $endTime->add($duration);
                         } elseif (!$component->DTSTART->hasTime()) {
                             $endTime = clone $startTime;
                             $endTime = $endTime->modify('+1 day');
                         } else {
                             // The event had no duration (0 seconds)
                             break;
                         }
                         $times[] = [$startTime, $endTime];
                     }
                     foreach ($times as $time) {
                         if ($this->end && $time[0] > $this->end) {
                             break;
                         }
                         if ($this->start && $time[1] < $this->start) {
                             break;
                         }
                         $busyTimes[] = [$time[0], $time[1], $FBTYPE];
                     }
                     break;
                 case 'VFREEBUSY':
                     foreach ($component->FREEBUSY as $freebusy) {
                         $fbType = isset($freebusy['FBTYPE']) ? strtoupper($freebusy['FBTYPE']) : 'BUSY';
                         // Skipping intervals marked as 'free'
                         if ($fbType === 'FREE') {
                             continue;
                         }
                         $values = explode(',', $freebusy);
                         foreach ($values as $value) {
                             list($startTime, $endTime) = explode('/', $value);
                             $startTime = DateTimeParser::parseDateTime($startTime);
                             if (substr($endTime, 0, 1) === 'P' || substr($endTime, 0, 2) === '-P') {
                                 $duration = DateTimeParser::parseDuration($endTime);
                                 $endTime = clone $startTime;
                                 $endTime = $endTime->add($duration);
                             } else {
                                 $endTime = DateTimeParser::parseDateTime($endTime);
                             }
                             if ($this->start && $this->start > $endTime) {
                                 continue;
                             }
                             if ($this->end && $this->end < $startTime) {
                                 continue;
                             }
                             $busyTimes[] = [$startTime, $endTime, $fbType];
                         }
                     }
                     break;
             }
         }
     }
     if ($this->baseObject) {
         $calendar = $this->baseObject;
     } else {
         $calendar = new VCalendar();
     }
     $vfreebusy = $calendar->createComponent('VFREEBUSY');
     $calendar->add($vfreebusy);
     if ($this->start) {
         $dtstart = $calendar->createProperty('DTSTART');
         $dtstart->setDateTime($this->start);
         $vfreebusy->add($dtstart);
     }
     if ($this->end) {
         $dtend = $calendar->createProperty('DTEND');
         $dtend->setDateTime($this->end);
         $vfreebusy->add($dtend);
     }
     $dtstamp = $calendar->createProperty('DTSTAMP');
     $dtstamp->setDateTime(new DateTimeImmutable('now', new \DateTimeZone('UTC')));
     $vfreebusy->add($dtstamp);
     foreach ($busyTimes as $busyTime) {
         $busyTime[0] = $busyTime[0]->setTimeZone(new \DateTimeZone('UTC'));
         $busyTime[1] = $busyTime[1]->setTimeZone(new \DateTimeZone('UTC'));
         $prop = $calendar->createProperty('FREEBUSY', $busyTime[0]->format('Ymd\\THis\\Z') . '/' . $busyTime[1]->format('Ymd\\THis\\Z'));
         $prop['FBTYPE'] = $busyTime[2];
         $vfreebusy->add($prop);
     }
     return $calendar;
 }

作者:bodu    项目:joran   
/**
  * @depends testValues
  * @expectedException \InvalidArgumentException
  */
 function testNoMasterBadUID()
 {
     $vcal = new VCalendar();
     // ev2 overrides an event, and puts it on 2pm instead.
     $ev2 = $vcal->createComponent('VEVENT');
     $ev2->UID = 'overridden';
     $ev2->{'RECURRENCE-ID'} = '20120110T120000Z';
     $ev2->DTSTART = '20120110T140000Z';
     $ev2->SUMMARY = 'Event 2';
     $vcal->add($ev2);
     // ev3 overrides an event, and puts it 2 days and 2 hours later
     $ev3 = $vcal->createComponent('VEVENT');
     $ev3->UID = 'overridden';
     $ev3->{'RECURRENCE-ID'} = '20120113T120000Z';
     $ev3->DTSTART = '20120115T140000Z';
     $ev3->SUMMARY = 'Event 3';
     $vcal->add($ev3);
     $it = new EventIterator($vcal, 'broken');
 }


问题


面经


文章

微信
公众号

扫码关注公众号