diff --git a/src/AbstractController.php b/src/AbstractController.php index 6b63ebb7..99939158 100755 --- a/src/AbstractController.php +++ b/src/AbstractController.php @@ -5,6 +5,7 @@ namespace kissj; use DI\Attribute\Inject; +use GuzzleHttp\Utils; use kissj\Entry\EntryStatus; use kissj\Event\Event; use kissj\FileHandler\SaveFileHandler; @@ -68,12 +69,24 @@ protected function redirect( ->withStatus(302); } + protected function getJsonResponseFromException(Response $response, TranslatableException $e): Response + { + return $this->getResponseWithJson( + $response, + [ + 'translationKey' => $e->translationKey, + 'translationMessage' => $this->translator->trans($e->translationKey), + ], + $e->httpStatus, + ); + } + /** * @param array> $json */ protected function getResponseWithJson(Response $response, array $json, int $statusCode = 200): Response { - $encodedJson = guzzleJsonEncode($json); + $encodedJson = Utils::jsonEncode($json); $response->getBody()->write($encodedJson); return $response diff --git a/src/Application/Route.php b/src/Application/Route.php index 8aa8ed39..3275a015 100755 --- a/src/Application/Route.php +++ b/src/Application/Route.php @@ -7,6 +7,7 @@ use DI\Container; use kissj\Deal\DealController; use kissj\Entry\EntryController; +use kissj\Participant\Admin\AdminJsonController; use kissj\ParticipantVendor\ParticipantVendorController; use kissj\Event\EventController; use kissj\Export\ExportController; @@ -373,9 +374,14 @@ public function addRoutesInto(App $app): App $app->group('/event/{eventSlug}', function (RouteCollectorProxy $app) { $app->group('/admin', function (RouteCollectorProxy $app) { $app->group('/{participantId}', function (RouteCollectorProxy $app) { - $app->post('/adminNote', AdminController::class . '::changeAdminNote') + $app->post('/adminNote', AdminJsonController::class . '::changeAdminNote') ->setName('admin-change-note'); }); + + $app->group('/approving', function (RouteCollectorProxy $app) { + $app->post('/approveParticipant/{participantId}', AdminJsonController::class . '::approveParticipant') + ->setName('admin-approve-json'); + }); })->add(AdminsOnlyMiddleware::class)->add(LoggedOnlyMiddleware::class); }); }); diff --git a/src/Mailer/Mailer.php b/src/Mailer/Mailer.php index 32dea71b..ef8907b6 100755 --- a/src/Mailer/Mailer.php +++ b/src/Mailer/Mailer.php @@ -78,13 +78,6 @@ public function sendRegistrationApprovedWithNonFirstPayment( $this->sendMailWithPayment($participant, $payment, 'payment-nonfirst-info'); } - public function sendRegistrationApprovedForSpecialPayment( - Participant $participant, - Payment $payment, - ): void { - $this->sendMailWithPayment($participant, $payment, 'payment-cs-contingent-info'); - } - private function sendMailWithPayment( Participant $participant, Payment $payment, diff --git a/src/Participant/Admin/AdminController.php b/src/Participant/Admin/AdminController.php index ea372209..2a958078 100755 --- a/src/Participant/Admin/AdminController.php +++ b/src/Participant/Admin/AdminController.php @@ -4,7 +4,10 @@ namespace kissj\Participant\Admin; +use kissj\Participant\Guest\Guest; +use kissj\Participant\ParticipantException; use kissj\Participant\Patrol\PatrolLeader; +use kissj\Participant\Troop\TroopParticipant; use RuntimeException; use kissj\AbstractController; use kissj\BankPayment\BankPayment; @@ -258,8 +261,19 @@ public function approveParticipant( ): Response { $participant = $this->participantRepository->getParticipantById($participantId, $event); - $this->participantService->approveRegistration($participant); - $this->logger->info('Approved registration for participant with ID ' . $participant->id); + try { + $participant = $this->participantService->approveRegistration($participant); + + if ($participant instanceof Guest) { + $this->flashMessages->success('flash.success.guestApproved'); + } elseif ($participant instanceof TroopParticipant) { + $this->flashMessages->success('flash.success.tpApproved'); + } else { + $this->flashMessages->success('flash.success.approved'); + } + } catch (ParticipantException $e) { + $this->flashMessages->warning($e->translationKey); + } return $this->redirect($request, $response, 'admin-show-approving'); } diff --git a/src/Participant/Admin/AdminJsonController.php b/src/Participant/Admin/AdminJsonController.php new file mode 100755 index 00000000..d22fc91d --- /dev/null +++ b/src/Participant/Admin/AdminJsonController.php @@ -0,0 +1,59 @@ +participantRepository->getParticipantById($participantId, $event); + + try { + $participant = $this->participantService->approveRegistration($participant); + } catch (ParticipantException $e) { + return $this->getJsonResponseFromException($response, $e); + } + + return $this->getResponseWithJson( + $response, + [ + 'userStatus' => $participant->getUserButNotNull()->status->value, + ] + ); + } + + public function changeAdminNote( + Request $request, + Response $response, + Event $event, + int $participantId, + ): Response { + $participant = $this->participantRepository->getParticipantById($participantId, $event); + + $this->participantService->setAdminNote( + $participant, + $this->getParameterFromBody($request, 'adminNote'), + ); + + return $this->getResponseWithJson($response, ['adminNote' => $participant->adminNote]); + } +} diff --git a/src/Participant/Participant.php b/src/Participant/Participant.php index a1fb5962..cf5c0884 100755 --- a/src/Participant/Participant.php +++ b/src/Participant/Participant.php @@ -193,17 +193,6 @@ public function getNoncanceledPayments(): array }); } - public function isInCzechContingent(): bool - { - return $this->contingent === EventTypeCej::CONTINGENT_CZECHIA; - } - - public function isInSpecialPaymentContingent(): bool - { - return $this->contingent === EventTypeCej::CONTINGENT_CZECHIA - || $this->contingent === EventTypeCej::CONTINGENT_HUNGARY; - } - public function getQrParticipantInfoString(): string { return $this->entryCode; diff --git a/src/Participant/ParticipantException.php b/src/Participant/ParticipantException.php new file mode 100755 index 00000000..24f91b55 --- /dev/null +++ b/src/Participant/ParticipantException.php @@ -0,0 +1,11 @@ +getUserButNotNull()->status === UserStatus::Approved) { - $this->flashMessages->warning('flash.warning.notApproved'); - - return $participant; + throw new ParticipantException('flash.warning.notApproved'); } $this->userService->setUserApproved($participant->getUserButNotNull()); @@ -363,28 +364,18 @@ public function approveRegistration(Participant $participant): Participant if ($participant instanceof Guest) { $this->userService->setUserPaid($participant->getUserButNotNull()); $this->mailer->sendGuestRegistrationFinished($participant); - $this->flashMessages->success('flash.success.guestApproved'); return $participant; } if ($participant instanceof TroopParticipant) { $this->mailer->sendTroopParticipantRegistrationFinished($participant); - $this->flashMessages->success('flash.success.tpApproved'); return $participant; } $payment = $this->paymentService->createAndPersistNewPayment($participant); - - if ($participant->isInCzechContingent()) { - $this->mailer->sendRegistrationApprovedForSpecialPayment($participant, $payment); - } elseif ($participant->isInSpecialPaymentContingent()) { - $this->mailer->sendRegistrationApprovedWithoutPayment($participant); - } else { - $this->mailer->sendRegistrationApprovedWithPayment($participant, $payment); - } - $this->flashMessages->success('flash.success.approved'); + $this->mailer->sendRegistrationApprovedWithPayment($participant, $payment); return $participant; } diff --git a/src/Settings/Settings.php b/src/Settings/Settings.php index e8a9d41a..f2386754 100755 --- a/src/Settings/Settings.php +++ b/src/Settings/Settings.php @@ -50,6 +50,7 @@ use kissj\Middleware\UserAuthenticationMiddleware; use kissj\Orm\Mapper; use kissj\Participant\Admin\AdminController; +use kissj\Participant\Admin\AdminJsonController; use kissj\Participant\Admin\AdminRepository; use kissj\Participant\Admin\AdminService; use kissj\Participant\Guest\GuestRepository; @@ -153,6 +154,7 @@ public function getContainerDefinition(string $envPath, string $envFilename): ar // https://php-di.org/doc/performances.html#optimizing-for-compilation $container = [ AdminController::class => autowire(), + AdminJsonController::class => autowire(), AdminRepository::class => autowire(), AdminService::class => autowire(), AdminsOnlyMiddleware::class => autowire(), diff --git a/src/Templates/translatable/emails/payment-cs-contingent-info.twig b/src/Templates/translatable/emails/payment-cs-contingent-info.twig deleted file mode 100755 index 4b7945d8..00000000 --- a/src/Templates/translatable/emails/payment-cs-contingent-info.twig +++ /dev/null @@ -1,28 +0,0 @@ -{% extends "emails/_mail-layout-no-text.twig" %} - -{% block content %} -

- Ahoj! -

-

- Gratulujeme, právě ti byla schválená registrace na {{ event.readableName }}. Pro úplné dokončení registrace, je potřeba ještě jeden krok a to zaplatit účastnický poplatek do 14 dnů ({{ payment.due|date('d. m. Y') }}). - Zaplacením poplatku zároveň souhlasíš s Podmínkami účasti a GDPR. -

- -

Platební informace:

-

Číslo účtu: {{ payment.accountNumber }}

-

Suma: {{ payment.price }},- {{ payment.currency }}

-

Variabilní symbol: {{ payment.getVariableSymbol }}

-

Poznámka: {{ payment.note }}

- -

- Svou registraci najdeš na adrese - {{ baseHostScheme }}{{ fullRegistrationLink }}. - Pokud máš jakýkoli dotaz, podívej se na naši stránku https://cej24.skauting.cz/ - nebo nám neváhej napsat email na cej2024cz@skaut.cz -

-

- All the best from the team of
- Czech Contingent - CEJ24 -

-{% endblock %} diff --git a/src/TranslatableException.php b/src/TranslatableException.php new file mode 100755 index 00000000..5c3f1b1e --- /dev/null +++ b/src/TranslatableException.php @@ -0,0 +1,17 @@ +