diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php deleted file mode 100644 index 07619bf..0000000 --- a/.php-cs-fixer.dist.php +++ /dev/null @@ -1,79 +0,0 @@ -exclude('Resources/contao/templates') - ->in([ - __DIR__.'/src', - ]) -; - -return (new PhpCsFixer\Config()) - ->setRules([ - '@Symfony' => true, - '@Symfony:risky' => true, - '@PHP71Migration' => true, - '@PHP71Migration:risky' => true, - '@PHPUnit60Migration:risky' => true, - 'align_multiline_comment' => true, - 'array_indentation' => true, - 'array_syntax' => ['syntax' => 'short'], - 'combine_consecutive_issets' => true, - 'combine_consecutive_unsets' => true, - 'comment_to_phpdoc' => true, - 'compact_nullable_typehint' => true, - 'escape_implicit_backslashes' => true, - 'fully_qualified_strict_types' => true, - 'general_phpdoc_annotation_remove' => [ - 'annotations' => [ - 'author', - 'expectedException', - 'expectedExceptionMessage', - ], - ], - 'header_comment' => ['header' => $header], - 'heredoc_to_nowdoc' => true, - 'linebreak_after_opening_tag' => true, - 'list_syntax' => ['syntax' => 'short'], - 'multiline_comment_opening_closing' => true, - 'multiline_whitespace_before_semicolons' => [ - 'strategy' => 'new_line_for_chained_calls', - ], - 'native_function_invocation' => [ - 'include' => ['@compiler_optimized'], - ], - 'no_alternative_syntax' => true, - 'no_binary_string' => true, - 'no_null_property_initialization' => true, - 'no_superfluous_elseif' => true, - 'no_superfluous_phpdoc_tags' => true, - 'no_unreachable_default_argument_value' => true, - 'no_useless_else' => true, - 'no_useless_return' => true, - 'ordered_class_elements' => true, - 'ordered_imports' => true, - 'php_unit_strict' => true, - 'phpdoc_add_missing_param_annotation' => true, - 'phpdoc_order' => true, - 'phpdoc_trim_consecutive_blank_line_separation' => true, - 'phpdoc_types_order' => [ - 'null_adjustment' => 'always_last', - 'sort_algorithm' => 'none', - ], - 'return_assignment' => true, - 'strict_comparison' => true, - 'strict_param' => true, - 'string_line_ending' => true, - 'void_return' => true, - ]) - ->setFinder($finder) - ->setRiskyAllowed(true) - ->setUsingCache(false) -; diff --git a/composer.json b/composer.json index d603d00..9aabc22 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ } ], "require": { - "php": ">=7.1", + "php": ">=8.1", "ext-json": "*", "contao/core-bundle": "^4.13 || ^5.0", "contao/calendar-bundle": "^4.13 || ^5.0", @@ -32,16 +32,15 @@ "inspiredminds/contao-backend-forms": ">=0.3, <2", "league/csv": "^9.6", "ramsey/uuid": "^3.0 || ^4.0", - "symfony/config": "^5.1 || ^6.0", - "symfony/dependency-injection": "^5.1 || ^6.0", - "symfony/http-foundation": "^5.1 || ^6.0", - "symfony/http-kernel": "^5.1 || ^6.0", - "symfony/routing": "^5.1 || ^6.0", - "symfony/security-core": "^5.1 || ^6.0", - "symfony/translation": "^5.1 || ^6.0", + "symfony/config": "^5.4 || ^6.4", + "symfony/dependency-injection": "^5.4 || ^6.4", + "symfony/http-foundation": "^5.4 || ^6.4", + "symfony/http-kernel": "^5.4 || ^6.4", + "symfony/routing": "^5.4 || ^6.4", + "symfony/security-core": "^5.4 || ^6.4", + "symfony/translation": "^5.4 || ^6.4", "terminal42/contao-node": "^1.3", "terminal42/notification_center": "^1.5", - "terminal42/service-annotation-bundle": "^1.1", "symfony/polyfill-php80": "^1.28" }, "autoload": { @@ -53,15 +52,16 @@ "contao-manager-plugin": "InspiredMinds\\ContaoEventRegistration\\ContaoManager\\Plugin" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.0", - "contao/manager-plugin": "^2.11" + "contao/easy-coding-standard": "^6.0", + "contao/rector": "^1.0" }, "config": { "allow-plugins": { "contao-components/installer": true, "contao-community-alliance/composer-plugin": true, "contao/manager-plugin": true, - "php-http/discovery": false + "php-http/discovery": false, + "dealerdirect/phpcodesniffer-composer-installer": true } } } diff --git a/src/Resources/config/routes.yaml b/config/routes.yaml similarity index 61% rename from src/Resources/config/routes.yaml rename to config/routes.yaml index 343fa0a..51ee7a3 100644 --- a/src/Resources/config/routes.yaml +++ b/config/routes.yaml @@ -1,3 +1,3 @@ im_contao_event_registration: - resource: ../../Controller + resource: ../src/Controller type: annotation diff --git a/src/Resources/config/services.yaml b/config/services.yaml similarity index 68% rename from src/Resources/config/services.yaml rename to config/services.yaml index 931b6f0..cf05c14 100644 --- a/src/Resources/config/services.yaml +++ b/config/services.yaml @@ -7,5 +7,5 @@ services: $bundles: '%kernel.bundles%' InspiredMinds\ContaoEventRegistration\: - resource: ../../ - exclude: ../../{Model,DependencyInjection,Resources} + resource: ../src/ + exclude: ../src/{Config,ContaoManager,DependencyInjection,Exception,Model} diff --git a/src/Resources/contao/config/config.php b/contao/config/config.php similarity index 98% rename from src/Resources/contao/config/config.php rename to contao/config/config.php index c84222d..531ff89 100644 --- a/src/Resources/contao/config/config.php +++ b/contao/config/config.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ diff --git a/src/Resources/contao/dca/tl_calendar.php b/contao/dca/tl_calendar.php similarity index 98% rename from src/Resources/contao/dca/tl_calendar.php rename to contao/dca/tl_calendar.php index bdba29c..a76f18f 100644 --- a/src/Resources/contao/dca/tl_calendar.php +++ b/contao/dca/tl_calendar.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ diff --git a/src/Resources/contao/dca/tl_calendar_events.php b/contao/dca/tl_calendar_events.php similarity index 90% rename from src/Resources/contao/dca/tl_calendar_events.php rename to contao/dca/tl_calendar_events.php index b3b00e9..2930740 100644 --- a/src/Resources/contao/dca/tl_calendar_events.php +++ b/contao/dca/tl_calendar_events.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ @@ -71,7 +71,7 @@ $GLOBALS['TL_DCA']['tl_calendar_events']['subpalettes']['reg_enable'] = 'reg_form,reg_min,reg_max,reg_regEnd,reg_cancelEnd,reg_requireConfirm'; foreach ($GLOBALS['TL_DCA']['tl_calendar_events']['palettes'] as $name => $palette) { - if (!\is_string($palette)) { + if (!is_string($palette)) { continue; } @@ -84,9 +84,9 @@ $GLOBALS['TL_DCA']['tl_calendar_events']['config']['ctable'][] = 'tl_event_registration'; -$GLOBALS['TL_DCA']['tl_calendar_events']['list']['operations'] = \array_slice($GLOBALS['TL_DCA']['tl_calendar_events']['list']['operations'], 0, 6, true) + [ +$GLOBALS['TL_DCA']['tl_calendar_events']['list']['operations'] = array_slice($GLOBALS['TL_DCA']['tl_calendar_events']['list']['operations'], 0, 6, true) + [ 'registrations' => [ 'href' => 'table=tl_event_registration', 'icon' => 'mgroup.svg', ], -] + \array_slice($GLOBALS['TL_DCA']['tl_calendar_events']['list']['operations'], 6, \count($GLOBALS['TL_DCA']['tl_calendar_events']['list']['operations']) - 1, true); +] + array_slice($GLOBALS['TL_DCA']['tl_calendar_events']['list']['operations'], 6, count($GLOBALS['TL_DCA']['tl_calendar_events']['list']['operations']) - 1, true); diff --git a/src/Resources/contao/dca/tl_event_registration.php b/contao/dca/tl_event_registration.php similarity index 97% rename from src/Resources/contao/dca/tl_event_registration.php rename to contao/dca/tl_event_registration.php index e91e2f5..7b477be 100644 --- a/src/Resources/contao/dca/tl_event_registration.php +++ b/contao/dca/tl_event_registration.php @@ -5,16 +5,17 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ +use Contao\DC_Table; use InspiredMinds\ContaoEventRegistration\Controller\EventRegistrationExportController; $GLOBALS['TL_DCA']['tl_event_registration'] = [ 'config' => [ - 'dataContainer' => 'Table', + 'dataContainer' => DC_Table::class, 'ptable' => 'tl_calendar_events', 'closed' => true, 'doNotCopyRecords' => true, diff --git a/src/Resources/contao/dca/tl_module.php b/contao/dca/tl_module.php similarity index 98% rename from src/Resources/contao/dca/tl_module.php rename to contao/dca/tl_module.php index 3c357eb..03850ff 100644 --- a/src/Resources/contao/dca/tl_module.php +++ b/contao/dca/tl_module.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ diff --git a/src/Resources/contao/languages/de/modules.php b/contao/languages/de/modules.php similarity index 98% rename from src/Resources/contao/languages/de/modules.php rename to contao/languages/de/modules.php index 34e392f..c41df14 100644 --- a/src/Resources/contao/languages/de/modules.php +++ b/contao/languages/de/modules.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ diff --git a/src/Resources/contao/languages/de/tl_calendar.php b/contao/languages/de/tl_calendar.php similarity index 97% rename from src/Resources/contao/languages/de/tl_calendar.php rename to contao/languages/de/tl_calendar.php index dcc4dc8..9f294ab 100644 --- a/src/Resources/contao/languages/de/tl_calendar.php +++ b/contao/languages/de/tl_calendar.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ diff --git a/src/Resources/contao/languages/de/tl_calendar_events.php b/contao/languages/de/tl_calendar_events.php similarity index 98% rename from src/Resources/contao/languages/de/tl_calendar_events.php rename to contao/languages/de/tl_calendar_events.php index 341862d..f3737b3 100644 --- a/src/Resources/contao/languages/de/tl_calendar_events.php +++ b/contao/languages/de/tl_calendar_events.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ diff --git a/src/Resources/contao/languages/de/tl_event_registration.php b/contao/languages/de/tl_event_registration.php similarity index 97% rename from src/Resources/contao/languages/de/tl_event_registration.php rename to contao/languages/de/tl_event_registration.php index d296e14..cc3aab9 100644 --- a/src/Resources/contao/languages/de/tl_event_registration.php +++ b/contao/languages/de/tl_event_registration.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ diff --git a/src/Resources/contao/languages/de/tl_nc_notification.php b/contao/languages/de/tl_nc_notification.php similarity index 97% rename from src/Resources/contao/languages/de/tl_nc_notification.php rename to contao/languages/de/tl_nc_notification.php index 517f265..3a378bc 100644 --- a/src/Resources/contao/languages/de/tl_nc_notification.php +++ b/contao/languages/de/tl_nc_notification.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ diff --git a/src/Resources/contao/languages/de/tokens.php b/contao/languages/de/tokens.php similarity index 98% rename from src/Resources/contao/languages/de/tokens.php rename to contao/languages/de/tokens.php index fc60af4..23756a2 100644 --- a/src/Resources/contao/languages/de/tokens.php +++ b/contao/languages/de/tokens.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ diff --git a/src/Resources/contao/languages/en/modules.php b/contao/languages/en/modules.php similarity index 98% rename from src/Resources/contao/languages/en/modules.php rename to contao/languages/en/modules.php index 516d54d..e3192e4 100644 --- a/src/Resources/contao/languages/en/modules.php +++ b/contao/languages/en/modules.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ diff --git a/src/Resources/contao/languages/en/tl_calendar.php b/contao/languages/en/tl_calendar.php similarity index 96% rename from src/Resources/contao/languages/en/tl_calendar.php rename to contao/languages/en/tl_calendar.php index 2a389be..2633de7 100644 --- a/src/Resources/contao/languages/en/tl_calendar.php +++ b/contao/languages/en/tl_calendar.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ diff --git a/src/Resources/contao/languages/en/tl_calendar_events.php b/contao/languages/en/tl_calendar_events.php similarity index 98% rename from src/Resources/contao/languages/en/tl_calendar_events.php rename to contao/languages/en/tl_calendar_events.php index 3d4ad65..fe84ca1 100644 --- a/src/Resources/contao/languages/en/tl_calendar_events.php +++ b/contao/languages/en/tl_calendar_events.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ diff --git a/src/Resources/contao/languages/en/tl_event_registration.php b/contao/languages/en/tl_event_registration.php similarity index 97% rename from src/Resources/contao/languages/en/tl_event_registration.php rename to contao/languages/en/tl_event_registration.php index ba743b0..00b376e 100644 --- a/src/Resources/contao/languages/en/tl_event_registration.php +++ b/contao/languages/en/tl_event_registration.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ diff --git a/src/Resources/contao/languages/en/tl_nc_notification.php b/contao/languages/en/tl_nc_notification.php similarity index 96% rename from src/Resources/contao/languages/en/tl_nc_notification.php rename to contao/languages/en/tl_nc_notification.php index 87f8fb6..4f646c6 100644 --- a/src/Resources/contao/languages/en/tl_nc_notification.php +++ b/contao/languages/en/tl_nc_notification.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ diff --git a/src/Resources/contao/languages/en/tokens.php b/contao/languages/en/tokens.php similarity index 97% rename from src/Resources/contao/languages/en/tokens.php rename to contao/languages/en/tokens.php index f537ef2..e7f51b0 100644 --- a/src/Resources/contao/languages/en/tokens.php +++ b/contao/languages/en/tokens.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ diff --git a/src/Resources/contao/templates/mod_event_registration_cancel.html5 b/contao/templates/mod_event_registration_cancel.html5 similarity index 100% rename from src/Resources/contao/templates/mod_event_registration_cancel.html5 rename to contao/templates/mod_event_registration_cancel.html5 diff --git a/src/Resources/contao/templates/mod_event_registration_confirm.html5 b/contao/templates/mod_event_registration_confirm.html5 similarity index 100% rename from src/Resources/contao/templates/mod_event_registration_confirm.html5 rename to contao/templates/mod_event_registration_confirm.html5 diff --git a/src/Resources/contao/templates/mod_event_registration_form.html5 b/contao/templates/mod_event_registration_form.html5 similarity index 100% rename from src/Resources/contao/templates/mod_event_registration_form.html5 rename to contao/templates/mod_event_registration_form.html5 diff --git a/src/Resources/contao/templates/mod_event_registration_list.html5 b/contao/templates/mod_event_registration_list.html5 similarity index 100% rename from src/Resources/contao/templates/mod_event_registration_list.html5 rename to contao/templates/mod_event_registration_list.html5 diff --git a/ecs.php b/ecs.php new file mode 100644 index 0000000..7b8ca49 --- /dev/null +++ b/ecs.php @@ -0,0 +1,26 @@ +sets([__DIR__.'/vendor/contao/easy-coding-standard/config/contao.php']); + + $ecsConfig->paths([ + __DIR__.'/src', + __DIR__.'/contao', + ]); + + $ecsConfig->ruleWithConfiguration(HeaderCommentFixer::class, [ + 'header' => "This file is part of the Contao Event Registration extension.\n\n(c) INSPIRED MINDS\n\n@license LGPL-3.0-or-later", + ]); + + $ecsConfig->skip([CommentLengthFixer::class]); + + $ecsConfig->parallel(); + $ecsConfig->lineEnding("\n"); + $ecsConfig->cacheDirectory(sys_get_temp_dir().'/ecs_default_cache'); +}; diff --git a/src/Resources/public/backend.css b/public/backend.css similarity index 100% rename from src/Resources/public/backend.css rename to public/backend.css diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..1de3e05 --- /dev/null +++ b/rector.php @@ -0,0 +1,20 @@ +sets([__DIR__.'/vendor/contao/rector/config/contao.php']); + + $rectorConfig->paths([ + __DIR__.'/src', + __DIR__.'/contao', + ]); + + $rectorConfig->skip([FirstClassCallableRector::class]); + + $rectorConfig->parallel(); + $rectorConfig->cacheDirectory(sys_get_temp_dir().'/rector_cache'); +}; diff --git a/src/Config/ExportConfig.php b/src/Config/ExportConfig.php index baa7c08..fb2eab5 100644 --- a/src/Config/ExportConfig.php +++ b/src/Config/ExportConfig.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ @@ -14,12 +14,9 @@ class ExportConfig { - /** @var int */ - public $pid; + public int $pid; - /** @var string */ - public $delimiter = ','; + public string $delimiter = ','; - /** @var bool */ - public $excelCompatible = false; + public bool $excelCompatible = false; } diff --git a/src/ContaoEventRegistrationBundle.php b/src/ContaoEventRegistrationBundle.php index d20eabf..701faf8 100644 --- a/src/ContaoEventRegistrationBundle.php +++ b/src/ContaoEventRegistrationBundle.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ @@ -16,4 +16,8 @@ class ContaoEventRegistrationBundle extends Bundle { + public function getPath(): string + { + return \dirname(__DIR__); + } } diff --git a/src/ContaoManager/Plugin.php b/src/ContaoManager/Plugin.php index 66489b6..cc09666 100644 --- a/src/ContaoManager/Plugin.php +++ b/src/ContaoManager/Plugin.php @@ -35,11 +35,11 @@ public function getBundles(ParserInterface $parser) ]; } - public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel): ?RouteCollection + public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel): RouteCollection|null { return $resolver - ->resolve(__DIR__.'/../Resources/config/routes.yaml') - ->load(__DIR__.'/../Resources/config/routes.yaml') + ->resolve(__DIR__.'/../../config/routes.yaml') + ->load(__DIR__.'/../../config/routes.yaml') ; } } diff --git a/src/Controller/EventRegistrationExportController.php b/src/Controller/EventRegistrationExportController.php index cf26c81..c154c27 100644 --- a/src/Controller/EventRegistrationExportController.php +++ b/src/Controller/EventRegistrationExportController.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ @@ -14,6 +14,7 @@ use Codefog\HasteBundle\CodefogHasteBundle; use Contao\CalendarEventsModel; +use Contao\CoreBundle\Controller\AbstractBackendController; use Contao\CoreBundle\Exception\PageNotFoundException; use Contao\Message; use Contao\System; @@ -24,34 +25,25 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface; -use Symfony\Component\HttpFoundation\Session\SessionInterface; +use Symfony\Component\HttpKernel\Attribute\AsController; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Contracts\Service\ServiceSubscriberInterface; use Symfony\Contracts\Translation\TranslatorInterface; -use Terminal42\ServiceAnnotationBundle\Annotation\ServiceTag; use Twig\Environment; -/** - * @Route("/contao/eventregistration/export/{eventId}", - * name=EventRegistrationExportController::class, - * defaults={"_scope": "backend"}, - * requirements={"eventId": "\d+"} - * ) - * - * @ServiceTag("controller.service_arguments") - */ -class EventRegistrationExportController +#[AsController] +#[Route( + path: '/contao/eventregistration/export/{eventId}', + name: self::class, + defaults: ['_scope' => 'backend'], +)] +class EventRegistrationExportController extends AbstractBackendController implements ServiceSubscriberInterface { - private $twig; - private $session; - private $exporter; - private $translator; - - public function __construct(Environment $twig, SessionInterface $session, EventRegistrationExport $exporter, TranslatorInterface $translator) - { - $this->twig = $twig; - $this->session = $session; - $this->exporter = $exporter; - $this->translator = $translator; + public function __construct( + private readonly Environment $twig, + private readonly EventRegistrationExport $exporter, + private readonly TranslatorInterface $translator, + ) { } public function __invoke(Request $request, int $eventId): Response @@ -63,7 +55,7 @@ public function __invoke(Request $request, int $eventId): Response } /** @var AttributeBagInterface $backendSession */ - $backendSession = $this->session->getBag('contao_backend'); + $backendSession = $request->getSession()->getBag('contao_backend'); // Get the form $form = $this->buildForm($request, $backendSession); @@ -81,30 +73,32 @@ public function __invoke(Request $request, int $eventId): Response try { $csv = $this->exporter->getCsv($config); - return new Response($csv->getContent(), 200, [ - 'Content-Encoding' => 'none', - 'Content-Type' => 'text/csv; charset=UTF-8', - 'Content-Disposition' => 'attachment; filename="'.$event->alias.'.csv"', - 'Content-Description' => 'File Transfer', - ]); + return new Response( + $csv->toString(), + 200, + [ + 'Content-Encoding' => 'none', + 'Content-Type' => 'text/csv; charset=UTF-8', + 'Content-Disposition' => 'attachment; filename="'.$event->alias.'.csv"', + 'Content-Description' => 'File Transfer', + ], + ); } catch (ExportException $e) { Message::addError($e->getMessage(), 'BE'); } } - return new Response($this->twig->render('@ContaoEventRegistration/be_event_registration_export.html.twig', [ + return $this->render('@ContaoEventRegistration/be_event_registration_export.html.twig', [ + 'headline' => $this->translator->trans('event_registration_export', ['event' => $event->title], 'im_contao_event_registration'), 'backUrl' => System::getReferer(), 'form' => $form->generate(), 'messages' => Message::generate(), - 'eventTitle' => $event->title, - ])); + ]); } private function buildForm(Request $request, AttributeBagInterface $backendSession): BackendForm { - $form = new BackendForm('exportConfig', Request::METHOD_POST, function ($form) use ($request) { - return $request->request->get('FORM_SUBMIT') === $form->getFormId(); - }); + $form = new BackendForm('exportConfig', Request::METHOD_POST, static fn ($form) => $request->request->get('FORM_SUBMIT') === $form->getFormId()); $form->setLegend($this->translator->trans('export', [], 'im_contao_event_registration')); diff --git a/src/Controller/FrontendModule/EventRegistrationCancelController.php b/src/Controller/FrontendModule/EventRegistrationCancelController.php index e4acbbe..0f699e6 100644 --- a/src/Controller/FrontendModule/EventRegistrationCancelController.php +++ b/src/Controller/FrontendModule/EventRegistrationCancelController.php @@ -29,24 +29,20 @@ use Terminal42\NodeBundle\NodeManager; /** - * @FrontendModule(type=EventRegistrationCancelController::TYPE, category="events") + * @FrontendModule(type=EventRegistrationCancelController::TYPE, category="events", template="mod_event_registration_cancel") */ class EventRegistrationCancelController extends AbstractFrontendModuleController { public const TYPE = 'event_registration_cancel'; - public const ACTION = 'cancel'; - private $eventRegistration; - private $nodeManager; - private $translator; - private $simpleTokenParser; + public const ACTION = 'cancel'; - public function __construct(EventRegistration $eventRegistration, NodeManager $nodeManager, TranslatorInterface $translator, SimpleTokenParser $simpleTokenParser) - { - $this->eventRegistration = $eventRegistration; - $this->nodeManager = $nodeManager; - $this->translator = $translator; - $this->simpleTokenParser = $simpleTokenParser; + public function __construct( + private readonly EventRegistration $eventRegistration, + private readonly NodeManager $nodeManager, + private readonly TranslatorInterface $translator, + private readonly SimpleTokenParser $simpleTokenParser, + ) { } protected function getResponse(Template $template, ModuleModel $model, Request $request): Response @@ -71,8 +67,9 @@ protected function getResponse(Template $template, ModuleModel $model, Request $ $event = CalendarEventsModel::findById((int) $registration->pid); $template->event = $event; + $template->registration = $registration; - $template->content = function () use ($model): ?string { + $template->content = function () use ($model): string|null { if ($nodes = StringUtil::deserialize($model->nodes, true)) { return implode('', $this->nodeManager->generateMultiple($nodes)); } @@ -111,7 +108,7 @@ private function processCancel(Template $template, ModuleModel $model, CalendarE $registration->save(); // Send notification - if (!empty($model->nc_notification) && null !== ($notification = Notification::findByPk((int) $model->nc_notification))) { + if (!empty($model->nc_notification) && null !== ($notification = Notification::findById((int) $model->nc_notification))) { $notification->send($tokens); } } diff --git a/src/Controller/FrontendModule/EventRegistrationConfirmController.php b/src/Controller/FrontendModule/EventRegistrationConfirmController.php index 6f9b990..9fb4d24 100644 --- a/src/Controller/FrontendModule/EventRegistrationConfirmController.php +++ b/src/Controller/FrontendModule/EventRegistrationConfirmController.php @@ -29,28 +29,23 @@ use Terminal42\NodeBundle\NodeManager; /** - * @FrontendModule(type=EventRegistrationConfirmController::TYPE, category="events") + * @FrontendModule(type=EventRegistrationConfirmController::TYPE, category="events", template="mod_event_registration_confirm") */ class EventRegistrationConfirmController extends AbstractFrontendModuleController { public const TYPE = 'event_registration_confirm'; - public const ACTION = 'confirm'; - - private $eventRegistration; - private $nodeManager; - private $translator; - private $simpleTokenParser; + public const ACTION = 'confirm'; - public function __construct(EventRegistration $eventRegistration, NodeManager $nodeManager, TranslatorInterface $translator, SimpleTokenParser $simpleTokenParser) - { - $this->eventRegistration = $eventRegistration; - $this->nodeManager = $nodeManager; - $this->translator = $translator; - $this->simpleTokenParser = $simpleTokenParser; + public function __construct( + private readonly EventRegistration $eventRegistration, + private readonly NodeManager $nodeManager, + private readonly TranslatorInterface $translator, + private readonly SimpleTokenParser $simpleTokenParser, + ) { } - protected function getResponse(Template $template, ModuleModel $model, Request $request): ?Response + protected function getResponse(Template $template, ModuleModel $model, Request $request): Response { $uuid = $request->query->get('uuid'); $action = $request->query->get('action'); @@ -72,8 +67,9 @@ protected function getResponse(Template $template, ModuleModel $model, Request $ $event = CalendarEventsModel::findById((int) $registration->pid); $template->event = $event; + $template->registration = $registration; - $template->content = function () use ($model): ?string { + $template->content = function () use ($model): string|null { if ($nodes = StringUtil::deserialize($model->nodes, true)) { return implode('', $this->nodeManager->generateMultiple($nodes)); } @@ -121,7 +117,7 @@ private function processConfirm(Template $template, ModuleModel $model, Calendar $registration->save(); // Send notification - if (!empty($model->nc_notification) && null !== ($notification = Notification::findByPk((int) $model->nc_notification))) { + if (!empty($model->nc_notification) && null !== ($notification = Notification::findById((int) $model->nc_notification))) { $notification->send($tokens); } } diff --git a/src/Controller/FrontendModule/EventRegistrationFormController.php b/src/Controller/FrontendModule/EventRegistrationFormController.php index d7abb2e..cc6ca4c 100644 --- a/src/Controller/FrontendModule/EventRegistrationFormController.php +++ b/src/Controller/FrontendModule/EventRegistrationFormController.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ @@ -21,24 +21,21 @@ use Symfony\Component\HttpFoundation\Response; /** - * @FrontendModule(type=EventRegistrationFormController::TYPE, category="events") + * @FrontendModule(type=EventRegistrationFormController::TYPE, category="events", template="mod_event_registration_form") */ class EventRegistrationFormController extends AbstractFrontendModuleController { public const TYPE = 'event_registration_form'; - private $eventRegistration; - - public function __construct(EventRegistration $eventRegistration) + public function __construct(private readonly EventRegistration $eventRegistration) { - $this->eventRegistration = $eventRegistration; } - protected function getResponse(Template $template, ModuleModel $model, Request $request): ?Response + protected function getResponse(Template $template, ModuleModel $model, Request $request): Response { $event = $this->eventRegistration->getCurrentEvent(); - if (null === $event || !$event->reg_enable) { + if (!$event || !$event->reg_enable) { return new Response(); } diff --git a/src/Controller/FrontendModule/EventRegistrationListController.php b/src/Controller/FrontendModule/EventRegistrationListController.php index 6f98f4e..3aee53d 100644 --- a/src/Controller/FrontendModule/EventRegistrationListController.php +++ b/src/Controller/FrontendModule/EventRegistrationListController.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ @@ -25,28 +25,24 @@ /** * Lists all (confirmed) registrations of an event. * - * @FrontendModule(type=EventRegistrationListController::TYPE, category="events") + * @FrontendModule(type=EventRegistrationListController::TYPE, category="events", template="mod_event_registration_list") */ class EventRegistrationListController extends AbstractFrontendModuleController { public const TYPE = 'event_registration_list'; - private $eventRegistration; - private $labelBuilder; - private $db; - - public function __construct(EventRegistration $eventRegistration, LabelBuilder $labelBuilder, Connection $db) - { - $this->eventRegistration = $eventRegistration; - $this->labelBuilder = $labelBuilder; - $this->db = $db; + public function __construct( + private readonly EventRegistration $eventRegistration, + private readonly LabelBuilder $labelBuilder, + private readonly Connection $db, + ) { } - protected function getResponse(Template $template, ModuleModel $model, Request $request): ?Response + protected function getResponse(Template $template, ModuleModel $model, Request $request): Response { $event = $this->eventRegistration->getCurrentEvent(); - if (null === $event || !$event->reg_enable) { + if (!$event || !$event->reg_enable) { return new Response(); } @@ -59,7 +55,7 @@ protected function getResponse(Template $template, ModuleModel $model, Request $ $registrations = $this->db->fetchAllAssociative($query, [(int) $mainEvent->id]); - if (empty($registrations)) { + if ([] === $registrations) { return new Response(); } @@ -68,7 +64,12 @@ protected function getResponse(Template $template, ModuleModel $model, Request $ $registration['label'] = ($this->labelBuilder)($registration); } - $registration['form_data'] = json_decode($registration['form_data']); + try { + $registration['form_data'] = json_decode((string) $registration['form_data'], null, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException) { + // noop + } + $registration = (object) $registration; } diff --git a/src/DependencyInjection/ContaoEventRegistrationExtension.php b/src/DependencyInjection/ContaoEventRegistrationExtension.php index bbd824f..bf89021 100644 --- a/src/DependencyInjection/ContaoEventRegistrationExtension.php +++ b/src/DependencyInjection/ContaoEventRegistrationExtension.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ @@ -21,7 +21,8 @@ class ContaoEventRegistrationExtension extends Extension { public function load(array $configs, ContainerBuilder $container): void { - $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - $loader->load('services.yaml'); + (new YamlFileLoader($container, new FileLocator(__DIR__.'/../../config'))) + ->load('services.yaml') + ; } } diff --git a/src/EventListener/DataContainer/CalendarEvents/ConfigOnLoadCallbackListener.php b/src/EventListener/DataContainer/CalendarEvents/ConfigOnLoadCallbackListener.php index fe9053f..06cf45e 100644 --- a/src/EventListener/DataContainer/CalendarEvents/ConfigOnLoadCallbackListener.php +++ b/src/EventListener/DataContainer/CalendarEvents/ConfigOnLoadCallbackListener.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ @@ -25,11 +25,8 @@ */ class ConfigOnLoadCallbackListener { - private $eventRegistration; - - public function __construct(EventRegistration $eventRegistration) + public function __construct(private readonly EventRegistration $eventRegistration) { - $this->eventRegistration = $eventRegistration; } public function __invoke(DataContainer $dc): void diff --git a/src/EventListener/DataContainer/CalendarEvents/RegistrationFormOptionsCallbackListener.php b/src/EventListener/DataContainer/CalendarEvents/RegistrationFormOptionsCallbackListener.php index cea9eb3..88c28e4 100644 --- a/src/EventListener/DataContainer/CalendarEvents/RegistrationFormOptionsCallbackListener.php +++ b/src/EventListener/DataContainer/CalendarEvents/RegistrationFormOptionsCallbackListener.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ @@ -22,13 +22,10 @@ */ class RegistrationFormOptionsCallbackListener { - private $db; - private $security; - - public function __construct(Connection $db, Security $security) - { - $this->db = $db; - $this->security = $security; + public function __construct( + private readonly Connection $db, + private readonly Security $security, + ) { } public function __invoke(): array @@ -39,9 +36,7 @@ public function __invoke(): array return []; } - $forms = $this->db->executeQuery('SELECT id, title FROM tl_form ORDER BY title')->fetchAll(); - - if (false === $forms) { + if (!$forms = $this->db->fetchAllAssociative('SELECT id, title FROM tl_form ORDER BY title')) { return []; } diff --git a/src/EventListener/DataContainer/CalendarEvents/RegistrationsButtonCallbackListener.php b/src/EventListener/DataContainer/CalendarEvents/RegistrationsButtonCallbackListener.php index f9488fc..80e8e98 100644 --- a/src/EventListener/DataContainer/CalendarEvents/RegistrationsButtonCallbackListener.php +++ b/src/EventListener/DataContainer/CalendarEvents/RegistrationsButtonCallbackListener.php @@ -28,14 +28,11 @@ */ class RegistrationsButtonCallbackListener { - private $eventRegistration; - - public function __construct(EventRegistration $eventRegistration) + public function __construct(private readonly EventRegistration $eventRegistration) { - $this->eventRegistration = $eventRegistration; } - public function __invoke(array $row, ?string $href, string $label, string $title, ?string $icon, string $attributes): string + public function __invoke(array $row, string|null $href, string $label, string $title, string|null $icon, string $attributes): string { $mainEvent = $this->eventRegistration->getMainEvent(CalendarEventsModel::findById($row['id'])); diff --git a/src/EventListener/DataContainer/EventRegistration/ChildRecordCallbackListener.php b/src/EventListener/DataContainer/EventRegistration/ChildRecordCallbackListener.php index 60d5da5..586c893 100644 --- a/src/EventListener/DataContainer/EventRegistration/ChildRecordCallbackListener.php +++ b/src/EventListener/DataContainer/EventRegistration/ChildRecordCallbackListener.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ @@ -22,11 +22,8 @@ */ class ChildRecordCallbackListener { - private $labelBuilder; - - public function __construct(LabelBuilder $labelBuilder) + public function __construct(private readonly LabelBuilder $labelBuilder) { - $this->labelBuilder = $labelBuilder; } public function __invoke(array $row): string @@ -34,8 +31,13 @@ public function __invoke(array $row): string $label = ($this->labelBuilder)($row); // Show all form data values as a fallback - if (empty($label)) { - $formData = json_decode($row['form_data'] ?? '', true) ?: []; + if (null === $label || '' === $label || '0' === $label) { + try { + $formData = json_decode($row['form_data'] ?? '', true, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException) { + $formData = []; + } + $label = StringUtil::substr(implode(', ', array_filter($formData)), 128); } diff --git a/src/EventListener/DataContainer/EventRegistration/ConfigOnLoadCallbackListener.php b/src/EventListener/DataContainer/EventRegistration/ConfigOnLoadCallbackListener.php index 59f446e..fe34068 100644 --- a/src/EventListener/DataContainer/EventRegistration/ConfigOnLoadCallbackListener.php +++ b/src/EventListener/DataContainer/EventRegistration/ConfigOnLoadCallbackListener.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ diff --git a/src/EventListener/DataContainer/EventRegistration/ConfigOnShowCallbackListener.php b/src/EventListener/DataContainer/EventRegistration/ConfigOnShowCallbackListener.php index af1b214..be1eff7 100644 --- a/src/EventListener/DataContainer/EventRegistration/ConfigOnShowCallbackListener.php +++ b/src/EventListener/DataContainer/EventRegistration/ConfigOnShowCallbackListener.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ @@ -26,8 +26,8 @@ public function __invoke(array $show, array $row, DataContainer $dc): array { foreach ($show as &$c) { foreach ($c as &$table) { - foreach ($table as $k => $v) { - if (str_contains($k, 'form_data')) { + foreach (array_keys($table) as $k) { + if (str_contains((string) $k, 'form_data')) { unset($table[$k]); break; } @@ -35,7 +35,12 @@ public function __invoke(array $show, array $row, DataContainer $dc): array } } - $formData = json_decode($row['form_data'] ?? '', true) ?? []; + try { + $formData = json_decode($row['form_data'] ?? '', true, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException) { + $formData = []; + } + $form = FormModel::findById((int) $row['form']); $t = FormFieldModel::getTable(); @@ -45,7 +50,7 @@ public function __invoke(array $show, array $row, DataContainer $dc): array if (null !== $form && null !== ($formField = FormFieldModel::findBy(["$t.pid = ?", "$t.name = ?"], [$form->id, $name])) && !empty($formField->label)) { $label = $formField->label.' '.$name.''; } - + if (\is_array($value)) { $show['tl_event_registration'][0][$label] = implode("\n", $value); } else { diff --git a/src/EventListener/DataContainer/EventRegistration/ExportButtonCallbackListener.php b/src/EventListener/DataContainer/EventRegistration/ExportButtonCallbackListener.php index 512bbb9..4f4c84b 100644 --- a/src/EventListener/DataContainer/EventRegistration/ExportButtonCallbackListener.php +++ b/src/EventListener/DataContainer/EventRegistration/ExportButtonCallbackListener.php @@ -23,16 +23,13 @@ */ class ExportButtonCallbackListener { - private $requestStack; - private $router; - - public function __construct(RequestStack $requestStack, RouterInterface $router) - { - $this->requestStack = $requestStack; - $this->router = $router; + public function __construct( + private readonly RequestStack $requestStack, + private readonly RouterInterface $router, + ) { } - public function __invoke(?string $href, string $label, string $title, string $class, string $attributes): string + public function __invoke(string|null $href, string $label, string $title, string $class, string $attributes): string { $request = $this->requestStack->getCurrentRequest(); diff --git a/src/EventListener/DataContainer/EventRegistration/FormDataLoadCallbackListener.php b/src/EventListener/DataContainer/EventRegistration/FormDataLoadCallbackListener.php index 4a1907f..da440a1 100644 --- a/src/EventListener/DataContainer/EventRegistration/FormDataLoadCallbackListener.php +++ b/src/EventListener/DataContainer/EventRegistration/FormDataLoadCallbackListener.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ @@ -19,8 +19,16 @@ */ class FormDataLoadCallbackListener { - public function __invoke($value): string + public function __invoke($value): string|null { - return json_encode(json_decode($value ?? '') ?: [], \JSON_PRETTY_PRINT); + if (!$value) { + return null; + } + + try { + return json_encode(json_decode((string) $value, null, 512, JSON_THROW_ON_ERROR) ?: [], JSON_PRETTY_PRINT); + } catch (\JsonException) { + return null; + } } } diff --git a/src/EventListener/DataContainer/EventRegistration/HeaderCallbackListener.php b/src/EventListener/DataContainer/EventRegistration/HeaderCallbackListener.php index 9424e8a..d002c6e 100644 --- a/src/EventListener/DataContainer/EventRegistration/HeaderCallbackListener.php +++ b/src/EventListener/DataContainer/EventRegistration/HeaderCallbackListener.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ @@ -25,13 +25,10 @@ */ class HeaderCallbackListener { - private $helper; - private $trans; - - public function __construct(EventRegistration $helper, TranslatorInterface $trans) - { - $this->helper = $helper; - $this->trans = $trans; + public function __construct( + private readonly EventRegistration $helper, + private readonly TranslatorInterface $trans, + ) { } public function __invoke(array $labels, DataContainer $dc): array diff --git a/src/EventListener/DataContainer/FrontendModule/RegistrationStatusNotificationOptionsCallback.php b/src/EventListener/DataContainer/FrontendModule/RegistrationStatusNotificationOptionsCallback.php index da097fb..078f969 100644 --- a/src/EventListener/DataContainer/FrontendModule/RegistrationStatusNotificationOptionsCallback.php +++ b/src/EventListener/DataContainer/FrontendModule/RegistrationStatusNotificationOptionsCallback.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ diff --git a/src/EventListener/EventParseTemplateListener.php b/src/EventListener/EventParseTemplateListener.php index d5bdbfa..21e3e36 100644 --- a/src/EventListener/EventParseTemplateListener.php +++ b/src/EventListener/EventParseTemplateListener.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ @@ -23,11 +23,8 @@ */ class EventParseTemplateListener { - private $eventRegistration; - - public function __construct(EventRegistration $eventRegistration) + public function __construct(private readonly EventRegistration $eventRegistration) { - $this->eventRegistration = $eventRegistration; } public function __invoke(Template $template): void diff --git a/src/EventListener/EventRegistrationFormListener.php b/src/EventListener/EventRegistrationFormListener.php index c7d5589..470188b 100644 --- a/src/EventListener/EventRegistrationFormListener.php +++ b/src/EventListener/EventRegistrationFormListener.php @@ -20,6 +20,7 @@ use InspiredMinds\ContaoEventRegistration\Model\EventRegistrationModel; use Ramsey\Uuid\Uuid; use Symfony\Component\Security\Core\Security; +use Symfony\Contracts\Translation\TranslatorInterface; /** * Creates a new event registration record. @@ -29,16 +30,14 @@ */ class EventRegistrationFormListener { - private $eventRegistration; - private $security; - - public function __construct(EventRegistration $eventRegistration, Security $security) - { - $this->eventRegistration = $eventRegistration; - $this->security = $security; + public function __construct( + private readonly EventRegistration $eventRegistration, + private readonly Security $security, + private readonly TranslatorInterface $translator, + ) { } - public function __invoke(array &$submittedData, array $formData, ?array $files, array $labels, Form $form): void + public function __invoke(array &$submittedData, array $formData, array|null $files, array &$labels, Form $form): void { if (!$this->eventRegistration->isEventRegistrationForm($form)) { return; @@ -46,7 +45,7 @@ public function __invoke(array &$submittedData, array $formData, ?array $files, $event = $this->getEvent(true); - if (null === $event || !$this->eventRegistration->canRegister($event)) { + if (!$event || !$this->eventRegistration->canRegister($event)) { return; } @@ -59,23 +58,23 @@ public function __invoke(array &$submittedData, array $formData, ?array $files, $registration->uuid = Uuid::uuid4()->toString(); $registration->form = (int) $form->id; $registration->member = $member ? (int) $member->id : 0; - $registration->amount = (int) $submittedData['amount'] ?: 1; - $registration->form_data = json_encode($submittedData); + $registration->amount = max(1, (int) ($submittedData['amount'] ?? 1)); + $registration->form_data = json_encode($submittedData, JSON_THROW_ON_ERROR); $registration->save(); // Inject event registration UUID + $t = EventRegistrationModel::getTable(); $submittedData['event_registration_uuid'] = $registration->uuid; + $labels['event_registration_uuid'] = $this->translator->trans($t.'.uuid.0', [], 'contao_'.$t); } /** * Returns the current event, if applicable. */ - private function getEvent(bool $returnMainEvent = true): ?CalendarEventsModel + private function getEvent(bool $returnMainEvent = true): CalendarEventsModel|null { - $event = $this->eventRegistration->getCurrentEvent(); - - if (null === $event) { + if (!$event = $this->eventRegistration->getCurrentEvent()) { return null; } @@ -90,7 +89,7 @@ private function getEvent(bool $returnMainEvent = true): ?CalendarEventsModel /** * Returns the current frontend user. */ - private function getMember(): ?FrontendUser + private function getMember(): FrontendUser|null { $user = $this->security->getUser(); diff --git a/src/EventListener/NotificationCenter/AddEventDataListener.php b/src/EventListener/NotificationCenter/AddEventDataListener.php index bb7fae3..1c840c3 100644 --- a/src/EventListener/NotificationCenter/AddEventDataListener.php +++ b/src/EventListener/NotificationCenter/AddEventDataListener.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ @@ -25,11 +25,8 @@ */ class AddEventDataListener { - private $eventRegistration; - - public function __construct(EventRegistration $eventRegistration) + public function __construct(private readonly EventRegistration $eventRegistration) { - $this->eventRegistration = $eventRegistration; } public function __invoke(Message $message, array &$tokens, string $language, Gateway $gateway): bool @@ -37,7 +34,7 @@ public function __invoke(Message $message, array &$tokens, string $language, Gat // Get the current event, if applicable. $event = $this->eventRegistration->getCurrentEvent(); - if (null === $event || !$this->isEventRegistrationFormNotification($message)) { + if (!$event || !$this->isEventRegistrationFormNotification($message)) { return true; } diff --git a/src/EventRegistration.php b/src/EventRegistration.php index 45a87aa..f92ed17 100644 --- a/src/EventRegistration.php +++ b/src/EventRegistration.php @@ -37,13 +37,10 @@ class EventRegistration 'endDate', ]; - private $db; - private $bundles; - - public function __construct(Connection $db, array $bundles) - { - $this->db = $db; - $this->bundles = $bundles; + public function __construct( + private readonly Connection $db, + private array $bundles, + ) { } /** @@ -51,21 +48,13 @@ public function __construct(Connection $db, array $bundles) */ public function addTemplateData(Template $template, CalendarEventsModel $event): void { - $template->canRegister = function () use ($event): bool { - return $this->canRegister($event); - }; + $template->canRegister = fn (): bool => $this->canRegister($event); - $template->registrationForm = function () use ($event): string { - return $this->getRegistrationForm($event); - }; + $template->registrationForm = fn (): string => $this->getRegistrationForm($event); - $template->isFull = function () use ($event): bool { - return $this->isFull($event); - }; + $template->isFull = fn (): bool => $this->isFull($event); - $template->registrationCount = function () use ($event): int { - return $this->getRegistrationCount($event); - }; + $template->registrationCount = fn (): int => $this->getRegistrationCount($event); $mainEvent = $this->getMainEvent($event); @@ -145,7 +134,7 @@ public function isEventRegistrationForm($form): bool /** * Returns the current event based on the auto_item. */ - public function getCurrentEvent(): ?CalendarEventsModel + public function getCurrentEvent(): CalendarEventsModel|null { $item = Input::get('auto_item'); @@ -159,7 +148,7 @@ public function getCurrentEvent(): ?CalendarEventsModel /** * Creates a simple token array with the given even data and optionally event registration data. */ - public function getSimpleTokens(CalendarEventsModel $event, EventRegistrationModel $registration = null): array + public function getSimpleTokens(CalendarEventsModel $event, EventRegistrationModel|null $registration = null): array { $tokens = []; @@ -176,7 +165,7 @@ public function getSimpleTokens(CalendarEventsModel $event, EventRegistrationMod $tokens['event_'.$name] = $value; } - if (null !== $registration) { + if ($registration) { Controller::loadDataContainer('tl_event_registration'); $dcaFields = &$GLOBALS['TL_DCA']['tl_event_registration']['fields']; $data = $registration->getCombinedRow(); @@ -217,7 +206,7 @@ public function getMainEvent(CalendarEventsModel $event): CalendarEventsModel return $event; } - $calendar = CalendarModel::findByPk((int) $event->pid); + $calendar = CalendarModel::findById((int) $event->pid); // If the calendar is not configured properly, no main event exists if (null === $calendar || empty($calendar->master)) { @@ -254,14 +243,14 @@ public function createStatusUpdateUrl(CalendarEventsModel $event, EventRegistrat switch ($action) { case EventRegistrationConfirmController::ACTION: if ($calendar->reg_confirm_page) { - $page = PageModel::findByPk($calendar->reg_confirm_page); + $page = PageModel::findById($calendar->reg_confirm_page); } break; case EventRegistrationCancelController::ACTION: if ($calendar->reg_cancel_page) { - $page = PageModel::findByPk($calendar->reg_cancel_page); + $page = PageModel::findById($calendar->reg_cancel_page); } break; diff --git a/src/EventRegistration/LabelBuilder.php b/src/EventRegistration/LabelBuilder.php index dbd64b6..5f4fcd3 100644 --- a/src/EventRegistration/LabelBuilder.php +++ b/src/EventRegistration/LabelBuilder.php @@ -21,17 +21,14 @@ */ class LabelBuilder { - private $framework; - - public function __construct(ContaoFramework $framework) + public function __construct(private readonly ContaoFramework $framework) { - $this->framework = $framework; } /** * @param EventRegistrationModel|array $row */ - public function __invoke($row): ?string + public function __invoke($row): string|null { $this->framework->initialize(); @@ -49,7 +46,12 @@ public function __invoke($row): ?string // Build label according to DCA config if (null !== $list && !empty($list['fields']) && !empty($list['format'])) { $fieldData = []; - $formData = json_decode($row['form_data'] ?? '', true) ?: []; + + try { + $formData = json_decode($row['form_data'] ?? '', true, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException) { + $formData = []; + } foreach ($list['fields'] as $labelField) { if (isset($row[$labelField])) { @@ -69,7 +71,7 @@ public function __invoke($row): ?string if (false === $label) { $label = null; } - } catch (\ValueError $e) { + } catch (\ValueError) { // Ignore value errors } } diff --git a/src/Exception/ExportException.php b/src/Exception/ExportException.php index 75a479e..7870204 100644 --- a/src/Exception/ExportException.php +++ b/src/Exception/ExportException.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ diff --git a/src/Export/EventRegistrationExport.php b/src/Export/EventRegistrationExport.php index f8c8e98..67768bd 100644 --- a/src/Export/EventRegistrationExport.php +++ b/src/Export/EventRegistrationExport.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ @@ -20,19 +20,17 @@ use InspiredMinds\ContaoEventRegistration\Config\ExportConfig; use InspiredMinds\ContaoEventRegistration\Exception\ExportException; use InspiredMinds\ContaoEventRegistration\Model\EventRegistrationModel; +use League\Csv\Writer; class EventRegistrationExport { - private $framework; - private $db; - - public function __construct(ContaoFramework $framework, Connection $db) - { - $this->framework = $framework; - $this->db = $db; + public function __construct( + private readonly ContaoFramework $framework, + private readonly Connection $db, + ) { } - public function getCsv(ExportConfig $config): \League\Csv\Writer + public function getCsv(ExportConfig $config): Writer { $this->framework->initialize(); @@ -42,11 +40,11 @@ public function getCsv(ExportConfig $config): \League\Csv\Writer throw new ExportException('There are no records to export.'); } - $csv = \League\Csv\Writer::createFromFileObject(new \SplTempFileObject(32 * 1024 * 1024)); + $csv = Writer::createFromFileObject(new \SplTempFileObject(32 * 1024 * 1024)); $csv->setDelimiter($config->delimiter ?: ','); if ($config->excelCompatible) { - $csv->setOutputBOM(\League\Csv\Writer::BOM_UTF8); + $csv->setOutputBOM(Writer::BOM_UTF8); } $table = EventRegistrationModel::getTable(); @@ -68,7 +66,7 @@ public function getCsv(ExportConfig $config): \League\Csv\Writer // Retrieve the label for the related record if (isset($config['foreignKey'])) { - [$foreignTable, $foreignLabelField] = explode('.', $config['foreignKey'], 2); + [$foreignTable, $foreignLabelField] = explode('.', (string) $config['foreignKey'], 2); $foreignLabel = $this->db->executeQuery('SELECT '.$foreignLabelField.' FROM '.$foreignTable.' WHERE id = ?', [$value])->fetchOne(); @@ -107,13 +105,17 @@ private function getHeader(Collection $records, array $fieldConfig): array // Go through all form_data entries and add them as the header foreach ($records as $record) { - foreach (json_decode($record->form_data ?? '', true) ?: [] as $key => $value) { - $formDataHeaders[$key] = $key; + try { + foreach (array_keys(json_decode($record->form_data ?? '', true, 512, JSON_THROW_ON_ERROR)) as $key) { + $formDataHeaders[$key] = $key; + } + } catch (\JsonException) { + // noop } } $formDataHeaders = array_diff(array_keys($formDataHeaders), $header); - return array_unique(array_merge($header, $formDataHeaders)); + return array_unique([...$header, ...$formDataHeaders]); } } diff --git a/src/Model/EventRegistrationModel.php b/src/Model/EventRegistrationModel.php index 4642d5e..1b49829 100644 --- a/src/Model/EventRegistrationModel.php +++ b/src/Model/EventRegistrationModel.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ @@ -56,7 +56,7 @@ public function getCombinedRow(): array $formData = $this->decodedFormData; - foreach ($row as $key => $value) { + foreach (array_keys($row) as $key) { unset($formData[$key]); } @@ -70,7 +70,11 @@ public function getCombinedRow(): array private function decodeFormData(): void { if (null === $this->decodedFormData) { - $this->decodedFormData = json_decode($this->form_data ?? '', true) ?: []; + try { + $this->decodedFormData = json_decode($this->form_data ?? '', true, 512, JSON_THROW_ON_ERROR); + } catch (\JsonException) { + $this->decodedFormData = []; + } } } } diff --git a/src/NotificationTypes.php b/src/NotificationTypes.php index 07a57fc..d0303a6 100644 --- a/src/NotificationTypes.php +++ b/src/NotificationTypes.php @@ -5,7 +5,7 @@ /* * This file is part of the Contao Event Registration extension. * - * (c) inspiredminds + * (c) INSPIRED MINDS * * @license LGPL-3.0-or-later */ @@ -15,5 +15,6 @@ class NotificationTypes { public const CONFIRM = 'event_registration_confirm'; + public const CANCEL = 'event_registration_cancel'; } diff --git a/src/Resources/views/be_event_registration_export.html.twig b/templates/be_event_registration_export.html.twig similarity index 53% rename from src/Resources/views/be_event_registration_export.html.twig rename to templates/be_event_registration_export.html.twig index 2618708..fa14606 100644 --- a/src/Resources/views/be_event_registration_export.html.twig +++ b/templates/be_event_registration_export.html.twig @@ -1,13 +1,7 @@ {% trans_default_domain 'contao_default' %} -{% extends "@ContaoCore/Backend/be_page.html.twig" %} +{% extends '@Contao/be_main' %} -{% block headline %} - {{ 'event_registration_export'|trans({event: eventTitle}, 'im_contao_event_registration') }} -{% endblock %} - -{% block error %}{% endblock %} - -{% block main %} +{% block main_content %}
diff --git a/src/Resources/translations/im_contao_event_registration.de.yaml b/translations/im_contao_event_registration.de.yaml similarity index 100% rename from src/Resources/translations/im_contao_event_registration.de.yaml rename to translations/im_contao_event_registration.de.yaml diff --git a/src/Resources/translations/im_contao_event_registration.en.yaml b/translations/im_contao_event_registration.en.yaml similarity index 100% rename from src/Resources/translations/im_contao_event_registration.en.yaml rename to translations/im_contao_event_registration.en.yaml