/** * @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); } }
function event_to_ical($event) { $vCalendar = new \Eluceo\iCal\Component\Calendar('Calendar API V1'); $vEvent = new \Eluceo\iCal\Component\Event(); $vEvent->setDtStart($event->start); $vEvent->setDtEnd($event->start); $vEvent->setNoTime(true); $vEvent->setSummary($event->summary); return $vEvent; }
public function testDescriptionWithNewLines() { $input = "new string \n new line \n new line \n new string"; $vCalendar = new \Eluceo\iCal\Component\Calendar('www.example.com'); $vEvent = new \Eluceo\iCal\Component\Event(); $vEvent->setDtStart(new \DateTime('2014-12-24')); $vEvent->setDtEnd(new \DateTime('2014-12-24')); $vEvent->setDescription($input); $vCalendar->addComponent($vEvent); $output = $vCalendar->render(); $this->assertContains($input, $output); }
public function write() { $vCalendar = new \Eluceo\iCal\Component\Calendar('www.example.com'); $erb = new EventRepositoryBuilder($this->siteContainer); // TODO up to one month old! foreach ($erb->fetchAll() as $event) { $vEvent = new \Eluceo\iCal\Component\Event(); $vEvent->setDtStart($event->getStart())->setDtEnd($event->getEnd())->setSummary($event->getTitle())->setDescription($event->getDescription())->setUrl($this->twigHelper->getTwig()->getExtension('openacalendar_internallink')->internalLinkToDir('/event/' . $event->getSlug())); $vCalendar->addComponent($vEvent); } $this->outFolder->addFileContents('api1', 'events.ics', $vCalendar->render()); }
/** * Add a new calendar event. * * @param Request $request * * * @Route("/download", name="event_download") * @Method("GET") */ public function downloadAction() { $vCalendar = new \Eluceo\iCal\Component\Calendar('www.example.com'); $vEvent = new \Eluceo\iCal\Component\Event(); $vEvent->setDtStart(new \DateTime('2012-12-24'))->setDtEnd(new \DateTime('2012-12-24'))->setNoTime(true)->setSummary('Christmas'); $vCalendar->addComponent($vEvent); $response = new Response(); $response->setContent($vCalendar->render())->setCharset('ISO-8859-1')->setStatusCode(Response::HTTP_OK); $response->headers->set('Content-Type', 'multipart/alternative'); $response->headers->set('Content-Disposition', 'attachment; filename="cal.ics"'); return $response; }
public function testFoldWithMultibyte() { $input = "x" . str_repeat("あいうえお", 5); $vCalendar = new \Eluceo\iCal\Component\Calendar('www.example.com'); $vEvent = new \Eluceo\iCal\Component\Event(); $vEvent->setDtStart(new \DateTime('2012-12-24')); $vEvent->setDtEnd(new \DateTime('2012-12-24')); $vEvent->setDescription($input); $vCalendar->addEvent($vEvent); $output = $vCalendar->render(); $output = preg_replace('/\\r\\n /u', '', $output); $this->assertContains($input, $output); }
public function calendar($society_id) { $events = $this->eventsForSociety($society_id)['events']; $vCalendar = new \Eluceo\iCal\Component\Calendar('lowdown.netsoc.co'); foreach ($events as $event) { $vEvent = new \Eluceo\iCal\Component\Event(); $eventTime = new DateTime($event->time); $endTime = $eventTime; $endTime->add(new DateInterval('PT1H')); $eventSummary = $event->society()->first()->name . ' Society: ' . $event->title; $vEvent->setDtStart($eventTime)->setDtEnd($endTime)->setSummary($eventSummary); if ($event->location) { $vEvent->setLocation($event->location); } $vCalendar->addComponent($vEvent); } header('Content-Type: text/calendar; charset=utf-8'); header('Content-Disposition: attachment; filename="cal.ics"'); echo $vCalendar->render(); }
/** * Renders an ical file for a specific group */ public function group(Group $group) { // 1. Create new calendar $vCalendar = new \Eluceo\iCal\Component\Calendar(config('app.url')); $vCalendar->setName(config('mobilizator.name') . ' : ' . $group->name); $vCalendar->setDescription(summary($group->body, 500)); // returns actions started the last 60 days $actions = $group->actions()->where('start', '>=', Carbon::now()->subDays(60))->get(); foreach ($actions as $action) { // 2. Create an event $vEvent = new \Eluceo\iCal\Component\Event(); $vEvent->setDtStart($action->start); $vEvent->setDtEnd($action->stop); $vEvent->setSummary($action->name); $vEvent->setDescription(summary($action->body), 1000); $vEvent->setLocation($action->location); $vEvent->setUrl(action('ActionController@show', [$action->group->id, $action->id])); $vEvent->setUseUtc(false); //TODO fixme $vCalendar->addComponent($vEvent); } return response($vCalendar->render())->header('Content-Type', 'text/calendar; charset=utf-8')->header('Content-Disposition', 'attachment; filename="cal.ics"'); }
public function ical($key) { switch ($key) { case 'public': $items = BookingItem::where('start_at', '>=', date('Y-m-d'))->where('booking.is_private', '=', false)->with('booking', 'ressource')->get(); $description = ''; break; default: $filter = true; if (preg_match('/^(.+)_(.+)$/', $key, $tokens)) { $key = $tokens[1]; if ($tokens[2] != 'all') { App::abort(404); return false; } $filter = false; } $owner = User::where('booking_key', '=', $key)->first(); if (!$owner) { App::abort(404); return false; } $description = $owner->fullname; $items = BookingItem::where('start_at', '>=', date('Y-m-d'))->join('booking', 'booking_item.booking_id', '=', 'booking.id')->join('users', 'booking.user_id', '=', 'users.id'); if ($filter) { $items = $items->where('users.booking_key', '=', $key); } $items = $items->with('booking', 'ressource')->get(); break; } $vCalendar = new \Eluceo\iCal\Component\Calendar(Request::server('SERVER_NAME')); $vCalendar->setDescription($description); $tz = new DateTimeZone(date_default_timezone_get()); foreach ($items as $booking_item) { $start = new \DateTime($booking_item->start_at); $start->setTimezone($tz); $end = new \DateTime($booking_item->start_at); $start->setTimezone($tz); $end->modify(sprintf('+%d minutes', $booking_item->duration)); $vEvent = new \Eluceo\iCal\Component\Event(); $vEvent->setDtStart($start)->setDtEnd($end)->setUseTimezone(true)->setSummary(sprintf('%s (%s)', $booking_item->booking->title, $booking_item->ressource->name)); $vCalendar->addComponent($vEvent); } $response = Response::make($vCalendar->render()); $response->header('Content-Type', 'text/calendar; charset=utf-8'); $response->header('Content-Disposition', 'attachment; filename="cal.ics"'); return $response; }
<?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-11-11 13:00:00')); $vEvent->setDtEnd(new \DateTime('2012-11-11 14:30:00')); $vEvent->setSummary('Weekly lunch with Markus'); // Set recurrence rule $recurrenceRule = new \Eluceo\iCal\Property\Event\RecurrenceRule(); $recurrenceRule->setFreq(\Eluceo\iCal\Property\Event\RecurrenceRule::FREQ_WEEKLY); $recurrenceRule->setInterval(1); $vEvent->setRecurrenceRule($recurrenceRule); // Adding Timezone (optional) $vEvent->setUseTimezone(true); // 3. Add event to calendar $vCalendar->addEvent($vEvent); // 4. Set headers header('Content-Type: text/calendar; charset=utf-8'); header('Content-Disposition: attachment; filename="cal.ics"'); // 5. Output echo $vCalendar->render();
function makeICalendar($row) { $vEvent = new \Eluceo\iCal\Component\Event(); $vEvent->setDtStart(new \DateTime($row['startDate'])); $vEvent->setDtEnd(new \DateTime($row['endDate'])); $vEvent->setNoTime(false); $vEvent->setSummary($row['name'] . " 2016 New Years Levee"); $vEvent->setLocation($row['location_name'] . "\n" . $row['location_address'], $row['location_name'], $row['latitude'] . "," . $row['longitude']); $vEvent->setUseTimezone(true); return $vEvent; }
public function generateIcal() { // set default timezone (PHP 5.4) date_default_timezone_set('Europe/Berlin'); $ical_name = 'HSG Wesel - Gesamtspielplan'; $ical_calid = 'hsg_wesel_1516_total'; $ics_file_name = 'hsg_wesel_1516_total.ics'; $team_info = $this->getTeamInfo(); if (is_array($team_info)) { $ical_name = 'HSG Wesel - Saison 2015/16 - ' . $team_info['team']; $ical_calid = 'hsg_wesel_1516_' . $team_info['liga_id']; $ics_file_name = 'hsg_wesel_1516_' . $this->getTeam() . '.ics'; } else { switch ($this->art) { case '188': $ical_name = 'HSG Wesel - Saison 2015/16 - Spielplan Heim'; $ical_calid = 'hsg_wesel_1516_1330105011_heim'; $ics_file_name = 'hsg_wesel_1516_spielplan_heim' . '.ics'; break; case '199': $ical_name = 'HSG Wesel - Saison 2015/16 - Spielplan Auswärts'; $ical_calid = 'hsg_wesel_1516_1330105011_auswaerts'; $ics_file_name = 'hsg_wesel_1516_auswaerts' . '.ics'; break; } } // 1. Create new calendar $vCalendar = new \Eluceo\iCal\Component\Calendar('HSG Wesel SIS-Handball ICS-Generator'); $vCalendar->setName($ical_name); $vCalendar->setDescription('HSG Wesel / photominister.de'); $vCalendar->setCalId($ical_calid); $vCalendar->setMethod('PUBLISH'); // 2. Create an event // $this->framework->dump($this->art); if (count($this->xml->Spiel) > 0) { foreach ($this->xml->Spiel as $spiel) { $element = $this->getHash($spiel); $show_heim = substr($spiel->Heim, 0, 9) == 'HSG Wesel'; $show_gast = substr($spiel->Gast, 0, 9) == 'HSG Wesel'; switch ($this->art) { case '188': $cond = $show_heim; break; case '199': $cond = $show_gast; break; default: $cond = $show_heim || $show_gast; break; } if ($cond) { $description = $spiel->LigaName . '..... www.hsg-wesel.de ..... www.handballinwesel.de ..... www.facebook.com/hsgwesel'; $description = str_replace("\r\n", "\\n", $description); $vEvent = new \Eluceo\iCal\Component\Event(); $vEvent->setDtStart(new \DateTime($spiel->SpielVon)); $vEvent->setDtEnd(new \DateTime($spiel->SpielBis)); $vEvent->setSummary($spiel->Heim . ' - ' . $spiel->Gast); $vEvent->setDescription($description); $vEvent->setLocation($spiel->HallenName . ', ' . $spiel->HallenStrasse . ', ' . $spiel->HallenOrt); $vEvent->setUseTimezone(TRUE); // 3. Add event to calendar $vCalendar->addComponent($vEvent); unset($vEvent); } } } // 4. Set headers header('Content-Type: text/calendar; charset=utf-8'); header('Content-Disposition: attachment; filename="' . $ics_file_name . '"'); // 5. Output echo $vCalendar->render(); exit; }
//pull the information for all the modules $modinfo = get_fast_modinfo($course); foreach ($modinfo->cms as $mod) { //if completion is not enabled, then skip it if (!$mod->completion || !$mod->completionexpected) { continue; } //if hidden then skip it if (!$mod->visible) { continue; } $dt = new DateTime(); $dt->setTimestamp($mod->completionexpected); //create an event $ievent = new \Eluceo\iCal\Component\Event(); $ievent->setDtStart($dt); $ievent->setDtEnd($dt); $ievent->setNoTime(true); $ievent->setSummary($mod->name); //add Timezone (optional) $ievent->setUseTimezone(true); //add event to calendar $ical->addComponent($ievent); } //set headers $filename = preg_replace('/[^A-Za-z0-9_\\-]/', '_', $course->shortname) . '_Calendar.ics'; header('Content-Type: text/calendar; charset=utf-8'); header('Content-Disposition: attachment; filename="' . $filename . '"'); //output echo $ical->render(); exit;
public function generateCalendar(Request $request) { $vCalendar = new Calendar('www.boilermake.org'); $events = Event::all(); // Iterate through all events foreach ($events as $event) { $vEvent = new \Eluceo\iCal\Component\Event(); $vEvent->setDtStart(new \DateTime($event->begin))->setDtEnd(new \DateTime($event->end))->setNoTime(true)->setSummary($event->title); $vCalendar->addComponent($vEvent); } // Headers that might not actually do anything header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); //date in the past header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); //tell it we just updated header('Cache-Control: no-store, no-cache, must-revalidate'); //force revaidation header('Cache-Control: post-check=0, pre-check=0', false); header('Pragma: no-cache'); header('Content-Type: text/calendar; charset=utf-8'); header('Content-Disposition: attachment; filename="cal.ics"'); echo $vCalendar->render(); }
/** * Export the events diary to iCal. * @return Response */ public function export() { // Create the calendar $calendar = new Calendar('www.bts-crew.com'); $calendar->setName('Backstage Diary'); // Get all the events and add each time $events = Event::where('type', Event::TYPE_EVENT)->get(); foreach ($events as $event) { foreach ($event->times as $time) { $cal_event = new \Eluceo\iCal\Component\Event(); $cal_event->setDtStart($time->start)->setDtEnd($time->end)->setSummary($time->event->name . ' - ' . $time->name)->setLocation($time->event->venue); $calendar->addComponent($cal_event); } } // Respond return (new HttpResponse($calendar->render(), 200))->header('Content-Type', 'text/calendar; charset=utf-8')->header('Content-Disposition', 'attachment; filename="bts_diary.ics"'); }
public function calendar($user_id) { $user_id = Crypt::decrypt($user_id); $soc_ids = DB::table('subscriptions')->where('user_id', $user_id)->lists('society_id'); $events = Event::where('time', '>', date('Y-m-d H:i:s'))->whereIn('society_id', $soc_ids)->get(); $vCalendar = new \Eluceo\iCal\Component\Calendar('lowdown.netsoc.co'); foreach ($events as $event) { $vEvent = new \Eluceo\iCal\Component\Event(); $eventTime = new DateTime($event->time); $endTime = $eventTime; $endTime->add(new DateInterval('PT1H')); $eventSummary = $event->society()->first()->name . ' Society: ' . $event->title; $vEvent->setDtStart($eventTime)->setDtEnd($endTime)->setSummary($eventSummary); if ($event->location) { $vEvent->setLocation($event->location); } $vCalendar->addComponent($vEvent); } header('Content-Type: text/calendar; charset=utf-8'); header('Content-Disposition: attachment; filename="cal.ics"'); echo $vCalendar->render(); }
<?php // require files require_once '../src/Eluceo/iCal/Component.php'; require_once '../src/Eluceo/iCal/PropertyBag.php'; require_once '../src/Eluceo/iCal/Property.php'; require_once '../src/Eluceo/iCal/Component/Calendar.php'; require_once '../src/Eluceo/iCal/Component/Event.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-24')); $vEvent->setDtEnd(new \DateTime('2012-12-24')); $vEvent->setNoTime(true); $vEvent->setSummary('Christmas'); // Adding Timezone (optional) $vEvent->setUseTimezone(true); // 3. Add event to calendar $vCalendar->addEvent($vEvent); // 4. Set headers header('Content-Type: text/calendar; charset=utf-8'); header('Content-Disposition: attachment; filename="cal.ics"'); // 5. Output echo $vCalendar->render();
/** * */ public function exportIcalAction() { require_once Mage::getBaseDir() . '/lib/iCal/Eluceo/iCal/Component.php'; require_once Mage::getBaseDir() . '/lib/iCal/Eluceo/iCal/PropertyBag.php'; require_once Mage::getBaseDir() . '/lib/iCal/Eluceo/iCal/Property.php'; require_once Mage::getBaseDir() . '/lib/iCal/Eluceo/iCal/Component/Calendar.php'; require_once Mage::getBaseDir() . '/lib/iCal/Eluceo/iCal/Component/Event.php'; //date_default_timezone_set('Europe/Berlin'); $vCalendar = new \Eluceo\iCal\Component\Calendar(Mage::app()->getStore()->getName()); $coll = Mage::getModel('payperrentals/reservationorders')->getCollection()->groupByOrderId(); if (urldecode($this->getRequest()->getParam('store'))) { $coll->getSelect()->joinLeft(array('so' => Mage::getSingleton('core/resource')->getTableName('sales_flat_order')), 'main_table.order_id = ' . 'so.entity_id', array('so.store_id as store_id')); $coll->getSelect()->where('so.store_id=?', $this->getRequest()->getParam('store')); } foreach ($coll as $item) { $_order = Mage::getModel('sales/order')->load($item->getOrderId()); $_address = $_order->getShippingAddress(); $vEvent = new \Eluceo\iCal\Component\Event(); $vEvent->setDtStart(new \DateTime($item->getStartDate())); $vEvent->setDtEnd(new \DateTime($item->getEndDate())); $vEvent->setDescription($_order->getCustomerFirstname() . ' ' . $_order->getCustomerLastname()); $_addressString = ''; if ($_address instanceof Mage_Sales_Model_Order_Address) { $_addressString .= implode(' ', $_address->getStreet()) . ', ' . $_address->getPostcode() . ', ' . $_address->getCity(); } $vEvent->setLocation($_order->getCustomerFirstname() . ' ' . $_order->getCustomerLastname() . ($_addressString != '' ? ', ' . $_addressString : '')); //$vEvent->setNoTime(true); $vEvent->setSummary($item->getOrderId()); //$vEvent->setUseTimezone(true); $vCalendar->addEvent($vEvent); } header('Content-Type: text/calendar; charset=utf-8'); header('Content-Disposition: attachment; filename="cal.ics"'); echo $vCalendar->render(); }
/** * _getCalendarEvent * @param Cake\Entity $entity passed * @param array $options with extra settings * @return \Eluceo\iCal\Component\Event $vEvent */ protected function _getCalendarEvent($entity, $options = []) { $vEvent = new \Eluceo\iCal\Component\Event(); $vOrganizer = new \Eluceo\iCal\Property\Event\Organizer($options['organizer'], ['MAILTO' => $options['organizer']]); $vEvent->setOrganizer($vOrganizer); $vEvent->setSummary($options['subject']); if ($entity->description) { $vEvent->setDescription($entity->description); } $dates = $this->_getEventTime($entity, $options); $vEvent->setDtStart($dates['start']); $vEvent->setDtEnd($dates['end']); if ($entity->location) { $vEvent->setLocation($entity->location, "Location:"); } return $vEvent; }