/**
  * @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);
     }
 }
 /**
  * @param ICalendar &$calendar
  * @param callable $doesExist
  * @param boolean $isPublicUri
  */
 public static function generateURI(ICalendar &$calendar, \closure $doesExist, $isPublicUri = true)
 {
     if ($isPublicUri === true) {
         $uri = $calendar->getPublicUri();
     } else {
         $uri = $calendar->getPrivateUri();
     }
     if ($uri === null) {
         $uri = mb_strtolower($calendar->getDisplayname());
     }
     $uri = CalendarUtility::slugify($uri);
     while ($doesExist($uri)) {
         $newUri = self::suggestUri($uri);
         if ($newUri === $uri) {
             break;
         }
         $uri = $newUri;
     }
     if ($isPublicUri) {
         $calendar->setPublicUri($uri);
     } else {
         $calendar->setPrivateUri($uri);
     }
 }
 /**
  * Make sure either a publicUri or a displayname are set
  * @param \OCA\Calendar\ICalendar $calendar
  * @throws \OCA\Calendar\BusinessLayer\Exception
  */
 private function checkUriOrDisplaynameExists(ICalendar $calendar)
 {
     $displayname = $calendar->getDisplayname();
     if (($displayname === null || trim($displayname) === '') && $calendar->getPublicUri() === null) {
         throw new Exception('Please enter a calendar-name', Http::STATUS_UNPROCESSABLE_ENTITY);
     }
 }
 /**
  * @param ICalendar $n
  * @param ICalendar $o
  * @throws Exception
  */
 private function checkForIllegalChanges(ICalendar $n, ICalendar $o)
 {
     if ($n->getUserId() !== $o->getUserId()) {
         throw new Exception('Not allowed to transfer calendar to another user!');
     }
     if ($n->getBackend()->getId() !== $o->getBackend()->getId()) {
         throw new Exception('Not allowed to transfer calendar to another backend!');
     }
     if ($n->getPublicUri() !== $o->getPublicUri()) {
         if ($this->cache->doesExist($n->getPublicUri(), $n->getUserId())) {
             throw new Exception('New URI is already assigned to another calendar!');
         }
     }
 }