/**
  * @param ICalendar $calendar
  * @param \OCA\Calendar\IObject|\OCA\Calendar\IObjectCollection $data
  * @param TimezoneMapper $timezones
  */
 public function __construct(ICalendar $calendar, $data, TimezoneMapper $timezones)
 {
     $vobject = $data->getVObject();
     if ($vobject) {
         if ($timezones) {
             SabreUtility::addMissingVTimezones($vobject, $timezones);
         }
         $serialized = $vobject->serialize();
         $contentType = 'application/octet-stream';
         $filename = $calendar->getPublicUri();
         if ($data instanceof IObject) {
             $filename .= '-' . $data->getSummary();
         }
         $filename .= '.ics';
         parent::__construct($serialized, $filename, $contentType);
     }
 }
 /**
  *@PublicPage
  * @NoCSRFRequired
  * 
  */
 public function exportEvents()
 {
     $token = $this->params('t');
     $calid = null;
     $eventid = null;
     if (isset($token)) {
         $linkItem = \OCP\Share::getShareByToken($token, false);
         if (is_array($linkItem) && isset($linkItem['uid_owner']) && !isset($linkItem['share_with'])) {
             $rootLinkItem = \OCP\Share::resolveReShare($linkItem);
             if (isset($rootLinkItem['uid_owner'])) {
                 \OCP\JSON::checkUserExists($rootLinkItem['uid_owner']);
                 if ($linkItem['item_type'] === CalendarApp::SHARECALENDAR) {
                     $sPrefix = CalendarApp::SHARECALENDARPREFIX;
                 }
                 if ($linkItem['item_type'] === CalendarApp::SHAREEVENT) {
                     $sPrefix = CalendarApp::SHAREEVENTPREFIX;
                 }
                 if ($linkItem['item_type'] === CalendarApp::SHARETODO) {
                     $sPrefix = CalendarApp::SHARETODOPREFIX;
                 }
                 $itemSource = CalendarApp::validateItemSource($linkItem['item_source'], $sPrefix);
                 if ($linkItem['item_type'] === CalendarApp::SHARECALENDAR) {
                     $calid = $itemSource;
                 }
                 if ($linkItem['item_type'] === CalendarApp::SHAREEVENT || $linkItem['item_type'] === CalendarApp::SHARETODO) {
                     $eventid = $itemSource;
                 }
             }
         }
     } else {
         if (\OCP\User::isLoggedIn()) {
             $calid = $this->params('calid');
             $eventid = $this->params('eventid');
         }
     }
     if (!is_null($calid)) {
         //check shared calendar also
         $calendar = CalendarApp::getCalendar($calid, true, true);
         if (!$calendar) {
             $params = ['status' => 'error'];
             $response = new JSONResponse($params);
             return $response;
         }
         $name = str_replace(' ', '_', $calendar['displayname']) . '.ics';
         $calendarEvents = Export::export($calid, Export::CALENDAR);
         $response = new DataDownloadResponse($calendarEvents, $name, 'text/calendar');
         $response->addHeader('last-modified', $calendar['lastmodifieddate']);
         return $response;
     }
     if (!is_null($eventid)) {
         $data = CalendarApp::getEventObject($eventid, false);
         if (!$data) {
             $params = ['status' => 'error'];
             $response = new JSONResponse($params);
             return $response;
         }
         $name = str_replace(' ', '_', $data['summary']) . '.ics';
         $singleEvent = Export::export($eventid, Export::EVENT);
         $response = new DataDownloadResponse($singleEvent, $name, 'text/calendar');
         return $response;
     }
 }