Ejemplo n.º 1
0
 /**
  * @coversNothing
  */
 public function testExample3()
 {
     $timeZone = new \DateTimeZone('Europe/Berlin');
     // 1. Create new calendar
     $vCalendar = new \Eluceo\iCal\Component\Calendar('www.example.com');
     // 2. Create an event
     $vEvent = new \Eluceo\iCal\Component\Event('123456');
     $vEvent->setDtStart(new \DateTime('2012-12-31', $timeZone));
     $vEvent->setDtEnd(new \DateTime('2012-12-31', $timeZone));
     $vEvent->setNoTime(true);
     $vEvent->setIsPrivate(true);
     $vEvent->setSummary('New Year’s Eve');
     // Set recurrence rule
     $recurrenceRule = new \Eluceo\iCal\Property\Event\RecurrenceRule();
     $recurrenceRule->setFreq(\Eluceo\iCal\Property\Event\RecurrenceRule::FREQ_YEARLY);
     $recurrenceRule->setInterval(1);
     $vEvent->setRecurrenceRule($recurrenceRule);
     // Adding Timezone (optional)
     $vEvent->setUseTimezone(true);
     // 3. Add event to calendar
     $vCalendar->addComponent($vEvent);
     $lines = array('/BEGIN:VCALENDAR/', '/VERSION:2\\.0/', '/PRODID:www\\.example\\.com/', '/X-PUBLISHED-TTL:P1W/', '/BEGIN:VEVENT/', '/UID:123456/', '/DTSTART;TZID=Europe\\/Berlin;VALUE=DATE:20121231/', '/SEQUENCE:0/', '/TRANSP:OPAQUE/', '/DTEND;TZID=Europe\\/Berlin;VALUE=DATE:20121231/', '/SUMMARY:New Year’s Eve/', '/CLASS:PRIVATE/', '/RRULE:FREQ=YEARLY;INTERVAL=1/', '/X-MICROSOFT-CDO-ALLDAYEVENT:TRUE/', '/DTSTAMP:20\\d{6}T\\d{6}Z/', '/END:VEVENT/', '/END:VCALENDAR/');
     foreach (explode("\n", $vCalendar->render()) as $key => $line) {
         $this->assertTrue(isset($lines[$key]), 'Too many lines... ' . $line);
         $this->assertRegExp($lines[$key], $line);
     }
 }
Ejemplo n.º 2
0
<?php

// use composer autoloader
require_once __DIR__ . '/../vendor/autoload.php';
// set default timezone (PHP 5.4)
date_default_timezone_set('Europe/Berlin');
// 1. Create new calendar
$vCalendar = new \Eluceo\iCal\Component\Calendar('www.example.com');
// 2. Create an event
$vEvent = new \Eluceo\iCal\Component\Event();
$vEvent->setDtStart(new \DateTime('2012-12-31'));
$vEvent->setDtEnd(new \DateTime('2012-12-31'));
$vEvent->setNoTime(true);
$vEvent->setSummary('New Year’s Eve');
// Set recurrence rule
$recurrenceRule = new \Eluceo\iCal\Property\Event\RecurrenceRule();
$recurrenceRule->setFreq(\Eluceo\iCal\Property\Event\RecurrenceRule::FREQ_YEARLY);
$recurrenceRule->setInterval(1);
$vEvent->setRecurrenceRule($recurrenceRule);
// Adding Timezone (optional)
$vEvent->setUseTimezone(true);
// 3. Add event to calendar
$vCalendar->addComponent($vEvent);
// 4. Set headers
header('Content-Type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename="cal.ics"');
// 5. Output
echo $vCalendar->render();
Ejemplo n.º 3
0
$vTimezoneRuleDst->setTzName('CEST');
$vTimezoneRuleDst->setDtStart(new \DateTime('1981-03-29 02:00:00', $dtz));
$vTimezoneRuleDst->setTzOffsetFrom('+0100');
$vTimezoneRuleDst->setTzOffsetTo('+0200');
$dstRecurrenceRule = new \Eluceo\iCal\Property\Event\RecurrenceRule();
$dstRecurrenceRule->setFreq(\Eluceo\iCal\Property\Event\RecurrenceRule::FREQ_YEARLY);
$dstRecurrenceRule->setByMonth(3);
$dstRecurrenceRule->setByDay('-1SU');
$vTimezoneRuleDst->setRecurrenceRule($dstRecurrenceRule);
// 3. Create timezone rule object for Standard Time
$vTimezoneRuleStd = new \Eluceo\iCal\Component\TimezoneRule(\Eluceo\iCal\Component\TimezoneRule::TYPE_STANDARD);
$vTimezoneRuleStd->setTzName('CET');
$vTimezoneRuleStd->setDtStart(new \DateTime('1996-10-27 03:00:00', $dtz));
$vTimezoneRuleStd->setTzOffsetFrom('+0200');
$vTimezoneRuleStd->setTzOffsetTo('+0100');
$stdRecurrenceRule = new \Eluceo\iCal\Property\Event\RecurrenceRule();
$stdRecurrenceRule->setFreq(\Eluceo\iCal\Property\Event\RecurrenceRule::FREQ_YEARLY);
$stdRecurrenceRule->setByMonth(10);
$stdRecurrenceRule->setByDay('-1SU');
$vTimezoneRuleStd->setRecurrenceRule($stdRecurrenceRule);
// 4. Create timezone definition and add rules
$vTimezone = new \Eluceo\iCal\Component\Timezone($tz);
$vTimezone->addComponent($vTimezoneRuleDst);
$vTimezone->addComponent($vTimezoneRuleStd);
$vCalendar->setTimezone($vTimezone);
// 5. Create an event
$vEvent = new \Eluceo\iCal\Component\Event();
$vEvent->setDtStart(new \DateTime('2012-12-24', $dtz));
$vEvent->setDtEnd(new \DateTime('2012-12-24', $dtz));
$vEvent->setSummary('Summary with some german "umlauten" and a backslash \\: Kinder mögen Äpfel pflücken.');
// 6. Adding Timezone