コード例 #1
0
ファイル: ICalRenderer.php プロジェクト: dstansby/camdram
 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();
 }
コード例 #2
0
 /**
  * @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);
 }
コード例 #3
0
 /**
  *
  * @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);
 }
コード例 #4
0
 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();
 }
コード例 #5
0
ファイル: ics.php プロジェクト: Rotron/jorani
 /**
  * Action : download an iCal event corresponding to a leave request
  * @param int leave request id
  * @author Benjamin BALET <*****@*****.**>
  */
 public function ical($id)
 {
     header('Content-type: text/calendar; charset=utf-8');
     header('Content-Disposition: attachment; filename=leave.ics');
     $this->load->model('leaves_model');
     $leave = $this->leaves_model->getLeaves($id);
     //Get timezone and language of the user
     $this->load->model('users_model');
     $employee = $this->users_model->getUsers($leave['employee']);
     if (!is_null($employee['timezone'])) {
         $tzdef = $employee['timezone'];
     } else {
         $tzdef = $this->config->item('default_timezone');
         if ($tzdef == FALSE) {
             $tzdef = 'Europe/Paris';
         }
     }
     $this->lang->load('global', $this->polyglot->code2language($employee['language']));
     $vcalendar = new VObject\Component\VCalendar();
     $vcalendar->add('VEVENT', array('SUMMARY' => lang('leave'), 'CATEGORIES' => lang('leave'), 'DESCRIPTION' => $leave['cause'], 'DTSTART' => new \DateTime($leave['startdate'], new \DateTimeZone($tzdef)), 'DTEND' => new \DateTime($leave['enddate'], new \DateTimeZone($tzdef)), 'URL' => base_url() . "leaves/" . $id));
     echo $vcalendar->serialize();
 }
コード例 #6
0
    $involved .= ' - ';
    if ($game[7] != 'Z' && sizeof($game[7]) == 1) {
        $involved .= $game[7][0];
    } else {
        $involved .= $game[5];
    }
    $vev->add('SUMMARY', $involved . ' / ' . $game[3] . ' / EURO 2016 France');
    //$ev->add_property('summary', $involved.' / '.$game[3].' / EURO 2016 France');
    $vev->add('DESCRIPTION', 'Game ' . $game[0] . "\n" . "source: http://www.uefa.com/uefaeuro/season=2016/matches/index.html\n\nbrought to you by http://kralo.github.io/euro2016-calendar-ics-exporter/");
    $vev->add('location', $game[2]);
    // Start-end date
    $date = DateTime::createFromFormat('j.m.Y G:i T', $game[1] . ' CEST');
    $vev->add('DTSTART', gmdate('Ymd\\TGis\\Z', $date->getTimestamp()));
    $vev->add('DURATION', 'PT1H45M');
    $vev->DTSTAMP = '20160501T235602Z';
    $vev->add('categories', 'EURO2016-Schedule');
    $vev->add('TRANSP', 'TRANSPARENT');
}
$vev = $vcalendar->add('VEVENT');
// Summary and description; also resources
$vev->add('SUMMARY', 'EURO 2016 France calendar subscription phasing out');
$vev->add('DESCRIPTION', "**Calendar is going to be deleted on 2016-08-31! Delete your subscription NOW**\n\nHey! Thank you for using my service!\nI hope it was of good use to you.\nWith the EURO being over, I will shut down this service on 2016-08-31\n" . "You should delete the subscription now because I don't know what your device will do once I shut it down.\nCheck out my other projects at https://github.com/kralo/");
// Start-end date
$date = new DateTime();
$vev->add('DTSTART', gmdate('Ymd\\T000000\\Z', $date->getTimestamp()));
$vev->add('DURATION', 'PT24H00M');
$vev->DTSTAMP = gmdate('Ymd\\TGis\\Z', (new DateTime())->getTimestamp());
$vev->add('categories', 'EURO2016-Schedule');
$vev->add('TRANSP', 'TRANSPARENT');
echo $vcalendar->serialize();
コード例 #7
0
 /**
  * Export events to iCalendar format
  *
  * @param  array   Events as array
  * @param  string  VCalendar method to advertise
  * @param  boolean Directly send data to stdout instead of returning
  * @param  callable Callback function to fetch attachment contents, false if no attachment export
  * @param  boolean Add VTIMEZONE block with timezone definitions for the included events
  * @return string  Events in iCalendar format (http://tools.ietf.org/html/rfc5545)
  */
 public function export($objects, $method = null, $write = false, $get_attachment = false, $with_timezones = true)
 {
     $this->method = $method;
     // encapsulate in VCALENDAR container
     $vcal = new VObject\Component\VCalendar();
     $vcal->VERSION = '2.0';
     $vcal->PRODID = $this->prodid;
     $vcal->CALSCALE = 'GREGORIAN';
     if (!empty($method)) {
         $vcal->METHOD = $method;
     }
     // write vcalendar header
     if ($write) {
         echo preg_replace('/END:VCALENDAR[\\r\\n]*$/m', '', $vcal->serialize());
     }
     foreach ($objects as $object) {
         $this->_to_ical($object, !$write ? $vcal : false, $get_attachment);
     }
     // include timezone information
     if ($with_timezones || !empty($method)) {
         foreach ($this->vtimezones as $tzid => $range) {
             $vt = self::get_vtimezone($tzid, $range[0], $range[1]);
             if (empty($vt)) {
                 continue;
                 // no timezone information found
             }
             if ($write) {
                 echo $vt->serialize();
             } else {
                 $vcal->add($vt);
             }
         }
     }
     if ($write) {
         echo "END:VCALENDAR\r\n";
         return true;
     } else {
         return $vcal->serialize();
     }
 }
コード例 #8
0
ファイル: ComponentTest.php プロジェクト: bodun/jorani
 function testSerializeOrderCompAndProp()
 {
     $comp = new VCalendar(array(), false);
     $comp->add($event = $comp->createComponent('VEVENT'));
     $comp->add('PROP1', 'BLABLA');
     $comp->add('VERSION', '2.0');
     $comp->add($comp->createComponent('VTIMEZONE'));
     unset($event->DTSTAMP, $event->UID);
     $str = $comp->serialize();
     $this->assertEquals("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPROP1:BLABLA\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", $str);
 }
コード例 #9
0
ファイル: planning.class.php プロジェクト: glpi-project/glpi
 /**
  *  Generate ical file content
  *
  * @param $who             user ID
  * @param $who_group       group ID
  * @param $limititemtype   itemtype only display this itemtype (default '')
  *
  * @return icalendar string
  **/
 static function generateIcal($who, $who_group, $limititemtype = '')
 {
     global $CFG_GLPI;
     if ($who === 0 && $who_group === 0) {
         return false;
     }
     if (!empty($CFG_GLPI["version"])) {
         $unique_id = "GLPI-Planning-" . trim($CFG_GLPI["version"]);
     } else {
         $unique_id = "GLPI-Planning-UnknownVersion";
     }
     // create vcalendar
     $vcalendar = new VObject\Component\VCalendar();
     // $xprops = array( "X-LIC-LOCATION" => $tz );
     // iCalUtilityFunctions::createTimezone( $v, $tz, $xprops );
     $interv = array();
     $begin = time() - MONTH_TIMESTAMP * 12;
     $end = time() + MONTH_TIMESTAMP * 12;
     $begin = date("Y-m-d H:i:s", $begin);
     $end = date("Y-m-d H:i:s", $end);
     $params = array('genical' => true, 'who' => $who, 'who_group' => $who_group, 'whogroup' => $who_group, 'begin' => $begin, 'end' => $end);
     $interv = array();
     if (empty($limititemtype)) {
         foreach ($CFG_GLPI['planning_types'] as $itemtype) {
             $interv = array_merge($interv, $itemtype::populatePlanning($params));
         }
     } else {
         $interv = $limititemtype::populatePlanning($params);
     }
     if (count($interv) > 0) {
         foreach ($interv as $key => $val) {
             if (isset($val['itemtype'])) {
                 if (isset($val[getForeignKeyFieldForItemType($val['itemtype'])])) {
                     $uid = $val['itemtype'] . "#" . $val[getForeignKeyFieldForItemType($val['itemtype'])];
                 } else {
                     $uid = "Other#" . $key;
                 }
             } else {
                 $uid = "Other#" . $key;
             }
             $vevent['UID'] = $uid;
             $vevent['DTSTART'] = new \DateTime($val["begin"]);
             $vevent['DTEND'] = new \DateTime($val["end"]);
             if (isset($val["tickets_id"])) {
                 $summary = sprintf(__('Ticket #%1$s %2$s'), $val["tickets_id"], $val["name"]);
             } else {
                 if (isset($val["name"])) {
                     $summary = $val["name"];
                 }
             }
             $vevent['SUMMARY'] = $summary;
             if (isset($val["content"])) {
                 $description = $val["content"];
                 // be sure to replace nl by \r\n
                 $description = preg_replace("/<br( [^>]*)?" . ">/i", "\r\n", $description);
                 $description = Html::clean($description);
             } else {
                 if (isset($val["name"])) {
                     $description = $val["name"];
                     // be sure to replace nl by \r\n
                     $description = preg_replace("/<br( [^>]*)?" . ">/i", "\r\n", $description);
                     $description = Html::clean($description);
                 }
             }
             $vevent['DESCRIPTION'] = $description;
             if (isset($val["url"])) {
                 $vevent['URL'] = $val["url"];
             }
             $vcalendar->add('VEVENT', $vevent);
         }
     }
     $output = $vcalendar->serialize();
     $filename = date('YmdHis') . '.ics';
     @Header("Content-Disposition: attachment; filename=\"{$filename}\"");
     @Header("Content-Length: " . Toolbox::strlen($output));
     @Header("Connection: close");
     @Header("content-type: text/calendar; charset=utf-8");
     echo $output;
 }
コード例 #10
0
 public function onStaffCreated($staff)
 {
     // Set the calendar we're creating
     $calendarName = str_replace(' ', '', $staff->user->name) . '.ics';
     // Get the calendar
     $calendar = new VCalendar();
     // Create the calendar file
     File::put(App::make('path.public') . "/calendars/{$calendarName}", $calendar->serialize());
     // Set the email data
     $data = array('name' => $staff->user->name);
     // Send the email
     Mail::send('emails.staffCreated', $data, function ($msg) use($staff) {
         $msg->to($staff->user->email)->subject(Config::get('bjga.email.subject') . " Staff Account Created")->replyTo(Config::get('bjga.email.contact'));
     });
 }
コード例 #11
0
ファイル: BuildTestData.php プロジェクト: jdt/CalBender
<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once '../Source/vendor/autoload.php';
use Sabre\VObject\Component\VCalendar;
function getClient()
{
    $client = new SimpleCalDAVClient();
    $client->connect("http://localhost:8008/calendars/users/test/calendar/", "test", "test");
    $arrayOfCalendars = $client->findCalendars();
    $client->setCalendar($arrayOfCalendars["calendar"]);
    return $client;
}
$events = getClient()->getEvents("19000101T000000Z", "20991231T235959Z");
while (count($events) > 0) {
    getClient()->delete($events[0]->getHref(), $events[0]->getEtag());
    $events = getClient()->getEvents("19000101T000000Z", "20991231T235959Z");
}
$test1 = new VCalendar(['VEVENT' => ['SUMMARY' => 'Test 1', 'DTSTART' => new \DateTime('2016-03-07 10:00:00'), 'DTEND' => new \DateTime('2016-03-07 12:00:00')]]);
$test2 = new VCalendar(['VEVENT' => ['SUMMARY' => 'Test 2', 'DTSTART' => new \DateTime('2016-03-07 12:00:00'), 'DTEND' => new \DateTime('2016-03-07 14:00:00')]]);
$test3 = new VCalendar(['VEVENT' => ['SUMMARY' => 'Test 3', 'DTSTART' => new \DateTime('2016-03-07 12:00:00'), 'DTEND' => new \DateTime('2016-03-07 15:00:00')]]);
$test4 = new VCalendar(['VEVENT' => ['SUMMARY' => 'Test 4', 'DTSTART' => new \DateTime('2016-03-07 16:00:00'), 'DTEND' => new \DateTime('2016-03-07 18:00:00')]]);
getClient()->create($test1->serialize());
getClient()->create($test2->serialize());
getClient()->create($test3->serialize());
getClient()->create($test4->serialize());
コード例 #12
0
 /**
  * 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();
 }
コード例 #13
0
 /**
  * @return string
  */
 public function __toString()
 {
     return $this->vObject->serialize();
 }
コード例 #14
0
 /**
  * get text/calendar representation of stored object
  * @return integer
  */
 public function getCalendarData()
 {
     return $this->vObject->serialize();
 }
コード例 #15
0
 /**
  * @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;
 }