1111 * LICENSE file that was distributed with this source code.
1212 */
1313
14+ use Exception ;
1415use Extcode \Cart \Domain \Model \Cart \Cart ;
1516use Extcode \Cart \Service \SessionHandler ;
1617use Extcode \Cart \Utility \CartUtility ;
18+ use Extcode \CartEvents \Domain \Model \Category ;
1719use Extcode \CartEvents \Domain \Model \Dto \EventDemand ;
1820use Extcode \CartEvents \Domain \Model \Event ;
1921use Extcode \CartEvents \Domain \Model \EventDate ;
2830use TYPO3 \CMS \Extbase \Configuration \ConfigurationManagerInterface ;
2931use TYPO3 \CMS \Extbase \Http \ForwardResponse ;
3032use TYPO3 \CMS \Extbase \Mvc \Controller \ActionController ;
31- use TYPO3 \CMS \Form \Mvc \Persistence \FormPersistenceManagerInterface ;
3233
33- class EventController extends ActionController
34+ final class EventController extends ActionController
3435{
3536 private Cart $ cart ;
3637
@@ -40,6 +41,7 @@ public function __construct(
4041 private readonly SessionHandler $ sessionHandler ,
4142 private readonly CartUtility $ cartUtility ,
4243 private readonly EventRepository $ eventRepository ,
44+ private readonly EventDateRepository $ eventDateRepository ,
4345 private readonly CategoryRepository $ categoryRepository ,
4446 ) {}
4547
@@ -118,6 +120,10 @@ public function showAction(?Event $event = null): ResponseInterface
118120 #[IgnoreValidation(['value ' => 'priceCategory ' ])]
119121 public function formAction (?EventDate $ eventDate = null , ?PriceCategory $ priceCategory = null ): ResponseInterface
120122 {
123+ if (class_exists (\TYPO3 \CMS \Form \Mvc \Persistence \FormPersistenceManagerInterface::class) === false ) {
124+ throw new \BadFunctionCallException ('This action requires the installation of typo3/cms-form. ' );
125+ }
126+
121127 if (!$ eventDate ) {
122128 $ arguments = $ this ->request ->getArguments ();
123129 foreach ($ arguments as $ argumentKey => $ argumentValue ) {
@@ -126,14 +132,17 @@ public function formAction(?EventDate $eventDate = null, ?PriceCategory $priceCa
126132 $ priceCategoryId = (int )$ argumentValue ['priceCategoryId ' ];
127133
128134 if ($ eventDateId ) {
129- $ eventDateRepository = GeneralUtility::makeInstance (
130- EventDateRepository::class
131- );
132- $ eventDate = $ eventDateRepository ->findByUid ($ eventDateId );
133-
134- $ formDefinition = $ eventDate ->getEvent ()->getFormDefinition ();
135+ $ eventDate = $ this ->eventDateRepository ->findByUid ($ eventDateId );
136+ if (($ eventDate instanceof EventDate) === false ) {
137+ throw new Exception ('Can not find EventDate with uid ' . $ eventDateId . '. ' , 1769617660 );
138+ }
139+ $ event = $ eventDate ->getEvent ();
140+ if (($ event instanceof Event) === false ) {
141+ throw new Exception ('EventDate with uid ' . $ eventDateId . ' has no event! ' , 1769617873 );
142+ }
143+ $ formDefinition = $ event ->getFormDefinition ();
135144 $ formPersistenceManager = GeneralUtility::makeInstance (
136- FormPersistenceManagerInterface::class
145+ \ TYPO3 \ CMS \ Form \ Mvc \ Persistence \ FormPersistenceManagerInterface::class
137146 );
138147 $ form = $ formPersistenceManager ->load ($ formDefinition );
139148
@@ -146,14 +155,17 @@ public function formAction(?EventDate $eventDate = null, ?PriceCategory $priceCa
146155 PriceCategoryRepository::class
147156 );
148157 $ priceCategory = $ priceCategoryRepository ->findByUid ($ priceCategoryId );
158+ if (($ priceCategory instanceof PriceCategory) === false ) {
159+ throw new Exception ('Can not find PriceCategory with uid ' . $ priceCategoryId . '. ' , 1769642011 );
160+ }
149161 }
150162 }
151163 }
152164 }
153165 }
154166
155- if (! $ eventDate ) {
156- throw new \ InvalidArgumentException ( );
167+ if (( $ eventDate instanceof EventDate) === false ) {
168+ throw new Exception ( ' Can not find EventDate. ' , 1769641914 );
157169 }
158170
159171 $ this ->view ->assign ('eventDate ' , $ eventDate );
@@ -169,19 +181,19 @@ public function formAction(?EventDate $eventDate = null, ?PriceCategory $priceCa
169181 'type ' => 'Hidden ' ,
170182 'identifier ' => 'productType ' ,
171183 'label ' => 'productType ' ,
172- 'defaultValue ' => ( $ eventDate ? 'CartEvents ' : '' ) ,
184+ 'defaultValue ' => 'CartEvents ' ,
173185 ],
174186 9998 => [
175187 'type ' => 'Hidden ' ,
176188 'identifier ' => 'eventDateId ' ,
177189 'label ' => 'eventDateId ' ,
178- 'defaultValue ' => ( $ eventDate ? $ eventDate ->getUid () : '' ),
190+ 'defaultValue ' => $ eventDate ->getUid (),
179191 ],
180192 9999 => [
181193 'type ' => 'Hidden ' ,
182194 'identifier ' => 'priceCategoryId ' ,
183195 'label ' => 'priceCategoryId ' ,
184- 'defaultValue ' => ($ priceCategory ? $ priceCategory ->getUid () : '' ),
196+ 'defaultValue ' => (( $ priceCategory instanceof PriceCategory) ? $ priceCategory ->getUid () : '' ),
185197 ],
186198 ],
187199 ],
@@ -195,28 +207,7 @@ public function formAction(?EventDate $eventDate = null, ?PriceCategory $priceCa
195207 return $ this ->htmlResponse ();
196208 }
197209
198- protected function getEvent (): ?Event
199- {
200- $ eventUid = 0 ;
201-
202- if ((int )$ GLOBALS ['TSFE ' ]->page ['doktype ' ] == 186 ) {
203- $ eventUid = (int )$ GLOBALS ['TSFE ' ]->page ['cart_events_event ' ];
204- }
205-
206- if ($ eventUid > 0 ) {
207- $ event = $ this ->eventRepository ->findByUid ($ eventUid );
208- if ($ event && $ event instanceof Event) {
209- return $ event ;
210- }
211- }
212-
213- return null ;
214- }
215-
216- /**
217- * Create the demand object which define which records will get shown
218- */
219- protected function createDemandObjectFromSettings (string $ type , array $ settings ): EventDemand
210+ private function createDemandObjectFromSettings (string $ type , array $ settings ): EventDemand
220211 {
221212 /** @var EventDemand $demand */
222213 $ demand = GeneralUtility::makeInstance (
@@ -254,7 +245,7 @@ protected function createDemandObjectFromSettings(string $type, array $settings)
254245 return $ demand ;
255246 }
256247
257- protected function addCategoriesToDemandObjectFromSettings (EventDemand &$ demand ): void
248+ private function addCategoriesToDemandObjectFromSettings (EventDemand &$ demand ): void
258249 {
259250 if ($ this ->settings ['categoriesList ' ]) {
260251 $ selectedCategories = GeneralUtility::intExplode (
@@ -268,6 +259,9 @@ protected function addCategoriesToDemandObjectFromSettings(EventDemand &$demand)
268259 if ($ this ->settings ['listSubcategories ' ]) {
269260 foreach ($ selectedCategories as $ selectedCategory ) {
270261 $ category = $ this ->categoryRepository ->findByUid ($ selectedCategory );
262+ if (($ category instanceof Category) === false ) {
263+ continue ;
264+ }
271265 $ categories = array_merge (
272266 $ categories ,
273267 $ this ->categoryRepository ->findSubcategoriesRecursiveAsArray ($ category )
@@ -281,10 +275,7 @@ protected function addCategoriesToDemandObjectFromSettings(EventDemand &$demand)
281275 }
282276 }
283277
284- /**
285- * assigns currency translation array to view
286- */
287- protected function assignCurrencyTranslationData (): void
278+ private function assignCurrencyTranslationData (): void
288279 {
289280 $ this ->restoreSession ();
290281
@@ -297,7 +288,7 @@ protected function assignCurrencyTranslationData(): void
297288 $ this ->view ->assign ('currencyTranslationData ' , $ currencyTranslationData );
298289 }
299290
300- protected function addCacheTags (iterable $ events ): void
291+ private function addCacheTags (iterable $ events ): void
301292 {
302293 $ cacheTags = [];
303294
@@ -333,7 +324,7 @@ private function forwardToShowActionWhenRequested(): ?ForwardResponse
333324 return $ forwardResponse ->withArguments (['event ' => $ this ->request ->getArgument ('event ' )]);
334325 }
335326
336- protected function restoreSession (): void
327+ private function restoreSession (): void
337328 {
338329 $ cart = $ this ->sessionHandler ->restoreCart ($ this ->cartConfiguration ['settings ' ]['cart ' ]['pid ' ]);
339330
0 commit comments