function updateCalendar($uid) { $insertFields = array('tstamp' => time()); // TODO: Check if all values are correct $this->searchForAdditionalFieldsToAddFromPostData($insertFields, 'calendar', false); $this->retrievePostData($insertFields); $uid = $this->checkUidForLanguageOverlay($uid, 'tx_cal_calendar'); if ($this->rightsObj->isAllowedToEditCalendarType()) { $this->checkOnNewOrDeletableFiles('tx_cal_calendar', 'ics_file', $insertFields, $uid); } // Creating DB records $table = 'tx_cal_calendar'; $where = 'uid = ' . $uid; $service = new \TYPO3\CMS\Cal\Service\ICalendarService(); if ($insertFields['type'] == 1 && $insertFields['ext_url'] or $insertFields['type'] == 2 && $insertFields['ics_file']) { \TYPO3\CMS\Cal\Hooks\TceMainProcessdatamap::processICS(\TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('tx_cal_calendar', $uid), $insertFields, $service); /** @var \TYPO3\CMS\Cal\Utility\RecurrenceGenerator $rgc */ $rgc = GeneralUtility::makeInstance('TYPO3\\CMS\\Cal\\Utility\\RecurrenceGenerator', $GLOBALS['TSFE']->id); $rgc->generateIndexForCalendarUid($uid); } else { $service->deleteTemporaryEvents($uid); /** @var \TYPO3\CMS\Cal\Utility\RecurrenceGenerator $rgc */ $rgc = GeneralUtility::makeInstance('TYPO3\\CMS\\Cal\\Utility\\RecurrenceGenerator', $uid); $rgc->cleanIndexTableOfCalendarUid($uid); } $result = $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, $where, $insertFields); if ($this->rightsObj->isAllowedToEditCalendarOwner()) { $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_cal_calendar_user_group_mm', 'uid_local =' . $uid); if ($this->controller->piVars['owner_ids'] != '') { $user = array(); $group = array(); $this->splitUserAndGroupIds(explode(',', strip_tags($this->controller->piVars['owner_ids'])), $user, $group); $this->insertIdsIntoTableWithMMRelation('tx_cal_calendar_user_group_mm', $user, $uid, 'fe_users'); $this->insertIdsIntoTableWithMMRelation('tx_cal_calendar_user_group_mm', $group, $uid, 'fe_groups'); } } if ($this->rightsObj->isAllowedToEditCalendarFreeAndBusyUser()) { $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_cal_calendar_fnb_user_group_mm', 'uid_local =' . $uid); if ($this->controller->piVars['freeAndBusyUser_ids'] != '') { $user = array(); $group = array(); $this->splitUserAndGroupIds(explode(',', strip_tags($this->controller->piVars['freeAndBusyUser_ids'])), $user, $group); $this->insertIdsIntoTableWithMMRelation('tx_cal_calendar_fnb_user_group_mm', $user, $uid, 'fe_users'); $this->insertIdsIntoTableWithMMRelation('tx_cal_calendar_fnb_user_group_mm', $group, $uid, 'fe_groups'); } } $this->unsetPiVars(); \TYPO3\CMS\Cal\Utility\Functions::clearCache(); return $this->find($uid, $this->conf['pidList']); }
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']); } }