<?php
namespace App\Controller;
use App\Entity\Utilisateur;
use App\Form\ContactType;
use App\Form\ProfilType;
use App\Repository\CmsRepository;
use App\Repository\FaqRepository;
use App\Repository\SlideRepository;
use App\Repository\TabRepository;
use App\Service\EmailService;
use App\Service\UtilisateurService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class DefaultController extends AbstractController
{
/**
* @Route("/", name="home")
* @param SlideRepository $slideRepository
* @param TabRepository $tabRepository
* @return Response
*/
public function index(SlideRepository $slideRepository, TabRepository $tabRepository)
{
$slides = $slideRepository->findBy([], ['position' => 'ASC']);
$tabs = $tabRepository->findBy([], ['position' => 'ASC']);
return $this->render('front/index.html.twig', [
'slides' => $slides,
'tabs' => $tabs
]);
}
/**
* @Route("/mes-informations", name="mes_informations")
* @IsGranted(UtilisateurService::ROLE_FILIALE)
* @param Request $request
* @return Response
*/
public function mesInformations(Request $request)
{
/** @var Utilisateur $user */
$user = $this->getUser();
$form = $this->createForm(ProfilType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
return $this->redirectToRoute('mes_informations');
}
return $this->render('default/mes_informations.html.twig', [
'form' => $form->createView()
]);
}
/**
* @Route("/contact", name="contact", methods={"GET","POST"})
* @IsGranted(UtilisateurService::ROLE_FILIALE)
* @param Request $request
* @param EmailService $emailService
* @return Response
*/
public function contact(Request $request, EmailService $emailService)
{
/** @var Utilisateur $user */
$user = $this->getUser();
$form =$this->createForm(ContactType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$emailService->createContact($user, $form->getData());
$this->addFlash('success', 'Le message a bien été envoyé.');
}
return $this->render('parcours/contact.html.twig', [
'form' => $form->createView()
]);
}
/**
* @Route("/mentions-legales", name="mentions_legales", methods={"GET"})
* @param Request $request
* @param CmsRepository $cmsRepository
* @return Response
*/
public function mentions_legales(Request $request, CmsRepository $cmsRepository): Response
{
$content = $cmsRepository->findOneBySlug('mentions-legales');
return $this->render('front/content.html.twig', [
'content' => $content
]);
}
/**
* @Route("/video", name="video", methods={"GET"})
* @param Request $request
* @param CmsRepository $cmsRepository
* @return Response
*/
public function video(Request $request, CmsRepository $cmsRepository): Response
{
$content = $cmsRepository->findOneBySlug('video');
return $this->render('front/content.html.twig', [
'content' => $content
]);
}
/**
* @Route("/guide", name="guide", methods={"GET"})
* @param Request $request
* @param CmsRepository $cmsRepository
* @return Response
*/
public function guide(Request $request, CmsRepository $cmsRepository): Response
{
$content = $cmsRepository->findOneBySlug('guide');
return $this->render('front/content.html.twig', [
'content' => $content
]);
}
/**
* @Route("/nos-valeurs", name="nosvaleurs", methods={"GET"})
* @param Request $request
* @param CmsRepository $cmsRepository
* @return Response
*/
public function nosvaleurs(Request $request, CmsRepository $cmsRepository): Response
{
$content = $cmsRepository->findOneBySlug('nos-valeurs');
return $this->render('front/content.html.twig', [
'content' => $content
]);
}
/**
* @Route("/faq", name="faq")
* @param SlideRepository $slideRepository
* @param TabRepository $tabRepository
* @return Response
*/
public function faq(FaqRepository $faqRepository)
{
$faqs = $faqRepository->findBy([], ['position' => 'ASC']);
return $this->render('front/faq.html.twig', [
'faqs' => $faqs
]);
}
}