b90032e8ad549ca1d4d73bac144b4fdac1063904
[TYPO3CMS/Extensions/caldav.git] / Classes / Hooks / TceMainProcessdatamap.php
1 <?php
2 namespace TYPO3\CMS\Caldav\Hooks;
3 /**
4 * *************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2015 Mario Matzulla (mario(at)matzullas.de)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 * *************************************************************
26 */
27
28 define ('ICALENDAR_PATH', \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath ('cal') . 'Classes/Model/ICalendar.php');
29
30 use TYPO3\CMS\Core\Utility\GeneralUtility;
31 use TYPO3\CMS\Backend\Utility\BackendUtility;
32
33 /**
34 * This hook extends the tcemain class.
35 * It catches changes on tx_cal_event
36 *
37 * @author Mario Matzulla <mario(at)matzullas.de>
38 */
39 class TceMainProcessdatamap {
40
41
42 public function processDatamap_afterDatabaseOperations($status, $table, $id, &$fieldArray, &$tcemain) {
43
44 /* If we have a new calendar event */
45 if (($table == 'tx_cal_event' || $table == 'tx_cal_exception_event') && count($fieldArray)>1) {
46 $event = BackendUtility::getRecord ($table, $status=='new'?$tcemain->substNEWwithIDs[$id]:$id);
47
48 /* If we're in a workspace, don't notify anyone about the event */
49 if($event['pid'] > 0) {
50 /* Check Page TSConfig for a preview page that we should use */
51 $pageTSConf = BackendUtility::getPagesTSconfig($event['pid']);
52 if($pageTSConf['options.']['tx_cal_controller.']['pageIDForPlugin']) {
53 $pageIDForPlugin = $pageTSConf['options.']['tx_cal_controller.']['pageIDForPlugin'];
54 } else {
55 $pageIDForPlugin = $event['pid'];
56 }
57
58 $page = BackendUtility::getRecord('pages', intval($pageIDForPlugin), 'doktype');
59
60 if($page['doktype'] != 254) {
61 $tx_cal_api = new \TYPO3\CMS\Cal\Controller\Api ();
62 $tx_cal_api = &$tx_cal_api->tx_cal_api_without($pageIDForPlugin);
63
64 if(! isset ($tx_cal_api->conf ['view.'] ['allowedViewsToLinkTo'])) {
65 return;
66 }
67
68 if($table == 'tx_cal_event'){
69 $eventObject = $tx_cal_api->modelObj->findEvent($event['uid'], 'tx_cal_phpicalendar', $tx_cal_api->conf['pidList'], false, false, false, true, true);
70
71 $oldPath = &$eventObject->conf['view.']['event.']['eventModelTemplate'];
72
73 $oldView = $eventObject->conf['view'];
74 $eventObject->conf['view'] = 'single_ics';
75 $extPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath ('cal');
76
77 $oldPath = 'EXT:cal/Resources/Private/Templates/v2/event_model.tmpl';
78 $oldPath = str_replace('EXT:cal/', $extPath, $oldPath);
79 //$oldPath = str_replace(PATH_site, '', $oldPath);
80 $eventObject->conf['view.']['event.']['eventModelTemplate'] = $oldPath;
81 $oldBackPath = $GLOBALS['TSFE']->tmpl->getFileName_backPath;
82 $GLOBALS['TSFE']->tmpl->getFileName_backPath = '';
83 $fileInfo = GeneralUtility::split_fileref($oldPath);
84 $GLOBALS['TSFE']->tmpl->allowedPaths[] = $fileInfo['path'];
85
86 $viewObj = \TYPO3\CMS\Cal\Utility\Registry::Registry('basic','viewcontroller');
87 $masterArray = Array($eventObject);
88 $drawnIcs = $viewObj->drawIcs($masterArray, '', false);
89 $table = 'tx_cal_event';
90 $where = 'uid = '.$event['uid'];
91 $eventData = Array('tx_caldav_data'=>$drawnIcs);
92 $result = $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table,$where,$eventData);
93
94 $table = 'tx_cal_calendar';
95 $where = 'uid = '.$event['calendar_id'];
96 $eventData = Array('tstamp'=>time());
97 $result = $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table,$where,$eventData);
98
99 $GLOBALS['TSFE']->tmpl->getFileName_backPath = $oldBackPath;
100 $eventObject->conf['view'] = $oldView;
101 }
102 }
103 }
104 }
105 }
106 }
107
108
109 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/caldav/hooks/class.tx_caldav_tcemain_processdatamap.php']) {
110 include_once ($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/caldav/hooks/class.tx_caldav_tcemain_processdatamap.php']);
111 }
112 ?>