Пример #1
0
 public function scheduleReminder($calEventUID)
 {
     // Get complete record
     $eventRecord = BackendUtility::getRecord('tx_cal_event', $calEventUID);
     // get the related monitoring records
     $taskId = null;
     $offset = 0;
     $select = '*';
     $table = 'tx_cal_fe_user_event_monitor_mm';
     $where = 'uid_local = ' . $calEventUID;
     $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select, $table, $where);
     while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
         $taskId = $row['schedulerId'];
         $offset = $row['offset'];
         // maybe there is a recurring instance
         // get the uids of recurring events from index
         $now = new \TYPO3\CMS\Cal\Model\CalDate();
         $now->setTZbyId('UTC');
         $now->addSeconds($offset * 60);
         $startDateTimeObject = new \TYPO3\CMS\Cal\Model\CalDate($eventRecord['start_date'] . '000000');
         $startDateTimeObject->setTZbyId('UTC');
         $startDateTimeObject->addSeconds($eventRecord['start_time']);
         $start_datetime = $startDateTimeObject->format('%Y%m%d%H%M%S');
         $select2 = '*';
         $table2 = 'tx_cal_index';
         $where2 = 'start_datetime >= ' . $now->format('%Y%m%d%H%M%S') . ' AND event_uid = ' . $calEventUID;
         $orderby2 = 'start_datetime asc';
         $result2 = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select2, $table2, $where2, $orderby2);
         if ($result) {
             $tmp = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result2);
             if (is_array($tmp)) {
                 $start_datetime = $tmp['start_datetime'];
                 $nextOccuranceTime = new \TYPO3\CMS\Cal\Model\CalDate($tmp['start_datetime']);
                 $nextOccuranceTime->setTZbyId('UTC');
                 $nextOccuranceEndTime = new \TYPO3\CMS\Cal\Model\CalDate($tmp['end_datetime']);
                 $nextOccuranceEndTime->setTZbyId('UTC');
                 $eventRecord['start_date'] = $nextOccuranceTime->format('%Y%m%d');
                 $eventRecord['start_time'] = $nextOccuranceTime->getHour() * 3600 + $nextOccuranceTime->getMinute() * 60 + $nextOccuranceTime->getSecond();
                 $eventRecord['end_date'] = $nextOccuranceEndTime->format('%Y%m%d');
                 $eventRecord['end_time'] = $nextOccuranceEndTime->getHour() * 3600 + $nextOccuranceEndTime->getMinute() * 60 + $nextOccuranceEndTime->getSecond();
             }
             $GLOBALS['TYPO3_DB']->sql_free_result($result2);
         }
         if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('scheduler')) {
             $scheduler = new \TYPO3\CMS\Scheduler\Scheduler();
             $date = new \TYPO3\CMS\Cal\Model\CalDate($start_datetime);
             $date->setTZbyId('UTC');
             $timestamp = $date->getTime();
             $offsetTime = new \TYPO3\CMS\Cal\Model\CalDate();
             $offsetTime->copy($date);
             $offsetTime->setTZbyId('UTC');
             $offsetTime->addSeconds(-1 * $offset * 60);
             if ($taskId > 0) {
                 if ($offsetTime->isFuture()) {
                     try {
                         $task = $scheduler->fetchTask($taskId);
                         $execution = new \TYPO3\CMS\Scheduler\Execution();
                         $execution->setStart($timestamp - $offset * 60);
                         $execution->setIsNewSingleExecution(true);
                         $execution->setMultiple(false);
                         $execution->setEnd(time() - 1);
                         $task->setExecution($execution);
                         $task->setDisabled(false);
                         $scheduler->saveTask($task);
                     } catch (OutOfBoundsException $e) {
                         $this->createSchedulerTask($scheduler, $date, $calEventUID, $timestamp, $offset, $row['uid']);
                     }
                 } else {
                     $this->deleteReminder($calEventUID);
                 }
             } else {
                 // taskId == 0 -> schedule task
                 $this->createSchedulerTask($scheduler, $date, $calEventUID, $timestamp, $offset, $row['uid']);
             }
         }
     }
 }
Пример #2
0
 function getStartOffset()
 {
     if (!isset($this->startOffset)) {
         $dayStart = $this->conf['view.']['day.']['dayStart'];
         // '0700'; // Start time for day grid
         while (strlen($dayStart) < 6) {
             $dayStart .= '0';
         }
         $d_start = new \TYPO3\CMS\Cal\Model\CalDate('01012000' . $dayStart);
         $this->startOffset = $d_start->getHour() + $d_start->getMinute() / 60;
     }
     return $this->startOffset;
 }
Пример #3
0
 /**
  *
  * @param
  *        	array	iCalendar component array
  * @return array
  */
 function insertCalEventsIntoDB($iCalendarComponentArray = array(), $calId, $pid = '', $cruserId = '', $isTemp = 1, $deleteNotUsedCategories = true)
 {
     $insertedOrUpdatedEventUids = array();
     $insertedOrUpdatedCategoryUids = array();
     if (empty($iCalendarComponentArray)) {
         return $insertedOrUpdatedEventUids;
     }
     $offsetArray = array();
     foreach ($iCalendarComponentArray as $component) {
         $table = 'tx_cal_event';
         $insertFields = array();
         $insertFields['isTemp'] = $isTemp;
         $insertFields['tstamp'] = time();
         $insertFields['crdate'] = time();
         $insertFields['pid'] = $pid;
         if (is_a($component, '\\TYPO3\\CMS\\Cal\\Model\\ICalendar\\vevent')) {
             $insertFields['cruser_id'] = $cruserId;
             $insertFields['calendar_id'] = $calId;
             if ($component->getAttribute('DTSTART')) {
                 $startdate = $component->getAttribute('DTSTART');
                 if (is_array($startdate)) {
                     $dateTime = new \TYPO3\CMS\Cal\Model\CalDate($startdate['year'] . $startdate['month'] . $startdate['mday'] . '000000');
                 } else {
                     $dateTime = new \TYPO3\CMS\Cal\Model\CalDate($startdate);
                 }
                 $params = $component->getAttributeParameters('DTSTART');
                 $timezone = $params['TZID'];
                 if ($timezone) {
                     $dateTime->convertTZbyID($timezone);
                 }
                 $insertFields['start_date'] = $dateTime->format('%Y%m%d');
                 $insertFields['start_time'] = $dateTime->hour * 3600 + $dateTime->minute * 60;
             } else {
                 continue;
             }
             if ($component->getAttribute('DTEND')) {
                 $enddate = $component->getAttribute('DTEND');
                 if (is_array($enddate)) {
                     $dateTime = new \TYPO3\CMS\Cal\Model\CalDate($enddate['year'] . $enddate['month'] . $enddate['mday'] . '000000');
                 } else {
                     $dateTime = new \TYPO3\CMS\Cal\Model\CalDate($enddate);
                 }
                 $params = $component->getAttributeParameters('DTEND');
                 $timezone = $params['TZID'];
                 if ($timezone) {
                     $dateTime->convertTZbyID($timezone);
                 }
                 $insertFields['end_date'] = $dateTime->format('%Y%m%d');
                 $insertFields['end_time'] = $dateTime->hour * 3600 + $dateTime->minute * 60;
             }
             if ($component->getAttribute('DURATION')) {
                 $enddate = $insertFields['start_time'] + $component->getAttribute('DURATION');
                 $dateTime = new \TYPO3\CMS\Cal\Model\CalDate($insertFields['start_date']);
                 $dateTime->addSeconds($enddate);
                 $params = $component->getAttributeParameters('DURATION');
                 $timezone = $params['TZID'];
                 if ($timezone) {
                     $dateTime->convertTZbyID($timezone);
                 }
                 $insertFields['end_date'] = $dateTime->format('%Y%m%d');
                 $insertFields['end_time'] = $dateTime->hour * 3600 + $dateTime->minute * 60;
             }
             $insertFields['icsUid'] = $component->getAttribute('UID');
             $insertFields['title'] = $component->getAttribute('SUMMARY');
             if ($component->organizerName()) {
                 $insertFields['organizer'] = str_replace('"', '', $component->organizerName());
             }
             $insertFields['location'] = $component->getAttribute('LOCATION');
             if ($insertFields['location'] == null) {
                 $insertFields['location'] = '';
             }
             $insertFields['description'] = $component->getAttribute('DESCRIPTION');
             $categoryString = $component->getAttribute('CATEGORY');
             if ($categoryString == "") {
                 $categoryString = $component->getAttribute('CATEGORIES');
             }
             $categories = GeneralUtility::trimExplode(',', $categoryString, 1);
             $categoryUids = array();
             foreach ($categories as $category) {
                 $category = trim($category);
                 $categorySelect = '*';
                 $categoryTable = 'tx_cal_category';
                 $categoryWhere = 'calendar_id = ' . intval($calId) . ' AND title =' . $GLOBALS['TYPO3_DB']->fullQuoteStr($category, $categoryTable);
                 $foundCategory = false;
                 $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery($categorySelect, $categoryTable, $categoryWhere);
                 if ($result) {
                     while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
                         $foundCategory = true;
                         $categoryUids[] = $row['uid'];
                     }
                     $GLOBALS['TYPO3_DB']->sql_free_result($result);
                 }
                 if (!$foundCategory) {
                     $result = $GLOBALS['TYPO3_DB']->exec_INSERTquery($categoryTable, array('tstamp' => $insertFields['tstamp'], 'crdate' => $insertFields['crdate'], 'pid' => $pid, 'title' => $category, 'calendar_id' => $calId));
                     if (FALSE === $result) {
                         throw new \RuntimeException('Could not write ' . $categoryTable . ' record to database: ' . $GLOBALS['TYPO3_DB']->sql_error(), 1431458143);
                     }
                     $categoryUids[] = $GLOBALS['TYPO3_DB']->sql_insert_id();
                 }
             }
             if ($component->getAttribute('RRULE')) {
                 $rrule = $component->getAttribute('RRULE');
                 $this->insertRuleValues($rrule, $insertFields);
             }
             if ($component->getAttribute('RDATE')) {
                 $rdate = $component->getAttribute('RDATE');
                 if (is_array($rdate)) {
                     $insertFields['rdate'] = implode(',', $rdate);
                 } else {
                     $insertFields['rdate'] = $rdate;
                 }
                 if ($component->getAttributeParameters('RDATE')) {
                     $parameterArray = $component->getAttributeParameters('RDATE');
                     $keys = array_keys($parameterArray);
                     $insertFields['rdate_type'] = strtolower($keys[0]);
                 } else {
                     $insertFields['rdate_type'] = 'date_time';
                 }
             }
             // Fix for allday events
             if ($insertFields['start_time'] == 0 && $insertFields['end_time'] == 0) {
                 $date = new \TYPO3\CMS\Cal\Model\CalDate($insertFields['end_date'] . '000000');
                 $date->setTZbyId('UTC');
                 $date->subtractSeconds(86400);
                 $insertFields['end_date'] = $date->format('%Y%m%d');
             }
             $eventRow = BackendUtility::getRecordRaw('tx_cal_event', 'icsUid="' . $insertFields['icsUid'] . '"');
             if ($eventRow['uid']) {
                 $result = $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . $eventRow['uid'], $insertFields);
                 $eventUid = $eventRow['uid'];
             } else {
                 $result = $GLOBALS['TYPO3_DB']->exec_INSERTquery($table, $insertFields);
                 if (FALSE === $result) {
                     throw new \RuntimeException('Could not write ' . $table . ' record to database: ' . $GLOBALS['TYPO3_DB']->sql_error(), 1431458144);
                 }
                 $eventUid = $GLOBALS['TYPO3_DB']->sql_insert_id();
             }
             $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['cal']);
             if ($component->getAttribute('RECURRENCE-ID')) {
                 $recurrenceIdStart = new \TYPO3\CMS\Cal\Model\CalDate($component->getAttribute('RECURRENCE-ID'));
                 $params = $component->getAttributeParameters('RECURRENCE-ID');
                 $timezone = $params['TZID'];
                 if ($timezone) {
                     $recurrenceIdStart->convertTZbyID($timezone);
                 }
                 $indexEntry = BackendUtility::getRecordRaw('tx_cal_index', 'event_uid="' . $eventUid . '" AND start_datetime="' . $recurrenceIdStart->format('%Y%m%d%H%M%S') . '"');
                 if ($indexEntry) {
                     $origStartDate = new \TYPO3\CMS\Cal\Model\CalDate();
                     $origStartDate = new \TYPO3\CMS\Cal\Model\CalDate();
                     $table = 'tx_cal_event_deviation';
                     $insertFields['parentid'] = $eventUid;
                     $insertFields['orig_start_time'] = $recurrenceIdStart->getHour() * 3600 + $recurrenceIdStart->getMinute() * 60;
                     $recurrenceIdStart->setHour(0);
                     $recurrenceIdStart->setMinute(0);
                     $recurrenceIdStart->setSecond(0);
                     $insertFields['orig_start_date'] = $recurrenceIdStart->getTime();
                     unset($insertFields['calendar_id']);
                     if ($indexEntry['event_deviation_uid'] > 0) {
                         $result = $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . $indexEntry['event_deviation_uid'], $insertFields);
                         $eventDeviationUid = $indexEntry['event_deviation_uid'];
                     } else {
                         $result = $GLOBALS['TYPO3_DB']->exec_INSERTquery($table, $insertFields);
                         if (FALSE === $result) {
                             throw new \RuntimeException('Could not write ' . $table . ' record to database: ' . $GLOBALS['TYPO3_DB']->sql_error(), 1431458145);
                         }
                         $eventDeviationUid = $GLOBALS['TYPO3_DB']->sql_insert_id();
                     }
                     $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_cal_index', 'uid=' . $indexEntry['uid'], array('event_deviation_uid' => $eventDeviationUid));
                 }
             } else {
                 /* Delete the old exception relations */
                 $exceptionEventUidsToBeDeleted = array();
                 $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_cal_exception_event.uid', 'tx_cal_exception_event,tx_cal_exception_event_mm', 'tx_cal_exception_event.uid = tx_cal_exception_event_mm.uid_foreign AND tx_cal_exception_event_mm.uid_local=' . $eventUid);
                 if ($result) {
                     while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
                         $exceptionEventUidsToBeDeleted[] = $row['uid'];
                     }
                     $GLOBALS['TYPO3_DB']->sql_free_result($result);
                 }
                 if (!empty($exceptionEventUidsToBeDeleted)) {
                     $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_cal_exception_event', 'uid in (' . implode(',', $exceptionEventUidsToBeDeleted) . ')');
                 }
                 $exceptionEventGroupUidsToBeDeleted = array();
                 $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_cal_exception_event_group.uid', 'tx_cal_exception_event_group,tx_cal_exception_event_group_mm', 'tx_cal_exception_event_group.uid = tx_cal_exception_event_group_mm.uid_foreign AND tx_cal_exception_event_group_mm.uid_local=' . $eventUid);
                 if ($result) {
                     while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
                         $exceptionEventGroupUidsToBeDeleted[] = $row['uid'];
                     }
                     $GLOBALS['TYPO3_DB']->sql_free_result($result);
                 }
                 if (!empty($exceptionEventGroupUidsToBeDeleted)) {
                     $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_cal_exception_event_group', 'uid in (' . implode(',', $exceptionEventGroupUidsToBeDeleted) . ')');
                 }
                 $where = ' uid_local=' . $eventUid;
                 $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_cal_exception_event_mm', $where);
                 $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_cal_exception_event_group_mm', $where);
                 // Exceptions:
                 if ($component->getAttribute('EXDATE')) {
                     if (is_array($component->getAttribute('EXDATE'))) {
                         foreach ($component->getAttribute('EXDATE') as $exceptionDescription) {
                             $this->createException($pid, $cruserId, $eventUid, $exceptionDescription);
                         }
                     } else {
                         $this->createException($pid, $cruserId, $eventUid, $component->getAttribute('EXDATE'));
                     }
                 }
                 if ($component->getAttribute('EXRULE')) {
                     if (is_array($component->getAttribute('EXRULE'))) {
                         foreach ($component->getAttribute('EXRULE') as $exceptionDescription) {
                             $this->createExceptionRule($pid, $cruserId, $eventUid, $exceptionDescription);
                         }
                     } else {
                         $this->createExceptionRule($pid, $cruserId, $eventUid, $component->getAttribute('EXRULE'));
                     }
                 }
                 $pageTSConf = BackendUtility::getPagesTSconfig($pid);
                 if ($pageTSConf['options.']['tx_cal_controller.']['pageIDForPlugin']) {
                     $pageIDForPlugin = $pageTSConf['options.']['tx_cal_controller.']['pageIDForPlugin'];
                 } else {
                     $pageIDForPlugin = $pid;
                 }
                 /** @var \TYPO3\CMS\Cal\Utility\RecurrenceGenerator $rgc */
                 $rgc = GeneralUtility::makeInstance('TYPO3\\CMS\\Cal\\Utility\\RecurrenceGenerator', $pageIDForPlugin);
                 $rgc->generateIndexForUid($eventUid, 'tx_cal_event');
                 if ($this->conf['view.']['event.']['remind']) {
                     /* Schedule reminders for new and changed events */
                     $pageTSConf = BackendUtility::getPagesTSconfig($pid);
                     $offset = is_numeric($pageTSConf['options.']['tx_cal_controller.']['view.']['event.']['remind.']['time']) ? $pageTSConf['options.']['tx_cal_controller.']['view.']['event.']['remind.']['time'] * 60 : 0;
                     $date = new \TYPO3\CMS\Cal\Model\CalDate($insertFields['start_date'] . '000000');
                     $date->setTZbyId('UTC');
                     $reminderTimestamp = $date->getTime() + $insertFields['start_time'] - $offset;
                     $reminderService =& \TYPO3\CMS\Cal\Utility\Functions::getReminderService();
                     $reminderService->scheduleReminder($eventUid);
                 }
                 /* Delete the old category relations */
                 $where = ' uid_local=' . $eventUid;
                 $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_cal_event_category_mm', $where);
                 foreach ($categoryUids as $uid) {
                     $result = $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_cal_event_category_mm', array('uid_local' => $eventUid, 'uid_foreign' => $uid));
                     if (FALSE === $result) {
                         throw new \RuntimeException('Could not write tx_cal_event_category_mm record to database: ' . $GLOBALS['TYPO3_DB']->sql_error(), 1431458146);
                     }
                 }
                 $insertedOrUpdatedEventUids[] = $eventUid;
                 $insertedOrUpdatedCategoryUids = array_merge($insertedOrUpdatedCategoryUids, $categoryUids);
                 // Hook: insertCalEventsIntoDB
                 $hookObjectsArr = \TYPO3\CMS\Cal\Utility\Functions::getHookObjectsArray('tx_cal_icalendar_service', 'iCalendarServiceClass', 'service');
                 foreach ($hookObjectsArr as $hookObj) {
                     if (method_exists($hookObj, 'insertCalEventsIntoDB')) {
                         $hookObj->insertCalEventsIntoDB($this, $eventUid, $component);
                     }
                 }
             }
         }
     }
     if ($deleteNotUsedCategories) {
         /* Delete the categories */
         $where = ' calendar_id=' . $calId;
         if (!empty($insertedOrUpdatedCategoryUids)) {
             array_unique($insertedOrUpdatedCategoryUids);
             $where .= ' AND uid NOT IN (' . implode(',', $insertedOrUpdatedCategoryUids) . ')';
         }
         $extConf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['cal']);
         $GLOBALS['TYPO3_DB']->exec_DELETEquery($extConf['categoryService'], $where);
     }
     return $insertedOrUpdatedEventUids;
 }
Пример #4
0
 public function getTimetableHeightMarker(&$template, &$sims, &$rems, &$wrapped, $view)
 {
     $conf =& \TYPO3\CMS\Cal\Utility\Registry::Registry('basic', 'conf');
     $gridLength = $conf['view.']['day.']['gridLength'];
     $dayStart = $conf['view.']['day.']['dayStart'];
     // '0700'; // Start time for day grid
     $dayEnd = $conf['view.']['day.']['dayEnd'];
     // '2300'; // End time for day grid
     while (strlen($dayStart) < 6) {
         $dayStart .= '0';
     }
     while (strlen($dayEnd) < 6) {
         $dayEnd .= '0';
     }
     $d_start = new \TYPO3\CMS\Cal\Model\CalDate('01012000' . $dayStart);
     $d_end = new \TYPO3\CMS\Cal\Model\CalDate('01012000' . $dayEnd);
     $sims['###TIMETABLE_HEIGHT###'] = ($d_end->getHour() * 3600 + $d_end->getMinute() * 60 - ($d_start->getHour() * 3600 + $d_start->getMinute() * 60)) / $gridLength * 0.35;
 }