Пример #1
0
 /**
  * Creates a new calendar for a principal.
  *
  * If the creation was a success, an id must be returned that can be used to reference
  * this calendar in other methods, such as updateCalendar
  *
  * @param string $principalUri
  * @param string $calendarUri
  * @param array $properties
  * @return mixed
  */
 public function createCalendar($principalUri, $calendarUri, array $properties)
 {
     $values = array();
     // Default value
     $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set';
     if (!isset($properties[$sccs])) {
         $values[':components'] = 'VEVENT,VTODO';
     } else {
         if (!$properties[$sccs] instanceof \Sabre\CalDAV\Property\SupportedCalendarComponentSet) {
             throw new \Sabre\DAV\Exception('The ' . $sccs . ' property must be of type: Sabre_CalDAV_Property_SupportedCalendarComponentSet');
         }
         $values[':components'] = implode(',', $properties[$sccs]->getValue());
     }
     $transp = '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}schedule-calendar-transp';
     if (isset($properties[$transp])) {
         $values[':transparent'] = $properties[$transp]->getValue() === 'transparent';
     }
     foreach ($this->propertyMap as $xmlName => $dbName) {
         if (isset($properties[$xmlName])) {
             $values[$dbName] = $properties[$xmlName];
         }
     }
     if (!isset($values['displayname'])) {
         $values['displayname'] = 'unnamed';
     }
     $values['components'] = 'VEVENT,VTODO';
     if (!isset($values['timezone'])) {
         $values['timezone'] = null;
     }
     if (!isset($values['transparent'])) {
         $values['transparent'] = 0;
     }
     if (!isset($values['calendarorder'])) {
         $values['calendarorder'] = 0;
     }
     if (!isset($values['calendarcolor'])) {
         $values['calendarcolor'] = null;
     }
     if (!is_null($values['calendarcolor']) && strlen($values['calendarcolor']) == 9) {
         $values['calendarcolor'] = substr($values['calendarcolor'], 0, 7);
     }
     return CalendarCalendar::addCalendarFromDAVData($principalUri, $calendarUri, $values['displayname'], $values['components'], $values['timezone'], $values['calendarorder'], $values['calendarcolor'], $values['transparent']);
 }