Ejemplo n.º 1
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');
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
 /**
  * @brief Add property to vobject
  * @param object $name of property
  * @param object $value of property
  * @param object $parameters of property
  * @returns Sabre_VObject_Property newly created
  */
 public function addProperty($name, $value, $parameters = array())
 {
     if (is_array($value)) {
         $value = self::escapeSemicolons($value);
     }
     $vcalendar = new \Sabre\VObject\Component\VCalendar();
     $property = $vcalendar->createProperty($name, $value);
     foreach ($parameters as $name => $value) {
         $property->parameters[] = $vcalendar->createProperty($name, $value);
     }
     $this->vobject->add($property);
     return $property;
 }