/** * Render an event as vevent * @param VCalendar $vcalendar * @param Event $event * @param Place $place */ private function renderEvent(VCalendar $vcalendar, Event $event, Place $place = null) { $vevent = $vcalendar->add('VEVENT', [], false); $this->addDate($event, $vevent, 'DTSTART', $event->getStart()); $this->addDate($event, $vevent, 'DTEND', $event->getEnd()); $properties = []; $properties['DTSTAMP'] = ['type' => 'DATE-TIME', 'value' => Utility::getNow()]; $properties['UID'] = ['type' => 'UNKNOWN', 'value' => $event->getUid()]; $properties['DESCRIPTION'] = ['type' => 'UNKNOWN', 'value' => $event->getDescription()]; $properties['SUMMARY'] = ['type' => 'UNKNOWN', 'value' => $event->getName()]; if ($place) { $properties['LOCATION'] = ['type' => 'UNKNOWN', 'value' => $place->getName()]; $properties['GEO'] = ['type' => 'UNKNOWN', 'value' => $place->getLocation()->getLatitude() . ';' . $place->getLocation()->getLongitude()]; } $allProperties = array_merge($properties, $event->getExtra()); foreach ($allProperties as $key => $val) { $prop = $vevent->add($key, $val['value']); if ($val['type'] === 'DATE') { $prop['VALUE'] = $val['type']; } } }
private function importEvents(Calendar $calendar, VCalendar $document) { // Prepare by deleting all existing events foreach ($calendar->getEvents() as $event) { $this->getEntityManager()->remove($event); } $calendar->getEvents()->clear(); // Abort if there is no events at all if (!$document->VEVENT) { return; } // First, import only originals, because we want to save RRULE before it is destroyed when expanding $originals = []; foreach ($document->VEVENT as $vevent) { if (!$vevent->__get('RECURRENCE-ID')) { $event = $this->importEvent($calendar, $vevent); $originals[$event->getUid()] = $event; } } // Expand repetitions 2 month in the past and 1 year in the future $now = Utility::getNow(); $start = $now->sub(new \DateInterval('P2M')); $end = $now->add(new \DateInterval('P1Y')); // Then we expand recurent rules $expandedDocument = $document->expand($start, $end); // Abort if there is no repetitions at all if (!$expandedDocument->VEVENT) { return; } // Finally re-import, but this time only the recurrent things foreach ($expandedDocument->VEVENT as $vevent) { $original = $this->findOriginal($originals, $vevent); if ($original) { $repetition = $this->importEvent($calendar, $vevent); $repetition->setOriginal($original); } } }
/** * Automatically called by Doctrine when the object is updated * * @ORM\PreUpdate */ public function timestampModification() { $this->setDateModified(Utility::getNow()); $this->setModifier(User::getCurrentUser()); }
/** * @param AbstractModel $object * @return string */ private function getResourceId(AbstractModel $object) { $class = \Application\Utility::getShortClassName($object); return 'Theodia\\V1\\Rest\\' . $class . '\\Controller::entity'; }