/**
  * Modify the given times via the configuration
  *
  * @param array         $times
  * @param Configuration $configuration
  *
  * @return void
  */
 public function handleConfiguration(array &$times, Configuration $configuration)
 {
     $excludeTimes = array();
     foreach ($configuration->getGroups() as $group) {
         $excludeTimes = array_merge($excludeTimes, $this->buildSingleTimeTableByGroup($group));
     }
     $times = $this->checkAndRemoveTimes($times, $excludeTimes);
 }
 /**
  * Build the configuration handler
  *
  * @param Configuration $configuration
  *
  * @return bool|AbstractTimeTable
  */
 protected function buildConfigurationHandler(Configuration $configuration)
 {
     $handler = 'HDNET\\Calendarize\\Service\\TimeTable\\' . ucfirst($configuration->getType()) . 'TimeTable';
     if (!class_exists($handler)) {
         return false;
     }
     return HelperUtility::create($handler);
 }
 /**
  * Import command
  *
  * @param string $icsCalendarUri
  * @param int    $pid
  */
 public function importCommand($icsCalendarUri = NULL, $pid = NULL)
 {
     if ($icsCalendarUri === NULL || !filter_var($icsCalendarUri, FILTER_VALIDATE_URL)) {
         $this->enqueueMessage('You have to enter a valid URL to the iCalendar ICS', 'Error', FlashMessage::ERROR);
     }
     if (!MathUtility::canBeInterpretedAsInteger($pid)) {
         $this->enqueueMessage('You have to enter a valid PID for the new created elements', 'Error', FlashMessage::ERROR);
     }
     // fetch external URI and write to file
     $this->enqueueMessage('Start to checkout the calendar: ' . $icsCalendarUri, 'Calendar', FlashMessage::INFO);
     $relativeIcalFile = 'typo3temp/ical.' . GeneralUtility::shortMD5($icsCalendarUri) . '.ical';
     $absoluteIcalFile = GeneralUtility::getFileAbsFileName($relativeIcalFile);
     $content = GeneralUtility::getUrl($icsCalendarUri);
     GeneralUtility::writeFile($absoluteIcalFile, $content);
     // get Events from file
     $icalEvents = $this->getIcalEvents($absoluteIcalFile);
     $this->enqueueMessage('Found ' . sizeof($icalEvents) . ' events in the given calendar', 'Items', FlashMessage::INFO);
     $events = $this->prepareEvents($icalEvents);
     $this->enqueueMessage('This is just a first draft. There are same missing fields. Will be part of the next release', 'Items', FlashMessage::ERROR);
     return;
     foreach ($events as $event) {
         $eventObject = $this->eventRepository->findOneByImportId($event['uid']);
         if ($eventObject instanceof Event) {
             // update
             $eventObject->setTitle($event['title']);
             $eventObject->setDescription($this->nl2br($event['description']));
             $this->eventRepository->update($eventObject);
             $this->enqueueMessage('Update Event Meta data: ' . $eventObject->getTitle(), 'Update');
         } else {
             // create
             $eventObject = new Event();
             $eventObject->setPid($pid);
             $eventObject->setImportId($event['uid']);
             $eventObject->setTitle($event['title']);
             $eventObject->setDescription($this->nl2br($event['description']));
             $configuration = new Configuration();
             $configuration->setType(Configuration::TYPE_TIME);
             $configuration->setFrequency(Configuration::FREQUENCY_NONE);
             /** @var \DateTime $startDate */
             $startDate = clone $event['start'];
             $startDate->setTime(0, 0, 0);
             $configuration->setStartDate($startDate);
             /** @var \DateTime $endDate */
             $endDate = clone $event['end'];
             $endDate->setTime(0, 0, 0);
             $configuration->setEndDate($endDate);
             $startTime = $this->dateTimeToDaySeconds($event['start']);
             if ($startTime > 0) {
                 $configuration->setStartTime($startTime);
                 $configuration->setEndTime($this->dateTimeToDaySeconds($event['end']));
                 $configuration->setAllDay(FALSE);
             } else {
                 $configuration->setAllDay(TRUE);
             }
             $eventObject->addCalendarize($configuration);
             $this->eventRepository->add($eventObject);
             $this->enqueueMessage('Add Event: ' . $eventObject->getTitle(), 'Add');
         }
     }
 }
 /**
  * Modify the given times via the configuration
  *
  * @param array         $times
  * @param Configuration $configuration
  *
  * @return void
  */
 public function handleConfiguration(array &$times, Configuration $configuration)
 {
     $url = $configuration->getExternalIcsUrl();
     if (!GeneralUtility::isValidUrl($url)) {
         HelperUtility::createFlashMessage('Configuration with invalid ICS URL: ' . $url, 'Index ICS URL', FlashMessage::ERROR);
         return;
     }
     $events = $this->icsReaderService->toArray($url);
     foreach ($events as $event) {
         /** @var $event ICalEvent */
         $startTime = DateTimeUtility::getDaySecondsOfDateTime($event->getStart());
         $endTime = DateTimeUtility::getDaySecondsOfDateTime($event->getEnd());
         if ($endTime === self::DAY_END) {
             $endTime = 0;
         }
         $entry = ['pid' => 0, 'start_date' => $event->getStart(), 'end_date' => $event->getEnd() ?: $event->getStart(), 'start_time' => $startTime, 'end_time' => $endTime, 'all_day' => $endTime === 0];
         $times[] = $entry;
     }
 }
 /**
  * Modify the given times via the configuration
  *
  * @param array         $times
  * @param Configuration $configuration
  *
  * @return void
  */
 public function handleConfiguration(array &$times, Configuration $configuration)
 {
     foreach ($configuration->getGroups() as $group) {
         $times = array_merge($times, $this->buildSingleTimeTableByGroup($group));
     }
 }
Example #6
0
 /**
  * Add recurrence items
  *
  * @param array         $times
  * @param Configuration $configuration
  * @param array         $baseEntry
  */
 protected function addRecurrenceItems(array &$times, Configuration $configuration, array $baseEntry)
 {
     if ($configuration->getRecurrence() === Configuration::RECURRENCE_NONE || $configuration->getDay() === Configuration::DAY_NONE) {
         return;
     }
     $recurrenceService = GeneralUtility::makeInstance('HDNET\\Calendarize\\Service\\RecurrenceService');
     $amountCounter = $configuration->getCounterAmount();
     $tillDate = $configuration->getTillDate();
     $maxLimit = $this->getFrequencyLimitPerItem();
     $lastLoop = $baseEntry;
     for ($i = 0; $i < $maxLimit && ($amountCounter === 0 || $i < $amountCounter); $i++) {
         $loopEntry = $lastLoop;
         $dateTime = false;
         if ($configuration->getFrequency() === Configuration::FREQUENCY_MONTHLY) {
             $dateTime = $recurrenceService->getRecurrenceForNextMonth($loopEntry['start_date'], $configuration->getRecurrence(), $configuration->getDay());
         } elseif ($configuration->getFrequency() === Configuration::FREQUENCY_YEARLY) {
             $dateTime = $recurrenceService->getRecurrenceForNextYear($loopEntry['start_date'], $configuration->getRecurrence(), $configuration->getDay());
         }
         if ($dateTime === false) {
             break;
         }
         /** @var \DateInterval $interval */
         $interval = $loopEntry['start_date']->diff($dateTime);
         $frequencyIncrement = $interval->format('%R%a days');
         $loopEntry = $this->createNextLoopEntry($loopEntry, $frequencyIncrement);
         if ($tillDate instanceof \DateTime && $loopEntry['start_date'] > $tillDate) {
             break;
         }
         $lastLoop = $loopEntry;
         $times[] = $loopEntry;
     }
 }
Example #7
0
 /**
  * Get the configuration
  *
  * @param int       $pid
  * @param \DateTime $startDate
  * @param \DateTime $endDate
  *
  * @return Configuration
  */
 protected function getConfiguration($pid, \DateTime $startDate, \DateTime $endDate)
 {
     $configuration = new Configuration();
     $configuration->setPid($pid);
     $configuration->setType(Configuration::TYPE_TIME);
     $configuration->setFrequency(Configuration::FREQUENCY_NONE);
     $configuration->setAllDay(true);
     $startTime = clone $startDate;
     $configuration->setStartDate(DateTimeUtility::resetTime($startDate));
     $endTime = $endDate;
     $configuration->setEndDate(DateTimeUtility::resetTime($endDate));
     $startTime = DateTimeUtility::getDaySecondsOfDateTime($startTime);
     if ($startTime > 0) {
         $configuration->setStartTime($startTime);
         $configuration->setEndTime(DateTimeUtility::getDaySecondsOfDateTime($endTime));
         $configuration->setAllDay(false);
     }
     return $configuration;
 }