Esempio n. 1
0
 function processCmdmap_postProcess(&$command, &$table, &$id, &$value, &$tce)
 {
     switch ($table) {
         case 'tx_cal_event':
             $select = '*';
             $table = 'tx_cal_event';
             $where = 'uid = ' . $id;
             $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select, $table, $where);
             if ($result) {
                 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
                     /* If we're in a workspace, don't notify anyone about the event */
                     if ($row['pid'] > 0 && !$GLOBALS['BE_USER']->workspace) {
                         /* Check Page TSConfig for a preview page that we should use */
                         $pageIDForPlugin = $this->getPageIDForPlugin($row['pid']);
                         $page = BackendUtility::getRecord('pages', intval($pageIDForPlugin), "doktype");
                         if ($page['doktype'] != 254) {
                             $tx_cal_api = GeneralUtility::makeInstance('TYPO3\\CMS\\Cal\\Controller\\Api');
                             $tx_cal_api =& $tx_cal_api->tx_cal_api_without($pageIDForPlugin);
                             $notificationService =& \TYPO3\CMS\Cal\Utility\Functions::getNotificationService();
                             if ($command == 'delete') {
                                 /* If the deleted event is temporary, reset the MD5 of the parent calendar */
                                 if ($row['isTemp']) {
                                     $calendar_id = $row['calendar_id'];
                                     $insertFields = array('md5' => '');
                                     $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_cal_calendar', 'uid=' . $calendar_id, $insertFields);
                                 }
                                 /** @var \TYPO3\CMS\Cal\Utility\RecurrenceGenerator $rgc */
                                 $rgc = GeneralUtility::makeInstance('TYPO3\\CMS\\Cal\\Utility\\RecurrenceGenerator');
                                 $rgc->cleanIndexTableOfUid($id, $table);
                                 /* Delete all deviations of the event */
                                 $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_cal_event_deviation', 'parentid=' . $id);
                             } else {
                                 $notificationService->notifyOfChanges($row, array($command => $value));
                             }
                         }
                     }
                 }
                 $GLOBALS['TYPO3_DB']->sql_free_result($result);
             }
             break;
         case 'tx_cal_calendar':
             /* If a calendar has been deleted, we might need to clean up. */
             if ($command == 'delete') {
                 /* Using getRecordRaw rather than getRecord since the record has already been deleted. */
                 $calendarRow = BackendUtility::getRecordRaw('tx_cal_calendar', 'uid=' . $id);
                 /* If the calendar is an External URL or ICS file, then we need to clean up */
                 if ($calendarRow['type'] == 1 or $calendarRow['type'] == 2) {
                     $service = new \TYPO3\CMS\Cal\Service\ICalendarService();
                     $service->deleteTemporaryEvents($id);
                     $service->deleteTemporaryCategories($id);
                     $service->deleteScheduledUpdates($id);
                     $service->deleteSchedulerTask($id);
                 }
             }
             if ($command == 'copy') {
                 $newCalendarIds = $tce->copyMappingArray['tx_cal_calendar'];
                 // check if source of copy has a scheduler task attached
                 $calendarRow = BackendUtility::getRecord('tx_cal_calendar', $id);
                 if ($calendarRow['schedulerId'] > 0) {
                     $scheduler = new \TYPO3\CMS\Scheduler\Scheduler();
                     $service = new \TYPO3\CMS\Cal\Service\ICalendarService();
                     foreach ($newCalendarIds as $newCalendarId) {
                         $service->createSchedulerTask($scheduler, 0, $newCalendarId);
                     }
                 }
             }
             break;
         case 'tx_cal_exception_event_group':
         case 'tx_cal_exception_event':
             if ($command == 'delete') {
                 $select = '*';
                 $where = 'uid = ' . $id;
                 $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select, $table, $where);
                 if ($result) {
                     while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
                         /* If we're in a workspace, don't notify anyone about the event */
                         if ($row['pid'] > 0 && !$GLOBALS['BE_USER']->workspace) {
                             /* Check Page TSConfig for a preview page that we should use */
                             $pageIDForPlugin = $this->getPageIDForPlugin($row['pid']);
                             $page = BackendUtility::getRecord('pages', intval($pageIDForPlugin), "doktype");
                             if ($page['doktype'] != 254) {
                                 $tx_cal_api = new \TYPO3\CMS\Cal\Controller\Api();
                                 $tx_cal_api =& $tx_cal_api->tx_cal_api_without($pageIDForPlugin);
                                 /** @var \TYPO3\CMS\Cal\Utility\RecurrenceGenerator $rgc */
                                 $rgc = GeneralUtility::makeInstance('TYPO3\\CMS\\Cal\\Utility\\RecurrenceGenerator');
                                 $rgc->cleanIndexTableOfUid($id, $table);
                             }
                         }
                     }
                     $GLOBALS['TYPO3_DB']->sql_free_result($result);
                 }
             }
             break;
         case 'tx_cal_event_deviation':
             if ($command == 'delete') {
                 $select = 'tx_cal_event.uid, tx_cal_event.pid';
                 $where = 'tx_cal_index.event_uid = tx_cal_event.uid and tx_cal_index.event_deviation_uid = ' . $id;
                 $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select, 'tx_cal_index, tx_cal_event', $where);
                 if ($result) {
                     while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
                         $this->reindexEvent($row['uid'], $row['pid']);
                     }
                 }
             }
             break;
     }
 }
Esempio n. 2
0
    function processDatamap_preProcessFieldArray(&$incomingFieldArray, $table, $id, &$tce)
    {
        /**
         * Demo code for using TCE to do custom validation of form elements.
         * The record is still
         * saved but a bad combination of start date and end date will generate an error message.
         */
        /*
         * if($table == 'tx_cal_event') { $startTimestamp = $incomingFieldArray['start_date'] + $incomingFieldArray['start_time']; $endTimestamp = $incomingFieldArray['end_date'] + $incomingFieldArray['end_time']; if ($startTimestamp > $endTimestamp) { $tce->log('tx_cal_event', 2, $id, 0, 1, "Event end (".BackendUtility::datetime($endTimestamp).") is earlier than event start (".BackendUtility::datetime($startTimestamp).").", 1); } }
         */
        /* preview events on eventViewPid on "save and preview" calls. but only if it's a regular event and the user is in live workspace */
        if ($table == 'tx_cal_event' && isset($GLOBALS['_POST']['_savedokview_x']) && !$incomingFieldArray['type'] && !$GLOBALS['BE_USER']->workspace) {
            $pagesTSConfig = BackendUtility::getPagesTSconfig($GLOBALS['_POST']['popViewId']);
            if ($pagesTSConfig['options.']['tx_cal_controller.']['eventViewPid']) {
                $GLOBALS['_POST']['popViewId_addParams'] = ($incomingFieldArray['sys_language_uid'] > 0 ? '&L=' . $incomingFieldArray['sys_language_uid'] : '') . '&no_cache=1&tx_cal_controller[view]=event&tx_cal_controller[type]=tx_cal_phpicalendar&tx_cal_controller[uid]=' . $id;
                $GLOBALS['_POST']['popViewId'] = $pagesTSConfig['options.']['tx_cal_controller.']['eventViewPid'];
            }
        }
        if ($table == 'tx_cal_event' || $table == "tx_cal_exeption_event") {
            $event = BackendUtility::getRecord($table, $id);
            if (intval($event['start_date']) == 0) {
                return;
            }
            /**
             * If we have an event, check if a start and end time have been sent.
             * If both are 0, then its an all day event.
             */
            if (array_key_exists('start_time', $incomingFieldArray) && array_key_exists('end_time', $incomingFieldArray) && $incomingFieldArray['start_time'] == 0 && $incomingFieldArray['end_time'] == 0) {
                $incomingFieldArray['allday'] = 1;
            }
            /**
             * If the recurring frequency has changed and recurrence rules are not
             * already set, preset a reasonable value based on event start date/time.
             * 
             * @todo Default date calculations do not take any timezone information into account.
             */
            if ($incomingFieldArray['freq'] != $event['freq']) {
                $date = $this->convertBackendDateToPear($incomingFieldArray['start_date']);
                $date->addSeconds($incomingFieldArray['start_time']);
                $dayArray = TceMainProcessdatamap::getWeekdayOccurrence($date);
                /* If we're on the 4th occurrence or later, let's assume we want the last occurrence */
                if ($dayArray[0] >= 4) {
                    $dayArray[0] = -1;
                }
                switch ($incomingFieldArray['freq']) {
                    case 'week':
                        /* Default Value = Day of the week when event starts. */
                        if (!$incomingFieldArray['byday'] && !$event['byday']) {
                            $incomingFieldArray['byday'] = strtolower($date->getDayName(true, 2));
                        }
                        break;
                    case 'month':
                        /* Default Value = Day of the week and weekday occurrence when event starts */
                        if (!$incomingFieldArray['byday'] && !$event['byday']) {
                            $incomingFieldArray['byday'] = $dayArray[0] . strtolower(substr($dayArray[1], 0, 2));
                        }
                        break;
                    case 'year':
                        /* Default Value = Day of the month and month when event starts */
                        if (!$incomingFieldArray['bymonthday'] && !$event['bymonthday']) {
                            $incomingFieldArray['bymonthday'] = $date->getDay();
                        }
                        if (!$incomingFieldArray['bymonth'] && !$event['bymonth']) {
                            $incomingFieldArray['bymonth'] = $date->getMonth();
                        }
                        break;
                }
            }
        }
        if ($table == 'tx_cal_category' && array_key_exists('calendar_id', $incomingFieldArray) && !strstr($id, 'NEW')) {
            $category = BackendUtility::getRecord('tx_cal_category', $id);
            if ($incomingFieldArray['calendar_id'] != $category['calendar_id']) {
                $incomingFieldArray['parent_category'] = 0;
            }
        }
        /* If an existing calendar is updated */
        if ($table == 'tx_cal_calendar' && array_key_exists('type', $incomingFieldArray) && !strstr($id, 'NEW')) {
            /* Get the calendar info from the db */
            $calendar = BackendUtility::getRecord('tx_cal_calendar', $id);
            $service = new \TYPO3\CMS\Cal\Service\ICalendarService();
            // Here we have to check if the calendar belongs to the type
            // problem with case 2 & 3 -> what to do with events of type database? delete them without warning? keep them and assign them to a default category?
            switch ($incomingFieldArray['type']) {
                case 0:
                    /* Standard */
                    /* Delete any temporary events previously associated with this calendar */
                    if ($calendar['type'] != 0) {
                        $service->deleteTemporaryEvents($id);
                        $service->deleteSchedulerTask($id);
                        $calendar['schedulerId'] = 0;
                        /** @var \TYPO3\CMS\Cal\Utility\RecurrenceGenerator $rgc */
                        $rgc = GeneralUtility::makeInstance('TYPO3\\CMS\\Cal\\Utility\\RecurrenceGenerator');
                        $rgc->cleanIndexTableOfCalendarUid($id);
                    }
                    break;
                case 1:
                    /* External URL or ICS file */
                /* External URL or ICS file */
                case 2:
                    /* ICS File */
                    $this->processICS($calendar, $incomingFieldArray, $service);
                    break;
            }
        }
        if ($table == 'tx_cal_exception_event_group' && !strstr($id, 'NEW')) {
            $exceptionEvent = BackendUtility::getRecord('tx_cal_exception_event_group', $id);
            /* If we're in a workspace, don't notify anyone about the event */
            if ($exceptionEvent['pid'] > 0 && !$GLOBALS['BE_USER']->workspace) {
                /* Check Page TSConfig for a preview page that we should use */
                $pageTSConf = BackendUtility::getPagesTSconfig($exceptionEvent['pid']);
                if ($pageTSConf['options.']['tx_cal_controller.']['pageIDForPlugin']) {
                    $pageIDForPlugin = $pageTSConf['options.']['tx_cal_controller.']['pageIDForPlugin'];
                } else {
                    $pageIDForPlugin = $exceptionEvent['pid'];
                }
                $page = BackendUtility::getRecord('pages', intval($pageIDForPlugin), "doktype");
                if ($page['doktype'] != 254) {
                    $tx_cal_api = GeneralUtility::makeInstance('TYPO3\\CMS\\Cal\\Controller\\Api');
                    $tx_cal_api = $tx_cal_api->tx_cal_api_without($pageIDForPlugin);
                    /** @var \TYPO3\CMS\Cal\Utility\RecurrenceGenerator $rgc */
                    $rgc = GeneralUtility::makeInstance('TYPO3\\CMS\\Cal\\Utility\\RecurrenceGenerator');
                    $rgc->cleanIndexTableOfExceptionGroupUid($id);
                }
            }
        }
        if ($table == 'tx_cal_attendee') {
            $incomingFieldArray['fe_user_id'] = str_replace(array(',', 'fe_users_'), array('', ''), $incomingFieldArray['fe_user_id']);
            $incomingFieldArray['fe_group_id'] = str_replace(array(',', 'fe_groups_'), array('', ''), $incomingFieldArray['fe_group_id']);
            if ($incomingFieldArray['fe_group_id'] > 0) {
                $subType = 'getGroupsFE';
                $groups = array(0);
                $serviceObj = null;
                $serviceObj = GeneralUtility::makeInstanceService('auth', $subType);
                if ($serviceObj == null) {
                    return;
                }
                $serviceObj->getSubGroups($incomingFieldArray['fe_group_id'], '', $groups);
                unset($incomingFieldArray['fe_group_id']);
                $select = 'DISTINCT fe_users.*';
                $table = 'fe_groups, fe_users';
                $where = 'fe_groups.uid IN (' . implode(',', $groups) . ') 
						AND FIND_IN_SET(fe_groups.uid, fe_users.usergroup)
						AND fe_users.email != \'\' 
						AND fe_groups.deleted = 0 
						AND fe_groups.hidden = 0 
						AND fe_users.disable = 0
						AND fe_users.deleted = 0';
                $result2 = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select, $table, $where);
                $attendeeUids = array();
                while ($row2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result2)) {
                    $incomingFieldArray['fe_user_id'] = $row2['fe_users.uid'];
                    $result = $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_cal_attendee', $incomingFieldArray);
                    if (FALSE === $result) {
                        throw new \RuntimeException('Could not write attendee record to database: ' . $GLOBALS['TYPO3_DB']->sql_error(), 1431458136);
                    }
                    $attendeeUids[] = $GLOBALS['TYPO3_DB']->sql_insert_id();
                }
                $GLOBALS['TYPO3_DB']->sql_free_result($result2);
                // $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_cal_event', $incomingFieldArray);
                foreach ($tce->datamap['tx_cal_event'] as $eventUid => $eventArray) {
                    $eventArray['attendee'] = array_unique(array_merge(GeneralUtility::trimExplode(',', $eventArray['attendee'], 1), $attendeeUids));
                }
            }
            unset($incomingFieldArray['fe_group_id']);
        }
    }