<?php
namespace App\Controller\Front;
use App\Entity\Email;
use App\Entity\FrontPage;
use App\Form\ContactType;
use App\Repository\EmailRepository;
use App\Service\EmailService;
use App\Service\FrontService;
use App\Service\ParameterService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class FrontPageController extends AbstractController
{
public function __construct(
private readonly FrontService $frontService,
private readonly ParameterService $parameterService,
){}
#[Route('/contact', name: 'app_front_contact')]
public function contact(Request $request,
EmailService $emailService,
EmailRepository $emailRepository,
ParameterService $parameterService
): Response
{
$form = $this->createForm(ContactType::class);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()) {
$from = $parameterService->getContactSMTPAddressFrom();
$to = trim($request->request->get('email'));
$societyName = $parameterService->getSocietyInfos()['name'];
$subject = $societyName. " Contact Message ";
$content = $this->renderView('email/contact.html.twig', ['data' => $form->getData()]);
// compose and save Email
$email = $emailService->composeMail($from, $to, $subject, $content, null, $from);
$email->setType(Email::CONTACT);
$emailRepository->save($email, true);
return $this->redirectToRoute('app_front_contact'); // success send page
}
return $this->renderForm('front/subpage/contact.html.twig', [
'form' => $form,
'society' => $this->parameterService->getSocietyParameters(),
'social_networks' => $this->frontService->getSocialNetworks(),
'agencies' => $this->frontService->getAgencies(),
'currencies' => $this->frontService->getCurrencies(),
'home' => null,
'tracking_tools' => $this->frontService->getTrackingTools()
]);
}
#[Route('/infos/{slug}', name: 'app_main_static_page', methods: ['GET'])]
public function getFrontPage(FrontPage $frontPage): Response
{
$contentPage = $frontPage->getContent();
$titlePage = $frontPage->getTitle();
return $this->render('front/subpage/static_page.html.twig', [
'content' => $contentPage,
'title' => $titlePage,
'society' => $this->parameterService->getSocietyParameters(),
'social_networks' => $this->frontService->getSocialNetworks(),
'agencies' => $this->frontService->getAgencies(),
'currencies' => $this->frontService->getCurrencies(),
'home' => null,
]);
}
}