1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Extension "sf_event_mgt" for TYPO3 CMS. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the |
9
|
|
|
* LICENSE.txt file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace DERHANSEN\SfEventMgt\Service; |
13
|
|
|
|
14
|
|
|
use DERHANSEN\SfEventMgt\Domain\Model\Event; |
15
|
|
|
use DERHANSEN\SfEventMgt\Domain\Repository\EventRepository; |
16
|
|
|
use DERHANSEN\SfEventMgt\Event\EventPidCheckFailedEvent; |
|
|
|
|
17
|
|
|
use DERHANSEN\SfEventMgt\Utility\PageUtility; |
18
|
|
|
use Psr\EventDispatcher\EventDispatcherInterface; |
19
|
|
|
use TYPO3\CMS\Core\Context\Context; |
20
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
21
|
|
|
use TYPO3\CMS\Extbase\Mvc\RequestInterface; |
|
|
|
|
22
|
|
|
|
23
|
|
|
class EventEvaluationService |
24
|
|
|
{ |
25
|
|
|
public function __construct( |
26
|
|
|
protected readonly EventRepository $eventRepository, |
27
|
|
|
protected readonly EventDispatcherInterface $eventDispatcher, |
28
|
|
|
protected readonly Context $context |
29
|
|
|
) { |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Evaluates the given event for the detail action |
34
|
|
|
*/ |
35
|
|
|
public function evaluateForDetailAction(RequestInterface $request, array $settings, ?Event $event = null): ?Event |
36
|
|
|
{ |
37
|
|
|
$event = $this->evaluateSingleEventSetting($settings, $event); |
38
|
|
|
$event = $this->evaluateIsShortcutSetting($request, $settings, $event); |
39
|
|
|
$event = $this->evaluateEventPreviewSetting($request, $settings, $event); |
40
|
|
|
if ($event && is_a($event, Event::class) && ($settings['detail']['checkPidOfEventRecord'] ?? false)) { |
41
|
|
|
$event = $this->checkPidOfEventRecord($request, $settings, $event); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $event; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Evaluates the given event for the ical download action |
49
|
|
|
*/ |
50
|
|
|
public function evaluateForIcalDownloadAction( |
51
|
|
|
RequestInterface $request, |
52
|
|
|
array $settings, |
53
|
|
|
?Event $event = null |
54
|
|
|
): ?Event { |
55
|
|
|
if ($event && is_a($event, Event::class) && ($settings['detail']['checkPidOfEventRecord'] ?? false)) { |
56
|
|
|
$event = $this->checkPidOfEventRecord($request, $settings, $event); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $event; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Evaluates the given event for the registration action |
64
|
|
|
*/ |
65
|
|
|
public function evaluateForRegistrationAction( |
66
|
|
|
RequestInterface $request, |
67
|
|
|
array $settings, |
68
|
|
|
?Event $event = null |
69
|
|
|
): ?Event { |
70
|
|
|
$event = $this->evaluateSingleEventSetting($settings, $event); |
71
|
|
|
if ($event && is_a($event, Event::class) && ($settings['registration']['checkPidOfEventRecord'] ?? false)) { |
72
|
|
|
$event = $this->checkPidOfEventRecord($request, $settings, $event); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $event; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Evaluates the given event for the save registration action |
80
|
|
|
*/ |
81
|
|
|
public function evaluateForSaveRegistrationAction( |
82
|
|
|
RequestInterface $request, |
83
|
|
|
array $settings, |
84
|
|
|
?Event $event = null |
85
|
|
|
): ?Event { |
86
|
|
|
if ($event && is_a($event, Event::class) && ($settings['registration']['checkPidOfEventRecord'] ?? false)) { |
87
|
|
|
$event = $this->checkPidOfEventRecord($request, $settings, $event); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $event; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* If no event is given and the singleEvent setting is set, the configured single event is returned |
95
|
|
|
*/ |
96
|
|
|
private function evaluateSingleEventSetting(array $settings, ?Event $event = null): ?Event |
97
|
|
|
{ |
98
|
|
|
if ($event === null && (int)($settings['singleEvent'] ?? 0) > 0) { |
99
|
|
|
$event = $this->eventRepository->findByUid((int)$settings['singleEvent']); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $event; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* If no event is given and the isShortcut setting is set, the event is displayed using the "Insert Record" |
107
|
|
|
* content element and should be loaded from contect object data |
108
|
|
|
*/ |
109
|
|
|
private function evaluateIsShortcutSetting(RequestInterface $request, array $settings, ?Event $event = null): ?Event |
110
|
|
|
{ |
111
|
|
|
if ($event === null && (bool)($settings['detail']['isShortcut'] ?? false)) { |
112
|
|
|
$eventRawData = $request->getAttribute('currentContentObject')->data; |
113
|
|
|
$event = $this->eventRepository->findByUid($eventRawData['uid']); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return $event; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* If no event is given and the the `event_preview` argument is set, the event is displayed for preview |
121
|
|
|
*/ |
122
|
|
|
private function evaluateEventPreviewSetting(RequestInterface $request, array $settings, ?Event $event = null): ?Event |
123
|
|
|
{ |
124
|
|
|
if ($event === null && $request->hasArgument('event_preview')) { |
125
|
|
|
$hasBackendUser = $this->context->getPropertyFromAspect('backend.user', 'isLoggedIn'); |
126
|
|
|
$previewEventId = (int)$request->getArgument('event_preview'); |
127
|
|
|
if ($previewEventId > 0 && $hasBackendUser) { |
128
|
|
|
if ($settings['previewHiddenRecords'] ?? false) { |
129
|
|
|
$event = $this->eventRepository->findByUidIncludeHidden($previewEventId); |
130
|
|
|
} else { |
131
|
|
|
$event = $this->eventRepository->findByUid($previewEventId); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
return $event; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Checks if the event pid could be found in the storagePage settings of the detail plugin and |
141
|
|
|
* if the pid could not be found it return null instead of the event object. |
142
|
|
|
*/ |
143
|
|
|
private function checkPidOfEventRecord(RequestInterface $request, array $settings, Event $event): ?Event |
144
|
|
|
{ |
145
|
|
|
$allowedStoragePages = GeneralUtility::intExplode( |
146
|
|
|
',', |
147
|
|
|
PageUtility::extendPidListByChildren( |
148
|
|
|
$settings['storagePage'] ?? '', |
149
|
|
|
(int)($settings['recursive'] ?? 0) |
150
|
|
|
), |
151
|
|
|
true |
152
|
|
|
); |
153
|
|
|
if (count($allowedStoragePages) > 0 && !in_array($event->getPid(), $allowedStoragePages, true)) { |
154
|
|
|
$this->eventDispatcher->dispatch(new EventPidCheckFailedEvent($event, $request)); |
155
|
|
|
return null; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
return $event; |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths