src/Controller/GuestController.php line 42
<?php
namespace App\Controller;
use App\Adapter\EntityAdapter\UserAd;
use App\Entity\Guest;
use App\Form\GuestFormType;
use App\Repository\GuestRepository;
use App\Service\ActiveUserAdService;
use App\Service\FindGroupUserAdService;
use App\Service\FindUserAdService;
use App\Service\GuestParseService;
use App\Service\SendMailUserRegisterService;
use App\Service\SetGroupUserAdService;
use SoapFault;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class GuestController extends AbstractController
{
public function __construct(
private readonly GuestRepository $guestRepository,
private readonly GuestParseService $guestParseService,
private readonly SendMailUserRegisterService $sendMailUserRegisterService,
private readonly FindUserAdService $findUserAdService,
private readonly ActiveUserAdService $activeUserAdService,
private readonly FindGroupUserAdService $findGroupUserAdService,
private readonly SetGroupUserAdService $setGroupUserAdService,
private readonly ParameterBagInterface $parameterBag,
)
{
}
/**
* @throws SoapFault
*/
#[Route('/', name: 'guest_form', methods: ['GET', 'POST'])]
public function index(Request $request): Response
{
$inputUrlPersonalData = $this->parameterBag->get("input_url_personalData");
$inputCheckboxUrlPersonalData = $this->parameterBag->get("input_checkbox_url_personalData");
$guest = new Guest();
$form = $this->createForm(GuestFormType::class, $guest);
$siteKey = $this->getParameter('google_recaptcha_site_key');
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$existingGuest = $this->guestRepository->findUserByDocumentNumber($guest);
if ($existingGuest) {
$userAd = ($this->findUserAdService)($existingGuest);
if (null === $userAd->getUserId()) {
($this->guestParseService)($existingGuest);
($this->sendMailUserRegisterService)($existingGuest, $userAd);
$this->guestRepository->save($existingGuest, true);
return $this->render('guest/success.html.twig');
}
return $this->render(
'guest/existing.html.twig',
[
"linkRecoverPass" => $this->parameterBag->get("url_recover_password"),
]
);
}
$userAd = ($this->findUserAdService)($guest);
$guest = ($this->guestParseService)($guest);
if (null !== $userAd->getUserId()) {
$guest->setExistUserAd(1);
($this->activeUserAdService)($userAd);
$userAd = ($this->findGroupUserAdService)($userAd);
($this->setGroupUserAdService)($userAd);
}
$this->guestRepository->save($guest, true);
($this->sendMailUserRegisterService)($guest, $userAd);
return $this->render('guest/success.html.twig');
}
return $this->render('guest/index.html.twig', [
'guest_form' => $form->createView(),
'site_key' => $siteKey,
'href_checkbox' => $inputUrlPersonalData,
'href_p' => $inputCheckboxUrlPersonalData,
]);
}
}