Example #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']);
             }
         }
     }
 }