Exemplo n.º 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)
 {
     $fieldNames = array('principaluri', 'uri', 'ctag');
     $values = array(':principaluri' => $principalUri, ':uri' => $calendarUri, ':ctag' => 1);
     // Default value
     $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set';
     $fieldNames[] = 'components';
     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());
     }
     foreach ($this->propertyMap as $xmlName => $dbName) {
         if (isset($properties[$xmlName])) {
             $myValue = $properties[$xmlName];
             $values[':' . $dbName] = $properties[$xmlName];
             $fieldNames[] = $dbName;
         }
     }
     if (!isset($newValues['displayname'])) {
         $newValues['displayname'] = 'unnamed';
     }
     if (!isset($newValues['components'])) {
         $newValues['components'] = 'VEVENT,VTODO';
     }
     if (!isset($newValues['timezone'])) {
         $newValues['timezone'] = null;
     }
     if (!isset($newValues['calendarorder'])) {
         $newValues['calendarorder'] = 0;
     }
     if (!isset($newValues['calendarcolor'])) {
         $newValues['calendarcolor'] = null;
     }
     if (!is_null($newValues['calendarcolor']) && strlen($newValues['calendarcolor']) == 9) {
         $newValues['calendarcolor'] = substr($newValues['calendarcolor'], 0, 7);
     }
     return OC_Calendar_Calendar::addCalendarFromDAVData($principalUri, $calendarUri, $newValues['displayname'], $newValues['components'], $newValues['timezone'], $newValues['calendarorder'], $newValues['calendarcolor']);
 }