Пример #1
0
 /**
  * find a timezone
  *
  * @param string $tzId
  * @param string $userId
  * @throws Exception
  * @return \OCA\Calendar\ITimezone
  */
 public function find($tzId, $userId)
 {
     try {
         return $this->mapper->find($tzId, $userId);
     } catch (DoesNotExistException $ex) {
         throw Exception::fromException($ex);
     } catch (MultipleObjectsReturnedException $ex) {
         throw Exception::fromException($ex);
     }
 }
 /**
  * @param mixed $data
  * @param int $format
  * @return \OCA\Calendar\Db\Calendar
  * @throws CorruptDataException
  * @throws TemporarilyNotAvailableException
  * @throws \InvalidArgumentException
  */
 public function createEntity($data, $format = self::FORMAT_PARAM)
 {
     if (!is_array($data) || empty($data)) {
         throw new CorruptDataException('CalendarFactory::createEntity() - Calendardata is empty');
     }
     if (isset($data['backend'])) {
         if ($data['backend'] instanceof IBackend) {
             if (!$this->backends->inCollection($data['backend'])) {
                 unset($data['backend']);
             }
         } else {
             $backend = $this->backends->find($data['backend']);
             if (!$backend instanceof IBackend) {
                 throw new TemporarilyNotAvailableException('CalendarFactory::createEntity() - Calendardata references unknown backend');
             }
             //replace backend-identifier with IBackend instance
             $data['backend'] = $backend;
         }
     }
     //replace timezone-identifier with ITimezone instance
     if (isset($data['timezone']) && isset($data['user_id'])) {
         try {
             $timezone = $this->timezones->find($data['timezone'], $data['user_id']);
             $row['timezone'] = $timezone;
         } catch (DoesNotExistException $ex) {
             unset($data['timezone']);
         }
     }
     //TODO - fix me
     unset($data['last_properties_update']);
     unset($data['last_object_update']);
     switch ($format) {
         case self::FORMAT_PARAM:
             return Calendar::fromParams($data);
             break;
         case self::FORMAT_ROW:
             return Calendar::fromRow($data);
             break;
         default:
             throw new \InvalidArgumentException('CalendarFactory::createEntity() - Unknown format given');
             break;
     }
 }
 /**
  * add missing timezones from VCalendar
  * @param Component\VCalendar &$vcalendar
  * @param TimezoneMapper $tzMapper
  */
 public static function addMissingVTimezones(Component\VCalendar &$vcalendar, TimezoneMapper $tzMapper)
 {
     $tzIds = self::parseComponentForTzIds($vcalendar);
     $tzIdsInVCalendar = [];
     foreach ($vcalendar->select('VTIMEZONE') as $vtimezone) {
         $tzIdsInVCalendar[] = $vtimezone->{'TZID'}->getValue();
     }
     $missingTzIds = array_diff($tzIds, $tzIdsInVCalendar);
     foreach ($missingTzIds as $tzId) {
         try {
             $timezonesVCalendar = $tzMapper->find($tzId, null)->getVObject();
             $vcalendar->add($timezonesVCalendar->{'VTIMEZONE'});
         } catch (DoesNotExistException $ex) {
             continue;
         }
     }
 }