<?php
namespace App\Controller\Frontend;
use App\Controller\Controller;
use App\Entity\FranceWiki;
use App\Entity\PortugalWiki;
use App\Entity\ProUser;
use App\Entity\RecruitmentWiki;
use App\Entity\Wiki;
use App\Form\Type\Frontend\ContactProType;
use App\Form\Type\Frontend\ContactType;
use App\Form\Type\Frontend\RecruitmentApplyType;
use App\Form\Type\Frontend\SaleAutoProType;
use App\Form\Upload\Uploader;
use App\Mailer\Mailer;
use App\Parameter\Provider;
use App\Repository\FranceWikiRepository;
use App\Repository\PortugalWikiRepository;
use App\Repository\RecruitmentWikiRepository;
use App\Repository\WikiRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Mime\Email;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
/**
* Controller for the landing pages needing only one action.
*/
class LandingController extends Controller
{
public function __construct(
private readonly TranslatorInterface $translator,
private readonly SessionInterface $session,
private readonly FormFactoryInterface $formFactory,
private readonly Mailer $mailer,
private readonly string $defaultFrom,
private readonly string $contactTo,
private readonly string $contactOptimvoTo,
private readonly Provider $provider)
{
}
public function contactAction(Request $request)
{
$form = $this->createForm(ContactType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
$this->mailer->send(
$this->renderView('/Mail/contact.html.twig', ['data' => $data]),
sprintf('Nouveau message de %s %s', $data['firstname'], $data['lastname']),
$this->contactTo,
$this->defaultFrom
);
$this->session->getFlashbag()->add('success', $this->translator->trans('frontend.landing.contact.flash.success', [], 'landing'));
return $this->redirect($this->generateUrl('frontend_contact'));
}
return $this->render('/Frontend/landing/contact.html.twig', ['form' => $form->createView()]);
}
public function wikiListPortugalAction(PortugalWikiRepository $portugalWikiRepository)
{
$wikis = $portugalWikiRepository->findBy(['published' => true], ['createdAt' => 'DESC']);
return $this->render('/Frontend/wiki/list_pt.html.twig', ['wikis' => $wikis]);
}
public function wikiListFranceAction(FranceWikiRepository $franceWikiRepository, $limit = null)
{
$wikis = $franceWikiRepository->findListByType(Wiki::TYPE_B2C, $limit);
return $this->render('/Frontend/wiki/list_fr.html.twig', ['wikis' => $wikis]);
}
public function wikiListFranceProAction(FranceWikiRepository $franceWikiRepository, $limit = null)
{
$wikis = $franceWikiRepository->findListByType(Wiki::TYPE_B2B, $limit);
return $this->render('/Frontend/wiki/list_fr.html.twig', ['wikis' => $wikis]);
}
public function wikiAction(EntityManagerInterface $entityManager, WikiRepository $wikiRepository, FranceWikiRepository $franceWikiRepository, $maker, $model)
{
$wikis = null;
$user = $this->getUser();
if (null === $user && 'private' === $this->session->get('dimension', 'private')) {
$userType = Wiki::TYPE_B2C;
} else {
$userType = Wiki::TYPE_B2B;
}
if (null === $model) {
$wiki = $wikiRepository->findOneBySlug($maker);
$imageAlt = $maker;
} else {
$wiki = $wikiRepository->findOneBySlugAndParentSlug($model, $maker);
$imageAlt = $maker.' '.$model;
}
if (null === $wiki || !$wiki->isPublished()) {
throw new NotFoundHttpException();
}
$template = '/Frontend/wiki/view.html.twig';
if ($wiki instanceof FranceWiki) {
$template = '/Frontend/wiki/franceView.html.twig';
$wikis = $franceWikiRepository->findLastWikis($model, $userType, 3);
if (Wiki::TYPE_B2C == $userType) {
$wiki->addOneToNbViews();
} elseif (Wiki::TYPE_B2B == $userType) {
$wiki->addOneToNbViewsPro();
}
$entityManager->flush();
}
if ($wiki instanceof PortugalWiki) {
$template = '/Frontend/wiki/portugalView.html.twig';
}
return $this->render($template, ['wiki' => $wiki, 'imageAlt' => $imageAlt, 'wikis' => $wikis]);
}
public function recruitmentWikiAction(RecruitmentWikiRepository $recruitmentWikiRepository)
{
$wikis = $recruitmentWikiRepository->findBy(['published' => true], ['createdAt' => 'DESC']);
return $this->render('/Frontend/wiki/recruitment.html.twig', ['wikis' => $wikis]);
}
public function recruitmentApplyAction(Request $request, TranslatorInterface $translator, Uploader $uploader, ?Wiki $wiki = null)
{
$form = $this->formFactory->create(RecruitmentApplyType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
$recipients = $this->provider->getParameterValue('recruitment.emails');
$files = $uploader->handleUpload($form);
$filePathCV = $files['cv']->getPathName();
$fileNameCV = $data['firstName'].'-'.$data['lastName'].'-CV.'.$files['cv']->guessExtension();
if (null !== $data['coverLetter']) {
$filePathLM = $files['coverLetter']->getPathName();
$fileNameLM = $data['firstName'].'-'.$data['lastName'].'-LM.'.$files['coverLetter']->guessExtension();
}
$message = new Email();
$message->to(...$this->provider->getParameterValue('recruitment.emails'));
$message->from($data['email']);
$message->subject('[VPauto] Candidature - '.$data['firstName'].' '.$data['lastName'].' - '.$data['job']);
$body = $data['message'];
$message->html($body);
try {
$message->attachFromPath($filePathCV, $fileNameCV);
if (null !== $data['coverLetter']) {
$message->attachFromPath($filePathLM, $fileNameLM);
}
} catch (\Exception $e) {
var_dump($e->getMessage());
exit;
}
$this->mailer->sendMessage($message);
$this->session->getFlashbag()->add('success', $translator->trans('frontend.wiki.recruitment.success'));
return $this->redirect($this->generateUrl('frontend_wiki_recruitment'));
}
return $this->render('/Frontend/wiki/recruitment_apply.html.twig', [
'wiki' => $wiki,
'form' => $form->createView(),
]);
}
public function contactProAction(Request $request)
{
$form = $this->createForm(ContactProType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
$this->mailer->send(
$this->renderView('/Mail/contact_pro.html.twig', ['data' => $data]),
sprintf('Nouveau message de %s %s', $data['firstname'], $data['lastname']),
$this->contactTo,
$this->defaultFrom
);
$this->session->getFlashbag()->add('success', $this->translator->trans('frontend.landing.contact.flash.success', [], 'landing'));
return $this->redirect($this->generateUrl('frontend_contact_pro'));
}
return $this->render('/Frontend/landing/contact-pro.html.twig', ['form' => $form->createView()]);
}
public function saleAutoProAction(Request $request)
{
$form = $this->createForm(SaleAutoProType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
$this->mailer->send(
$this->renderView('/Mail/contact_optimvo.html.twig', ['data' => $data]),
sprintf('Nouveau message de %s', $data['lastname']),
$this->contactOptimvoTo,
$this->defaultFrom
);
$this->session->getFlashbag()->add('success', $this->translator->trans('frontend.landing.contact.flash.success', [], 'landing'));
return $this->redirect($this->generateUrl('frontend_sale_auto_pro'));
}
return $this->render('/Frontend/landing/sale-auto-pro.html.twig', ['form' => $form->createView()]);
}
public function salesRoomsProAction()
{
return $this->render('/Frontend/landing/accessMap/access-map.html.twig', [
'type' => 'pro',
]);
}
public function roomLorientAction()
{
return $this->render('/Frontend/landing/accessMap/room-lorient.html.twig', [
'type' => 'pro',
]);
}
public function roomNantesAction()
{
return $this->render('/Frontend/landing/accessMap/room-nantes.html.twig', [
'type' => 'pro',
]);
}
public function roomRouenAction()
{
return $this->render('/Frontend/landing/accessMap/room-rouen.html.twig', [
'type' => 'pro',
]);
}
public function roomLyonAction()
{
return $this->render('/Frontend/landing/accessMap/room-lyon.html.twig', [
'type' => 'pro',
]);
}
public function roomParisAction()
{
return $this->render('/Frontend/landing/accessMap/room-paris.html.twig', [
'type' => 'pro',
]);
}
public function roomBordeauxAction()
{
return $this->render('/Frontend/landing/accessMap/room-bordeaux.html.twig', [
'type' => 'pro',
]);
}
public function roomMarseilleAction()
{
return $this->render('/Frontend/landing/accessMap/room-marseille.html.twig', [
'type' => 'pro',
]);
}
public function roomLilleAction()
{
return $this->render('/Frontend/landing/accessMap/room-lille.html.twig', [
'type' => 'pro',
]);
}
public function roomSeneffeAction()
{
return $this->render('/Frontend/landing/accessMap/room-seneffe.html.twig', [
'type' => 'pro',
]);
}
public function roomSetubalAction()
{
return $this->render('/Frontend/landing/accessMap/room-setubal.html.twig', [
'type' => 'pro',
]);
}
public function roomMadridAction()
{
return $this->render('/Frontend/landing/accessMap/room-madrid.html.twig', [
'type' => 'pro',
]);
}
public function privacyPolicyAction(Request $request)
{
if (null === $type = $this->getUser() instanceof ProUser ? 'pro' : null) {
$type = $request->query->get('type') ?? null;
}
return $this->render('/Frontend/landing/privacy-policy.html.twig', [
'type' => $type,
]);
}
/**
* Available templates :
* - /Frontend/landing/cgv/fr/content.html.twig
* - /Frontend/landing/cgv/be/content.fr.html.twig
* - /Frontend/landing/cgv/be/content.nl.html.twig
* - /Frontend/landing/cgv/be/content.en.html.twig
* - /Frontend/landing/cgv/es/content.es.html.twig
* - /Frontend/landing/cgv/es/content.en.html.twig
* - /Frontend/landing/cgv/pt/content.pt.html.twig
* - /Frontend/landing/cgv/pt/content.en.html.twig.
*/
public function countryCGVAction(Request $request, string $country, Environment $twig)
{
$locale = $request->getLocale();
$template = 'content.html.twig';
if ($twig->getLoader()->exists("/Frontend/landing/cgv/{$country}/content.{$locale}.html.twig")) {
$template = "content.{$locale}.html.twig";
} elseif ($twig->getLoader()->exists("/Frontend/landing/cgv/{$country}/content.en.html.twig")) {
$template = 'content.en.html.twig';
}
return $this->render("/Frontend/landing/cgv/{$country}/{$template}");
}
public function cookiesAction()
{
return $this->render('/Frontend/landing/cookies.html.twig');
}
}