1
|
|
|
<?php |
2
|
|
|
namespace DERHANSEN\SfEventMgt\Hooks; |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of the Extension "sf_event_mgt" for TYPO3 CMS. |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please read the |
8
|
|
|
* LICENSE.txt file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
use DERHANSEN\SfEventMgt\Service\EventCacheService; |
12
|
|
|
use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools; |
13
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Hooks for DataHandler |
17
|
|
|
* |
18
|
|
|
* @author Torben Hansen <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class DataHandlerHooks |
21
|
|
|
{ |
22
|
|
|
const EVENT_TABLE = 'tx_sfeventmgt_domain_model_event'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Flushes the cache if a event record was edited. |
26
|
|
|
* This happens on two levels: by UID and by PID. |
27
|
|
|
* |
28
|
|
|
* @param array $params |
29
|
|
|
*/ |
30
|
|
|
public function clearCachePostProc(array $params) |
31
|
|
|
{ |
32
|
|
|
if (isset($params['table']) && $params['table'] === 'tx_sfeventmgt_domain_model_event') { |
33
|
|
|
$eventUid = $params['uid'] ?? 0; |
34
|
|
|
$pageUid = $params['uid_page'] ?? 0; |
35
|
|
|
if ($eventUid > 0 || $pageUid > 0) { |
36
|
|
|
$eventCacheService = GeneralUtility::makeInstance(EventCacheService::class); |
37
|
|
|
$eventCacheService->flushEventCache($eventUid, $pageUid); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Checks if the fields defined in $checkFields are set in the data-array of pi_flexform. |
44
|
|
|
* If a field is present and contains an empty value, the field is unset. |
45
|
|
|
* |
46
|
|
|
* Structure of the checkFields array: |
47
|
|
|
* |
48
|
|
|
* array('sheet' => array('field1', 'field2')); |
49
|
|
|
* |
50
|
|
|
* @param string $status |
51
|
|
|
* @param string $table |
52
|
|
|
* @param string $id |
53
|
|
|
* @param array $fieldArray |
54
|
|
|
* @param \TYPO3\CMS\Core\DataHandling\DataHandler $reference |
55
|
|
|
* |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
|
|
public function processDatamap_postProcessFieldArray($status, $table, $id, &$fieldArray, &$reference) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
if ($table === 'tt_content' && $status == 'update' && isset($fieldArray['pi_flexform'])) { |
61
|
|
|
$checkFields = [ |
62
|
|
|
'notification' => [ |
63
|
|
|
'settings.notification.senderEmail', |
64
|
|
|
'settings.notification.senderName', |
65
|
|
|
'settings.notification.adminEmail', |
66
|
|
|
'settings.notification.replyToEmail', |
67
|
|
|
'settings.notification.registrationNew.userSubject', |
68
|
|
|
'settings.notification.registrationWaitlistNew.userSubject', |
69
|
|
|
'settings.notification.registrationNew.adminSubject', |
70
|
|
|
'settings.notification.registrationWaitlistNew.adminSubject', |
71
|
|
|
'settings.notification.registrationConfirmed.userSubject', |
72
|
|
|
'settings.notification.registrationWaitlistConfirmed.userSubject', |
73
|
|
|
'settings.notification.registrationConfirmed.adminSubject', |
74
|
|
|
'settings.notification.registrationWaitlistConfirmed.adminSubject', |
75
|
|
|
'settings.notification.registrationCancelled.userSubject', |
76
|
|
|
'settings.notification.registrationCancelled.adminSubject', |
77
|
|
|
], |
78
|
|
|
'sDEF' => [ |
79
|
|
|
'settings.displayMode', |
80
|
|
|
'settings.orderField', |
81
|
|
|
'settings.orderDirection', |
82
|
|
|
'settings.topEventRestriction', |
83
|
|
|
'settings.queryLimit', |
84
|
|
|
'settings.category', |
85
|
|
|
'settings.storagePage', |
86
|
|
|
'settings.registration.requiredFields', |
87
|
|
|
'settings.userRegistration.displayMode', |
88
|
|
|
'settings.userRegistration.orderField', |
89
|
|
|
'settings.userRegistration.orderDirection', |
90
|
|
|
'settings.userRegistration.storagePage', |
91
|
|
|
'settings.userRegistration.recursive' |
92
|
|
|
], |
93
|
|
|
'additional' => [ |
94
|
|
|
'settings.detailPid', |
95
|
|
|
'settings.listPid', |
96
|
|
|
'settings.registrationPid', |
97
|
|
|
'settings.paymentPid', |
98
|
|
|
'settings.restrictForeignRecordsToStoragePage', |
99
|
|
|
'settings.disableOverrideDemand' |
100
|
|
|
], |
101
|
|
|
'template' => [ |
102
|
|
|
'settings.templateLayout' |
103
|
|
|
] |
104
|
|
|
]; |
105
|
|
|
|
106
|
|
|
$flexformData = GeneralUtility::xml2array($fieldArray['pi_flexform']); |
107
|
|
|
foreach ($checkFields as $sheet => $fields) { |
108
|
|
|
foreach ($fields as $field) { |
109
|
|
|
if (isset($flexformData['data'][$sheet]['lDEF'][$field]['vDEF']) && |
110
|
|
|
$flexformData['data'][$sheet]['lDEF'][$field]['vDEF'] === '' |
111
|
|
|
) { |
112
|
|
|
unset($flexformData['data'][$sheet]['lDEF'][$field]); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
// If remaining sheet does not contain fields, then remove the sheet |
117
|
|
|
if (isset($flexformData['data'][$sheet]['lDEF']) && $flexformData['data'][$sheet]['lDEF'] === []) { |
118
|
|
|
unset($flexformData['data'][$sheet]); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** @var \TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools $flexFormTools */ |
123
|
|
|
$flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class); |
124
|
|
|
$fieldArray['pi_flexform'] = $flexFormTools->flexArray2Xml($flexformData, true); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Sets the TCA type of the fields 'registration' and 'registration_waitlist' to 'none' for copy and localize, |
130
|
|
|
* so field values will not be duplicated in the copy of the object. |
131
|
|
|
* |
132
|
|
|
* @param string $command |
133
|
|
|
* @param string $table |
134
|
|
|
* @param int $id |
135
|
|
|
* @param mixed $value |
136
|
|
|
* @param \TYPO3\CMS\Core\DataHandling\DataHandler $pObj |
137
|
|
|
* @param bool $pasteUpdate |
138
|
|
|
*/ |
139
|
|
|
public function processCmdmap_preProcess($command, $table, $id, $value, $pObj, $pasteUpdate) |
|
|
|
|
140
|
|
|
{ |
141
|
|
|
if (in_array($command, ['copy', 'localize']) && $table === self::EVENT_TABLE) { |
142
|
|
|
$GLOBALS['TCA'][self::EVENT_TABLE]['columns']['registration']['config']['type'] = 'none'; |
143
|
|
|
$GLOBALS['TCA'][self::EVENT_TABLE]['columns']['registration_waitlist']['config']['type'] = 'none'; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Sets the TCA type of certain fields back to their original state after a copy or move command |
149
|
|
|
* |
150
|
|
|
* @param string $command |
151
|
|
|
* @param string $table |
152
|
|
|
* @param int $id |
153
|
|
|
* @param string $value |
154
|
|
|
* @param \TYPO3\CMS\Core\DataHandling\DataHandler $pObj |
155
|
|
|
* @param bool $pasteUpdate |
156
|
|
|
* @param array $pasteDatamap |
157
|
|
|
*/ |
158
|
|
|
public function processCmdmap_postProcess($command, $table, $id, $value, $pObj, $pasteUpdate, $pasteDatamap) |
|
|
|
|
159
|
|
|
{ |
160
|
|
|
if (in_array($command, ['copy', 'localize']) && $table === self::EVENT_TABLE) { |
161
|
|
|
$GLOBALS['TCA'][self::EVENT_TABLE]['columns']['registration']['config']['type'] = 'inline'; |
162
|
|
|
$GLOBALS['TCA'][self::EVENT_TABLE]['columns']['registration_waitlist']['config']['type'] = 'inline'; |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.