Exemplo n.º 1
0
 public function indexAction(Request $request, $key)
 {
     $userManager = $this->container->get('ilioscore.user.manager');
     $user = $userManager->findUserBy(array('icsFeedKey' => $key));
     if (!$user) {
         throw new NotFoundHttpException();
     }
     $calendar = new ICS\Calendar('Ilios Calendar for ' . $user->getFirstAndLastName());
     $calendar->setPublishedTTL('P1H');
     $from = new \DateTime('-6 months');
     $to = new \DateTime('+6 months');
     $events = $userManager->findEventsForUser($user->getId(), $from, $to);
     foreach ($events as $event) {
         $vEvent = new ICS\Event();
         $vEvent->setDtStart($event->startDate)->setDtEnd($event->endDate)->setSummary($event->name)->setDescription($this->getDescriptionForEvent($event))->setCategories([$event->eventClass])->setLocation($event->location);
         $calendar->addComponent($vEvent);
     }
     $response = new Response();
     $response->setContent($calendar->render());
     $response->setCharset('utf-8');
     $response->headers->set('Content-Type', 'text/calendar');
     $response->headers->set('Content-Disposition', 'attachment; filename="' . $key . '.ics"');
     $response->prepare($request);
     $response->send();
 }
Exemplo n.º 2
0
 /**
  * @param string    $type
  * @param string    $name
  * @param string    $imageUrl
  *
  * @return \LolEspCal\Calendar
  */
 function create($type = 'all', $name = null, $imageUrl = null)
 {
     $iCalendar = new iCalendar('www.lolesports.com|' . $this->calendarName($this->getFullName($type, $name)));
     $iCalendar->setName($this->getReadableName($type, $name));
     $calendar = new Calendar();
     $calendar->setICalendar($iCalendar)->setType($type)->setName($name)->setFilename(str_replace(' ', '-', $this->calendarFilename($this->getFullName($type, $name))))->setImageUrl($imageUrl);
     return $calendar;
 }
Exemplo n.º 3
0
 /**
  * Transform results to all day iCal events
  *
  * @access public
  * @return FormatterInterface
  */
 public function addFullDayEvents()
 {
     foreach ($this->query->findAll() as $task) {
         $date = new DateTime();
         $date->setTimestamp($task[$this->startColumn]);
         $vEvent = $this->getTaskIcalEvent($task, 'task-#' . $task['id'] . '-' . $this->startColumn);
         $vEvent->setDtStart($date);
         $vEvent->setDtEnd($date);
         $vEvent->setNoTime(true);
         $this->vCalendar->addComponent($vEvent);
     }
     return $this;
 }
Exemplo n.º 4
0
 /**
  * Get project iCalendar
  *
  * @access public
  */
 public function project()
 {
     $token = $this->request->getStringParam('token');
     $project = $this->project->getByToken($token);
     // Token verification
     if (empty($project)) {
         $this->forbidden(true);
     }
     // Common filter
     $filter = $this->taskFilter->create()->filterByProject($project['id']);
     // Calendar properties
     $calendar = new iCalendar('Kanboard');
     $calendar->setName($project['name']);
     $calendar->setDescription($project['name']);
     $calendar->setPublishedTTL('PT1H');
     $this->renderCalendar($filter, $calendar);
 }
Exemplo n.º 5
0
 /**
  * Get project iCalendar
  *
  * @access public
  */
 public function project()
 {
     $token = $this->request->getStringParam('token');
     $project = $this->project->getByToken($token);
     // Token verification
     if (empty($project)) {
         throw AccessForbiddenException::getInstance()->withoutLayout();
     }
     // Common filter
     $queryBuilder = new QueryBuilder();
     $queryBuilder->withQuery($this->taskFinder->getICalQuery())->withFilter(new TaskStatusFilter(TaskModel::STATUS_OPEN))->withFilter(new TaskProjectFilter($project['id']));
     // Calendar properties
     $calendar = new iCalendar('Kanboard');
     $calendar->setName($project['name']);
     $calendar->setDescription($project['name']);
     $calendar->setPublishedTTL('PT1H');
     $this->renderCalendar($queryBuilder, $calendar);
 }
Exemplo n.º 6
0
 /**
  * Create iCalendar (.ics) file
  * @param bool $with_header
  * @return string
  */
 public function toICS($with_header = true)
 {
     $vCalendar = new Calendar('edt.u-bordeaux');
     $vCalendar->setTimezone(self::$timezone)->setName($this->name)->setDescription($this->name);
     /** @var EdtUbxItem $item */
     foreach ($this->items as $item) {
         $profs = implode(', ', $item->getProfs());
         $location = implode(', ', $item->getLocations());
         $groups = implode(', ', $item->getGroups());
         $vEvent = new Event();
         $vEvent->setUseTimezone(true)->setDtStart($item->getDtStart())->setDtEnd($item->getDtEnd())->setCategories($item->getCategory())->setLocation($location);
         $vEvent->setDescription(sprintf("%s\n%s%s%s%s%s", $item->getName(), $item->getCategory(), $location !== '' ? "\n{$location}" : '', $profs !== '' ? "\n{$profs}" : '', $groups !== '' ? "\n{$groups}" : '', $item->getNotes() ? "\nNotes: " . $item->getNotes() : ''));
         $vEvent->setSummary(sprintf('%s (%s)%s', $item->getName(), $item->getCategory(), $profs !== '' ? " - {$profs}" : ''));
         $vCalendar->addComponent($vEvent);
     }
     if ($with_header === true) {
         header('Content-type: text/calendar; charset=utf-8');
         header('Content-Disposition: attachment; filename=calendar.ics');
     }
     return $vCalendar->render();
 }
Exemplo n.º 7
0
 public function indexAction(Request $request, $key)
 {
     $manager = $this->container->get('ilioscore.user.manager');
     $user = $manager->findOneBy(array('icsFeedKey' => $key));
     if (!$user) {
         throw new NotFoundHttpException();
     }
     $calendar = new ICS\Calendar('Ilios Calendar for ' . $user->getFirstAndLastName());
     $calendar->setPublishedTTL('P1H');
     $from = new \DateTime(self::LOOK_BACK);
     $to = new \DateTime(self::LOOK_FORWARD);
     $events = $manager->findEventsForUser($user->getId(), $from, $to);
     $publishedEvents = array_filter($events, function (UserEvent $event) {
         return $event->isPublished && !$event->isScheduled;
     });
     $publishedEvents = $manager->addInstructorsToEvents($publishedEvents);
     $scheduledEvents = array_filter($events, function (UserEvent $event) {
         return $event->isPublished && $event->isScheduled;
     });
     /* @var UserEvent $event */
     foreach ($publishedEvents as $event) {
         $vEvent = new ICS\Event();
         $vEvent->setDtStart($event->startDate)->setDtEnd($event->endDate)->setSummary($event->name)->setDescription($this->getDescriptionForEvent($event))->setCategories([$event->eventClass])->setLocation($event->location);
         $calendar->addComponent($vEvent);
     }
     foreach ($scheduledEvents as $event) {
         $vEvent = new ICS\Event();
         $vEvent->setDtStart($event->startDate)->setDtEnd($event->endDate)->setSummary('Scheduled');
         $calendar->addComponent($vEvent);
     }
     $response = new Response();
     $response->setContent($calendar->render());
     $response->setCharset('utf-8');
     $response->headers->set('Content-Type', 'text/calendar');
     $response->headers->set('Content-Disposition', 'attachment; filename="' . $key . '.ics"');
     $response->prepare($request);
     return $response;
 }
Exemplo n.º 8
0
 /**
  * Transform results to all day ical events
  *
  * @access public
  * @param  string       $column        Column name for the date
  * @param  Calendar     $vCalendar     Calendar object
  * @return Calendar
  */
 public function addAllDayIcalEvents($column = 'date_due', Calendar $vCalendar = null)
 {
     if ($vCalendar === null) {
         $vCalendar = new Calendar('Kanboard');
     }
     foreach ($this->query->findAll() as $task) {
         $date = new DateTime();
         $date->setTimestamp($task[$column]);
         $vEvent = $this->getTaskIcalEvent($task, 'task-#' . $task['id'] . '-' . $column);
         $vEvent->setDtStart($date);
         $vEvent->setDtEnd($date);
         $vEvent->setNoTime(true);
         $vCalendar->addComponent($vEvent);
     }
     return $vCalendar;
 }
Exemplo n.º 9
0
 /**
  * Generates and returns an iCal file for a ticket.
  * @param  String $code  Code of a ticket in the system.
  * @return .ics file     iCal file representing that ticket.
  */
 public function iCal($code)
 {
     $vCalendar = new Calendar($_SERVER["HTTP_HOST"]);
     try {
         $ticket = Ticket::hasCode($code)->firstOrFail();
     } catch (ModelNotFoundException $e) {
         return view("tickets.unverifiable", ['error' => $this->errorMessages['ticket_invalid']]);
     }
     $event = $ticket->event;
     // Have to call Event this way to avoid clash with App\Event
     $vEvent = new iCal\Component\Event();
     $breakAddress = explode(",", $event->location->name, 2);
     $firstName = $breakAddress[0];
     $vEvent->setDtStart(new DateTime($event->start_datetime))->setDtEnd(new DateTime($event->end_datetime))->setLocation($event->location->name, $firstName, "{$event->location->latitude}, {$event->location->longitude}")->setSummary($event->title);
     $vCalendar->addComponent($vEvent);
     header('Content-Type: text/calendar; charset=utf-8');
     header('Content-Disposition: attachment; filename="cal.ics"');
     echo $vCalendar->render();
 }
Exemplo n.º 10
0
 public function __toString()
 {
     try {
         return parent::__toString();
     } catch (\Exception $ex) {
         $message = $ex->getMessage();
         if ($this->options['output']['errors']) {
             return $message;
         } else {
             trigger_error($message, E_USER_ERROR);
             return '';
         }
     }
 }
Exemplo n.º 11
0
<?php

/**
 * Export iCalendar feed with Captain Train trips
 *
 * PHP version 5.6
 *
 * @category CaptainTrainIcalendar
 * @package  CaptainTrainIcalendar
 * @author   Pierre Rudloff <*****@*****.**>
 * @license  GPL https://www.gnu.org/licenses/gpl.html
 * @link     https://github.com/Rudloff/captaintrain-icalendar
 */
require_once 'vendor/autoload.php';
use CaptainTrainIcalendar\Config;
use Eluceo\iCal\Component\Calendar;
use Eluceo\iCal\Component\Event;
$config = Config::getInstance();
if (isset($_GET['token']) && $_GET['token'] == $config->token) {
    $session = new \CaptainTrain\Session($config->email, $config->password);
    $vCalendar = new Calendar('captaintrain-icalendar');
    foreach ($session->getTrips() as $trip) {
        $vEvent = new Event();
        $vEvent->setDtStart($trip->departureDate)->setDtEnd($trip->arrivalDate)->setSummary($trip->departureStation->name . ' - ' . $trip->arrivalStation->name)->setUseTimezone(true)->setUrl('https://www.captaintrain.com/tickets');
        $vCalendar->addComponent($vEvent);
    }
    header('Content-Type: text/calendar');
    echo $vCalendar->render();
} else {
    http_response_code(403);
}
Exemplo n.º 12
0
 /**
  * Returns an array with all instances of a recurring event. If an event was detached it's not part of the series' instances.
  *
  * todo: Refactor - combining eluceo/ical and sabre/vobject this way seems very expensive.
  * @param Event $event
  * @param \DateTime|null $dateFrom
  * @param \DateTime|null $dateTo
  *
  * @return Event[]
  *
  * @throws \Exception
  */
 public function getInstances(Event $event, \DateTime $dateFrom = null, \DateTime $dateTo = null, $findOnlyOne = false)
 {
     $eventInstances = array();
     // this is necessary for using nthOccurrence, otherwise the maximum recurrence entities will result in an error
     // todo: Refactor - solve recurrence count for nthOccurrence
     VObject\Settings::$maxRecurrences = -1;
     if (!$event->getRecurrenceRule()) {
         return array($event);
     }
     $dateFrom = $dateFrom ? $dateFrom : $event->getDtStart();
     if (!$dateFrom) {
         return $eventInstances;
     }
     if (!$dateTo) {
         //default to one year if no end is set
         $dateTo = clone $event->getDtStart();
         $dateTo->add(new \DateInterval('P10Y'));
     }
     if (!$dateFrom || !$dateTo) {
         throw new \Exception('Trying to get instances of a recurring event without dateFrom and/or dateTo being set.');
     }
     //create the calendar
     $vCalendar = new Calendar($event->getUniqueId());
     if (self::isValidDateTime($event->getDtStart()) && self::isValidDateTime($event->getDtEnd())) {
         $vCalendar->addComponent($event);
     }
     //get edited events: depending on $includeEditedEvents to mark these events as deleted or to replace them by their edited event
     $editedEventsByTimestamp = array();
     $qb = $this->em->createQueryBuilder();
     $qb->select('e')->from('Xima\\ICalBundle\\Entity\\Component\\Event', 'e')->where('e.uniqueId = :uniqueId')->andWhere($qb->expr()->isNotNull('e.recurrenceId'))->setParameter('uniqueId', $event->getUniqueId());
     $editedEvents = $qb->getQuery()->getResult();
     foreach ($editedEvents as $editedEvent) {
         /* @var $editedEvent \Xima\ICalBundle\Entity\Component\Event */
         if (self::isValidDateTime($editedEvent->getDtStart()) && self::isValidDateTime($editedEvent->getDtEnd()) && self::isValidDateTime($editedEvent->getRecurrenceId()->getDatetime())) {
             $editedEventsByTimestamp[$editedEvent->getDtStart()->getTimestamp()] = $editedEvent;
             $vCalendar->addComponent($editedEvent);
         }
     }
     //render the calendar and parse it to get all recurrences of the event
     $vCalendarExpandedData = $vCalendar->render();
     $vCalendarExpanded = VObject\Reader::read($vCalendarExpandedData);
     /* @var $vCalendarExpanded \Sabre\VObject\Component\VCalendar */
     $vCalendarExpanded = $vCalendarExpanded->expand($dateFrom, $dateTo);
     foreach ($vCalendarExpanded->getComponents() as $instanceComp) {
         /* @var $instanceComp \Sabre\VObject\Component\VEvent */
         // It's basically the same event, but with the new calculated dates and times...
         // @todo: refactor so that dtStart is set when dateFrom gets set and so on...
         $dtStart = new \DateTime();
         $dtStart->setTimestamp($instanceComp->DTSTART->getDateTime()->getTimestamp());
         $dtEnd = new \DateTime();
         $dtEnd->setTimestamp($instanceComp->DTEND->getDateTime()->getTimestamp());
         $eventInstance = clone $event;
         /* @var $eventInstance Event */
         $eventInstance->setDtStart($dtStart);
         $eventInstance->setDateFrom($dtStart);
         $eventInstance->setTimeFrom($dtStart);
         $eventInstance->setDtEnd($dtEnd);
         $eventInstance->setDateTo($dtEnd);
         $eventInstance->setTimeTo($dtEnd);
         if ($findOnlyOne) {
             return array($eventInstance);
         }
         if (isset($editedEventsByTimestamp[$instanceComp->DTSTART->getDateTime()->getTimestamp()])) {
             // if the instance was detached, it's not part of the series' instances
             continue;
         } else {
             $eventInstances[] = $eventInstance;
         }
     }
     return $eventInstances;
 }
 /**
  *
  *
  */
 public function icsAction()
 {
     $calendarService = $this->getCalendarService()->setCalendarId($this->getEvent()->getRouteMatch()->getParam('id'));
     if ($calendarService->isEmpty()) {
         return $this->notFoundAction();
     }
     $vCalendar = new iCal('https://artemis-ia.eu');
     $vEvent = new iCalEvent();
     $vEvent->setDtStart($calendarService->getCalendar()->getDateFrom())->setDtEnd($calendarService->getCalendar()->getDateEnd())->setLocation($calendarService->getCalendar()->getLocation())->setNoTime(true)->setSummary($calendarService->getCalendar()->getCalendar())->setDescription(strip_tags($calendarService->getCalendar()->getDescription()));
     $vCalendar->addComponent($vEvent);
     $response = $this->getResponse();
     $response->getHeaders()->addHeaderLine('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 36000))->addHeaderLine("Cache-Control: max-age=36000, must-revalidate")->addHeaderLine("Pragma: public")->addHeaderLine('Content-Disposition: attachment; filename="' . $calendarService->getCalendar()->getCalendar() . '.ics"')->addHeaderLine('Content-Type: text/calendar; charset=utf-8')->addHeaderLine('Content-Length', strlen($vCalendar->render()));
     $response->setContent($vCalendar->render());
     return $response;
 }
Exemplo n.º 14
0
 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();
 }
 public function ExportEventToICS(SS_HTTPRequest $request)
 {
     try {
         $event_ids = $request->getVar('events_id');
         if (is_null($event_ids)) {
             return $this->validationError("missing events_id param");
         }
         $event_ids = explode(',', $event_ids);
         // https://www.ietf.org/rfc/rfc2445.txt
         $vCalendar = new Calendar('www.openstack.org');
         foreach ($event_ids as $event_id) {
             $event = $this->summitevent_repository->getById($event_id);
             if (is_null($event)) {
                 throw new NotFoundEntityException('SummitEvent', sprintf(' id %s', $event_id));
             }
             if (!$event->isPublished()) {
                 throw new EntityValidationException(sprintf("event id %s does not belongs to schedule!", $event->getIdentifier()));
             }
             $vEvent = new \Eluceo\iCal\Component\Event(md5(uniqid(mt_rand(), true)) . "event");
             $vEvent->setCreated(new \DateTime())->setDtStart(new \DateTime($event->getStartDateUTC()))->setDtEnd(new \DateTime($event->getEndDateUTC()))->setNoTime(false)->setSummary($event->Title)->setDescription(strip_tags($event->ShortDescription))->setDescriptionHTML($event->ShortDescription);
             if ($location = $event->getLocation()) {
                 $venue = $location;
                 $geo = null;
                 if ($location->getTypeName() == SummitVenueRoom::TypeName) {
                     $venue = $location->getVenue();
                 }
                 if (is_a($venue, 'SummitGeoLocatedLocation')) {
                     $geo = sprintf("%s;%s", $venue->getLat(), $venue->getLng());
                 }
                 $vEvent->setLocation($location->getFullName(), $location->getFullName(), $geo);
             }
             $vCalendar->addComponent($vEvent);
         }
         $response = new SS_HTTPResponse($vCalendar->render(), 200);
         $response->addHeader("Content-type", "text/calendar; charset=utf-8");
         $response->addHeader("Content-Disposition", "inline; filename=event-" . implode('-', $event_ids) . ".ics");
         return $response;
     } catch (EntityValidationException $ex1) {
         SS_Log::log($ex1, SS_Log::WARN);
         return $this->validationError($ex1->getMessages());
     } catch (NotFoundEntityException $ex2) {
         SS_Log::log($ex2, SS_Log::WARN);
         return $this->notFound($ex2->getMessage());
     } catch (Exception $ex) {
         SS_Log::log($ex, SS_Log::ERR);
         return $this->serverError();
     }
 }
 /**
  * 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"');
 }