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(); } }