/**
  * convert Tinebase_Record_RecordSet to Sabre\VObject\Component
  *
  * @param  Tinebase_Record_RecordSet  $_records
  * @return Sabre\VObject\Component
  */
 public function fromTine20RecordSet(Tinebase_Record_RecordSet $_records)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Events: ' . print_r($_records->toArray(), true));
     }
     // required vcalendar fields
     $version = Tinebase_Application::getInstance()->getApplicationByName('Calendar')->version;
     $vcalendar = new \Sabre\VObject\Component\VCalendar(array('PRODID' => "-//tine20.com//Tine 2.0 Calendar V{$version}//EN", 'VERSION' => '2.0', 'CALSCALE' => 'GREGORIAN'));
     if (isset($this->_method)) {
         $vcalendar->add('METHOD', $this->_method);
     }
     $originatorTz = $_records->getFirstRecord() ? $_records->getFirstRecord()->originator_tz : NULL;
     if (empty($originatorTz)) {
         throw new Tinebase_Exception_Record_Validation('originator_tz needed for conversion to Sabre\\VObject\\Component');
     }
     try {
         $vcalendar->add(new Sabre_VObject_Component_VTimezone($originatorTz));
     } catch (Exception $e) {
         Tinebase_Exception::log($e);
         throw new Tinebase_Exception_Record_Validation('Bad Timezone: ' . $originatorTz);
     }
     foreach ($_records as $_record) {
         $this->_convertCalendarModelEvent($vcalendar, $_record);
         if ($_record->exdate instanceof Tinebase_Record_RecordSet) {
             $_record->exdate->addIndices(array('is_deleted'));
             $eventExceptions = $_record->exdate->filter('is_deleted', false);
             foreach ($eventExceptions as $eventException) {
                 $this->_convertCalendarModelEvent($vcalendar, $eventException, $_record);
             }
         }
     }
     $this->_afterFromTine20Model($vcalendar);
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' card ' . $vcalendar->serialize());
     }
     return $vcalendar;
 }
示例#2
0
文件: helper.php 项目: sbambach/tasks
 public static function createVCalendarFromRequest($request)
 {
     $vcalendar = new \Sabre\VObject\Component\VCalendar();
     $vcalendar->PRODID = 'ownCloud Calendar';
     $vcalendar->VERSION = '2.0';
     $vtodo = $vcalendar->createComponent('VTODO');
     $vcalendar->add($vtodo);
     $vtodo->CREATED = new \DateTime('now', new \DateTimeZone('UTC'));
     $vtodo->UID = \Sabre\VObject\UUIDUtil::getUUID();
     return self::updateVCalendarFromRequest($request, $vcalendar);
 }
示例#3
0
 /**
  * @dataProvider values
  */
 function testGetNormalizedValue($expected, $input)
 {
     $vobj = new \Sabre\VObject\Component\VCalendar();
     $property = $vobj->add('ATTENDEE', $input);
     $this->assertEquals($expected, $property->getNormalizedValue());
 }
示例#4
0
<?php

/**
 * @var Termin[] $alle_termine
 */
Header("Content-Type: text/calendar");
$vcalendar = new \Sabre\VObject\Component\VCalendar();
foreach ($alle_termine as $curr_termin) {
    $vcalendar->add('VEVENT', $curr_termin->getVEventParams());
}
echo $vcalendar->serialize();
示例#5
0
 /**
  * Generate an event to show in the calendar
  *
  * @return \Sabre\VObject\Component\VCalendar|null
  */
 public function getBirthdayEvent()
 {
     if (!isset($this->BDAY)) {
         return null;
     }
     $birthday = $this->BDAY;
     if ((string) $birthday) {
         $title = str_replace('{name}', strtr((string) $this->FN, array('\\,' => ',', '\\;' => ';')), App::$l10n->t('{name}\'s Birthday'));
         try {
             $date = new \DateTime($birthday);
         } catch (Exception $e) {
             return null;
         }
         $vCal = new \Sabre\VObject\Component\VCalendar();
         $vCal->VERSION = '2.0';
         $vEvent = $vCal->createComponent('VEVENT');
         $vEvent->add('DTSTART');
         $vEvent->DTSTART->setDateTime($date);
         $vEvent->DTSTART['VALUE'] = 'DATE';
         $vEvent->add('DTEND');
         $date->add(new \DateInterval('P1D'));
         $vEvent->DTEND->setDateTime($date);
         $vEvent->DTEND['VALUE'] = 'DATE';
         $lm = new \DateTime('@' . $this->lastModified());
         $lm->setTimeZone(new \DateTimeZone('UTC'));
         $vEvent->DTSTAMP->setDateTime($lm);
         $vEvent->{'UID'} = $this->UID;
         $vEvent->{'RRULE'} = 'FREQ=YEARLY';
         $vEvent->{'SUMMARY'} = $title . ' (' . $date->format('Y') . ')';
         $vEvent->{'TRANSP'} = 'TRANSPARENT';
         $alarm = $vCal->createComponent('VALARM');
         $alarm->{'TRIGGER'} = '-PT0H';
         $alarm->add($vCal->createProperty('TRIGGER', '-PT0M', ['VALUE' => 'DURATION']));
         $alarm->add($vCal->createProperty('DESCRIPTION', $title . ' (' . $date->format('Y') . ')'));
         $vEvent->add($alarm);
         $appInfo = \OCP\App::getAppInfo('contacts');
         $appVersion = \OCP\App::getAppVersion('contacts');
         $vCal->PRODID = '-//ownCloud//NONSGML ' . $appInfo['name'] . ' ' . $appVersion . '//EN';
         $vCal->add($vEvent);
         return $vCal;
     }
     return null;
 }
 /**
  * generate VTimezone for given folder
  * 
  * @param  string|Tinebase_Model_Application  $applicationName
  * @return string
  */
 public static function getCalendarVTimezone($applicationName)
 {
     $timezone = Tinebase_Core::getPreference()->getValueForUser(Tinebase_Preference::TIMEZONE, Tinebase_Core::getUser()->getId());
     $application = $applicationName instanceof Tinebase_Model_Application ? $applicationName : Tinebase_Application::getInstance()->getApplicationByName($applicationName);
     // create vcalendar object with timezone information
     $vcalendar = new \Sabre\VObject\Component\VCalendar(array('PRODID' => "-//tine20.org//Tine 2.0 {$application->name} V{$application->version}//EN", 'VERSION' => '2.0', 'CALSCALE' => 'GREGORIAN'));
     $vcalendar->add(new Sabre_VObject_Component_VTimezone($timezone));
     // Taking out \r to not screw up the xml output
     return str_replace("\r", "", $vcalendar->serialize());
 }
示例#7
0
 public function createCalendar()
 {
     $record = $this->record;
     $this->log->debug(__CLASS__ . '::' . __METHOD__ . ' | Start CRM ID:' . $record['crmid']);
     $calType = $record['activitytype'] == 'Task' ? 'VTODO' : 'VEVENT';
     $endField = $this->getEndFieldName($calType);
     $vcalendar = new Sabre\VObject\Component\VCalendar();
     $vcalendar->PRODID = '-//' . self::PRODID . ' V' . vglobal('YetiForce_current_version') . '//';
     $start = $record['date_start'] . ' ' . $record['time_start'];
     $end = $record['due_date'] . ' ' . $record['time_end'];
     if ($record['allday']) {
         $startDT = new \DateTime($start);
         $DTSTART = $vcalendar->createProperty('DTSTART', $startDT);
         $endDT = new DateTime($end);
         $endDT->modify('+1 day');
         $DTEND = $vcalendar->createProperty($endField, $endDT);
         $DTEND['VALUE'] = 'DATE';
         $DTSTART['VALUE'] = 'DATE';
     } else {
         $startDT = $DTSTART = new \DateTime($start);
         $endDT = $DTEND = new \DateTime($end);
     }
     $cal = $vcalendar->createComponent($calType);
     //$cal->add($vcalendar->createProperty('CREATED', new \DateTime($record['createdtime'])));
     //$cal->add($vcalendar->createProperty('LAST-MODIFIED', new \DateTime($record['modifiedtime'])));
     $cal->add($vcalendar->createProperty('SUMMARY', $record['subject']));
     $cal->add($vcalendar->createProperty('DTSTART', $DTSTART));
     $cal->add($vcalendar->createProperty($endField, $DTEND));
     $cal->add($vcalendar->createProperty('CLASS', $record['visibility'] == 'Private' ? 'PRIVATE' : 'PUBLIC'));
     $cal->add($vcalendar->createProperty('PRIORITY', $this->getPriority($record['priority'], false)));
     $status = $this->getStatus($record['status'], false);
     if ($status) {
         $cal->add($vcalendar->createProperty('STATUS', $status, false));
     }
     $state = $this->getState($record['state'], false);
     if ($state) {
         $cal->add($vcalendar->createProperty('TRANSP', $state, false));
     }
     if (!empty($record['location'])) {
         $cal->add($vcalendar->createProperty('LOCATION', $record['location']));
     }
     if (!empty($record['description'])) {
         $cal->add($vcalendar->createProperty('DESCRIPTION', $record['description']));
     }
     $vcalendar->add($cal);
     $dtz = date_default_timezone_get();
     $vTimeZone = self::getVTimeZone($vcalendar, $dtz, $startDT->getTimestamp(), $endDT->getTimestamp());
     $vcalendar->add($vTimeZone);
     $calendarData = $vcalendar->serialize();
     $modifiedtime = strtotime($record['modifiedtime']);
     $extraData = $this->getDenormalizedData($calendarData);
     $calUri = date('Y-m-d\\THis') . '-' . $record['crmid'];
     $stmt = $this->pdo->prepare('INSERT INTO dav_calendarobjects (calendarid, uri, calendardata, lastmodified, etag, size, componenttype, firstoccurence, lastoccurence, uid, crmid) VALUES (?,?,?,?,?,?,?,?,?,?,?)');
     $stmt->execute([$this->calendarId, $calUri . '.ics', $calendarData, $modifiedtime, $extraData['etag'], $extraData['size'], $extraData['componentType'], $extraData['firstOccurence'], $extraData['lastOccurence'], $calUri, $record['crmid']]);
     $this->addChange($calUri, 1);
     $this->log->debug(__CLASS__ . '::' . __METHOD__ . ' | End');
 }
示例#8
0
 /**
  * @brief creates an VCalendar Object from the request data
  * @param array $request
  * @return object created $vcalendar
  */
 public static function createVCalendarFromRequest($request)
 {
     $vcalendar = new \Sabre\VObject\Component\VCalendar();
     $vcalendar->PRODID = 'ownCloud Calendar';
     $vcalendar->VERSION = '2.0';
     $vevent = $vcalendar->createComponent('VEVENT');
     $vcalendar->add($vevent);
     $now = new DateTime('now');
     $now->setTimeZone(new \DateTimeZone('UTC'));
     $vevent->CREATED = $now;
     $uid = substr(md5(rand() . time()), 0, 10);
     $vevent->UID = $uid;
     return self::updateVCalendarFromRequest($request, $vcalendar);
 }
示例#9
0
 /**
  * Generate an event to show in the calendar
  *
  * @return \Sabre\VObject\Component\VCalendar|null
  */
 public function getBirthdayEvent()
 {
     if (!isset($this->BDAY)) {
         return null;
     }
     $birthday = $this->BDAY;
     if ((string) $birthday) {
         $title = str_replace('{name}', strtr((string) $this->FN, array('\\,' => ',', '\\;' => ';')), App::$l10n->t('{name}\'s Birthday'));
         try {
             $date = new \DateTime($birthday);
         } catch (Exception $e) {
             return null;
         }
         $vCal = new \Sabre\VObject\Component\VCalendar();
         $vCal->VERSION = '2.0';
         $vEvent = $vCal->createComponent('VEVENT');
         $vEvent->add('DTSTART');
         $vEvent->DTSTART->setDateTime($date);
         $vEvent->DTSTART['VALUE'] = 'date';
         $vEvent->add('DURATION', 'P1D');
         $vEvent->{'UID'} = $this->UID;
         $vEvent->{'RRULE'} = 'FREQ=YEARLY';
         $vEvent->{'SUMMARY'} = $title . ' (' . $date->format('Y') . ')';
         $vEvent->{'TRANSP'} = 'TRANSPARENT';
         $appInfo = \OCP\App::getAppInfo('contacts');
         $appVersion = \OCP\App::getAppVersion('contacts');
         $vCal->PRODID = '-//ownCloud//NONSGML ' . $appInfo['name'] . ' ' . $appVersion . '//EN';
         $vCal->add($vEvent);
         return $vCal;
     }
     return null;
 }
示例#10
0
文件: SabreMW.php 项目: etxea/sabremw
 public function addEvent($calendar, $titulo, $descripcion, $fecha)
 {
     //FIXME esto debería ser una variable
     $location = "Uroges Cruces";
     echo "Vamos a crear {$calendar},{$titulo},{$descripcion},{$fecha} ";
     $uid = strtoupper(\Rhumsaa\Uuid\Uuid::uuid4());
     $inicio = new \DateTime($fecha);
     $inicio = "VALUE=DATE:" . $fecha;
     //$inicio = $inicio->setTimezone(new DateTimezone("europe/madrid"));
     $now = new DateTime("now");
     //$now = $now->setTimezone(new DateTimezone("europe/madrid"));
     $vcalendar = new \Sabre\VObject\Component\VCalendar();
     $event = $vcalendar->add('VEVENT', ['CREATED' => $now, 'UID' => $uid, 'SUMMARY' => $titulo, 'DESCRIPTION' => $descripcion, 'DTSTART' => $fecha, 'DTSTAMP' => $now, 'LAST-MODIFIED' => $now, 'TRANSP' => "TRANSPARENT", 'SEQUENCE' => 0]);
     //$vcalendar->add($event);
     $etag = md5($vcalendar->serialize());
     $startdate = $event->DTSTART->getDateTime()->getTimeStamp();
     $enddate = $startdate;
     $size = strlen($vcalendar->serialize());
     //echo "Tenemos el vclandera:<pre>";
     //echo $vcalendar->serialize();
     //echo "</pre>";
     //echo "Vamos a introducir en BBDD el etag $etag el size $size y el tiempo $startdate";
     $ret = $this->db->insert('oc_clndr_objects', array('calendardata' => $vcalendar->serialize(), 'uri' => $uid . ".ics", 'calendarid' => $calendar, 'startdate' => $startdate, 'enddate' => $enddate, 'lastmodified' => $now->getTimestamp()));
     $id = $this->db->lastInsertId();
     //Actualizamos el ctag del calendario
     $this->updateSyncToken($calendar);
     //echo "Insercion hecha con ID: ".$id;
     //echo "Vamos a introducir en BBDD el etag $etag el size $size y el tiempo $startdate";
     return $id;
 }
 /**
  * convert calendar event to \Sabre\VObject\Component
  * 
  * @param Tasks_Model_Task $_vtodo
  * @param Tasks_Model_Task $mainTask
  * @return \Sabre\VObject\Component
  */
 protected function _convertTasksModelTask(Sabre\VObject\Component\VCalendar $vcalendar, Tasks_Model_Task $task, Tasks_Model_Task $mainTask = null)
 {
     // clone the event and change the timezone
     $task = clone $task;
     if (!empty($task->originator_tz)) {
         $task->setTimezone($task->originator_tz);
     }
     $vtodo = $vcalendar->create('VTODO');
     $vtodo->add('CREATED', $task->creation_time->getClone()->setTimezone('UTC'));
     $lastModifiedDateTime = $task->last_modified_time ? $task->last_modified_time : $task->creation_time;
     $vtodo->add('LAST-MODIFIED', $lastModifiedDateTime->getClone()->setTimezone('UTC'));
     $vtodo->add('DTSTAMP', Tinebase_DateTime::now());
     $vtodo->add('UID', $task->uid);
     $vtodo->add('SEQUENCE', !empty($task->seq) ? $task->seq : 1);
     if (isset($task->dtstart)) {
         $vtodo->add('DTSTART', $task->dtstart);
     }
     if (isset($task->due)) {
         $vtodo->add('DUE', $task->due);
     }
     if (isset($task->completed)) {
         $vtodo->add('COMPLETED', $task->completed);
     }
     switch ($task->priority) {
         case 'LOW':
             $vtodo->add('PRIORITY', 9);
             break;
         case 'NORMAL':
             $vtodo->add('PRIORITY', 0);
             break;
         case 'HIGH':
         case 'URGENT':
             $vtodo->add('PRIORITY', 1);
             break;
     }
     if (!empty($task->percent)) {
         $vtodo->add('PERCENT-COMPLETE', $task->percent);
     }
     // task organizer
     if (!empty($task->organizer)) {
         $organizerContact = $task->resolveOrganizer();
         if ($organizerContact instanceof Addressbook_Model_Contact && !empty($organizerContact->email)) {
             $organizer = $vtodo->add('ORGANIZER', 'mailto:' . $organizerContact->email, array('CN' => $organizerContact->n_fileas, 'EMAIL' => $organizerContact->email));
         }
     }
     $optionalProperties = array('class', 'description', 'geo', 'location', 'summary', 'status', 'url');
     foreach ($optionalProperties as $property) {
         if (!empty($task->{$property})) {
             $vtodo->add($property, $task->{$property});
         }
     }
     // categories
     if (!isset($task->tags)) {
         $task->tags = Tinebase_Tags::getInstance()->getTagsOfRecord($task);
     }
     if (isset($task->tags) && count($task->tags) > 0) {
         $vtodo->add('CATEGORIES', (array) $task->tags->name);
     }
     if ($task->alarms) {
         // fake X-MOZ-LASTACK
         $vtodo->add('X-MOZ-LASTACK', $task->creation_time->getClone()->setTimezone('UTC'), array('VALUE' => 'DATE-TIME'));
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' event ' . print_r($task->alarms, TRUE));
         }
         foreach ($task->alarms as $alarm) {
             $valarm = $vcalendar->create('VALARM');
             $valarm->add('ACTION', 'DISPLAY');
             $valarm->add('DESCRIPTION', $task->summary);
             if (is_numeric($alarm->minutes_before)) {
                 if ($task->dtstart == $alarm->alarm_time) {
                     $periodString = 'PT0S';
                 } else {
                     $interval = $task->due->diff($alarm->alarm_time);
                     $periodString = sprintf('%sP%s%s%s%s', $interval->format('%r'), $interval->format('%d') > 0 ? $interval->format('%dD') : null, $interval->format('%h') > 0 || $interval->format('%i') > 0 ? 'T' : null, $interval->format('%h') > 0 ? $interval->format('%hH') : null, $interval->format('%i') > 0 ? $interval->format('%iM') : null);
                 }
                 # TRIGGER;VALUE=DURATION:-PT1H15M
                 $trigger = $valarm->add('TRIGGER', $periodString);
                 $trigger['VALUE'] = "DURATION";
             } else {
                 # TRIGGER;VALUE=DATE-TIME:...
                 $trigger = $valarm->add('TRIGGER', $alarm->alarm_time->getClone()->setTimezone('UTC')->format('Ymd\\THis\\Z'));
                 $trigger['VALUE'] = "DATE-TIME";
             }
             $vtodo->add($valarm);
         }
     }
     $vcalendar->add($vtodo);
 }
 /**
  * Returns a list of calendar objects.
  *
  * This method should work identical to getCalendarObject, but instead
  * return all the calendar objects in the list as an array.
  *
  * If the backend supports this, it may allow for some speed-ups.
  *
  * @param mixed $calendarId
  * @param array $uris
  * @return array
  * @throws DAV\Exception\NotFound
  */
 function getMultipleCalendarObjects($calendarId, array $uris)
 {
     $return = [];
     foreach ($uris as $uri) {
         /** @var Termin $termin */
         $termin = Termin::model()->findByPk($uri);
         if (!$termin) {
             throw new \Sabre\DAV\Exception\NotFound('Calendar not found');
         }
         $vcalendar = new \Sabre\VObject\Component\VCalendar();
         $vcalendar->add('VEVENT', $termin->getVEventParams());
         $calendardata = $vcalendar->serialize();
         $return[] = ['id' => $termin->id, 'uri' => $termin->id, 'lastmodified' => $termin->datum_letzte_aenderung, 'etag' => rand(0, 999999999999), 'calendarid' => $calendarId, 'calendardata' => $calendardata, 'size' => strlen($calendardata), 'component' => 'VEVENT'];
     }
     return $return;
 }