src/Controller/GuestController.php line 42

  1. <?php
  2. namespace App\Controller;
  3. use App\Adapter\EntityAdapter\UserAd;
  4. use App\Entity\Guest;
  5. use App\Form\GuestFormType;
  6. use App\Repository\GuestRepository;
  7. use App\Service\ActiveUserAdService;
  8. use App\Service\FindGroupUserAdService;
  9. use App\Service\FindUserAdService;
  10. use App\Service\GuestParseService;
  11. use App\Service\SendMailUserRegisterService;
  12. use App\Service\SetGroupUserAdService;
  13. use SoapFault;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. class GuestController extends AbstractController
  20. {
  21.     public function __construct(
  22.         private readonly GuestRepository             $guestRepository,
  23.         private readonly GuestParseService           $guestParseService,
  24.         private readonly SendMailUserRegisterService $sendMailUserRegisterService,
  25.         private readonly FindUserAdService           $findUserAdService,
  26.         private readonly ActiveUserAdService         $activeUserAdService,
  27.         private readonly FindGroupUserAdService      $findGroupUserAdService,
  28.         private readonly SetGroupUserAdService       $setGroupUserAdService,
  29.         private readonly ParameterBagInterface       $parameterBag,
  30.     )
  31.     {
  32.     }
  33.     /**
  34.      * @throws SoapFault
  35.      */
  36.     #[Route('/'name'guest_form'methods: ['GET''POST'])]
  37.     public function index(Request $request): Response
  38.     {
  39.         $inputUrlPersonalData $this->parameterBag->get("input_url_personalData");
  40.         $inputCheckboxUrlPersonalData $this->parameterBag->get("input_checkbox_url_personalData");
  41.         $guest = new Guest();
  42.         $form $this->createForm(GuestFormType::class, $guest);
  43.         $siteKey $this->getParameter('google_recaptcha_site_key');
  44.         $form->handleRequest($request);
  45.         if ($form->isSubmitted() && $form->isValid()) {
  46.             $existingGuest $this->guestRepository->findUserByDocumentNumber($guest);
  47.             if ($existingGuest) {
  48.                 $userAd = ($this->findUserAdService)($existingGuest);
  49.                 if (null === $userAd->getUserId()) {
  50.                     ($this->guestParseService)($existingGuest);
  51.                     ($this->sendMailUserRegisterService)($existingGuest$userAd);
  52.                     $this->guestRepository->save($existingGuesttrue);
  53.                     return $this->render('guest/success.html.twig');
  54.                 }
  55.                 return $this->render(
  56.                     'guest/existing.html.twig',
  57.                     [
  58.                         "linkRecoverPass" => $this->parameterBag->get("url_recover_password"),
  59.                     ]
  60.                 );
  61.             }
  62.             $userAd = ($this->findUserAdService)($guest);
  63.             $guest = ($this->guestParseService)($guest);
  64.             if (null !== $userAd->getUserId()) {
  65.                 $guest->setExistUserAd(1);
  66.                 ($this->activeUserAdService)($userAd);
  67.                 $userAd = ($this->findGroupUserAdService)($userAd);
  68.                 ($this->setGroupUserAdService)($userAd);
  69.             }
  70.             $this->guestRepository->save($guesttrue);
  71.             ($this->sendMailUserRegisterService)($guest$userAd);
  72.             return $this->render('guest/success.html.twig');
  73.         }
  74.         return $this->render('guest/index.html.twig', [
  75.             'guest_form' => $form->createView(),
  76.             'site_key' => $siteKey,
  77.             'href_checkbox' => $inputUrlPersonalData,
  78.             'href_p' => $inputCheckboxUrlPersonalData,
  79.         ]);
  80.     }
  81. }