<?php
namespace App\Controller\Front;
use App\Entity\Elearning;
use App\Entity\Faq;
use App\Entity\LiveSession;
use App\Services\PagesManager;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use App\Entity\Post;
use App\Entity\Slider;
use App\Entity\Temoignage;
/**
* Class PaymentController
* @package App\Controller\Front
* @Route("/")
*/
class PagesController extends AbstractController
{
private $pagesManager;
public function __construct(PagesManager $pagesManager)
{
$this->pagesManager = $pagesManager;
}
/**
* @Route("/", name="homepage")
* Method ({"GET", "POST"})
*/
public function homepage(Request $request): Response
{
$em = $this->getDoctrine()->getManager();
$page = $em->getRepository(Post::class)->findOneBySlug('acceuil');
$posts = $em->getRepository(Post::class)->findBy(['type' => 'post', 'status' => 'published'], ['createdAt' => 'DESC'], 5, 0);
$bannerSlides = $em->getRepository(Slider::class)->findByShowIn('home');
$partnerSlides = $em->getRepository(Slider::class)->findByShowIn('partner');
$temoignages = $em->getRepository(Temoignage::class)->findAll();
$videos = $em->getRepository(Elearning::class)->search(1, 2, null);
$formations = $em->getRepository(LiveSession::class)->search(1, 5, null, null);
return $this->render('front/pages/homepage.html.twig', [
'blocs' => $this->pagesManager->getPageBlocs($page),
'slides' => $bannerSlides,
'partners' => $partnerSlides,
'temoignages' => $temoignages,
'posts' => $posts,
'videos' => $videos,
'formations' => $formations
]);
}
/**
* @Route("/faq", name="page_foire_aux_questions")
* Method ({"GET", "POST"})
*/
public function FoireAuxQuestions(): Response
{
$em = $this->getDoctrine()->getManager();
$faqs = $em->getRepository(Faq::class)->findBy([], ['ordre' => 'ASC']);
return $this->render('front/pages/foire_questions.html.twig', [
'faqs' => $faqs
]);
}
/**
* @Route("/faq-footer", name="bloc_faq_footer")
* Method ({"GET", "POST"})
*/
public function faqFooter(): Response
{
$em = $this->getDoctrine()->getManager();
$faqs = $em->getRepository(Faq::class)->findBy(['showInFooter' => true], ['ordre' => 'ASC']);
return $this->render('front/pages/footer_faq.html.twig', [
'faqs' => $faqs
]);
}
/**
* @Route("/mentions-legales", name="page_mentions_legales")
* Method ({"GET", "POST"})
*/
public function mentionsLegales(): Response
{
$em = $this->getDoctrine()->getManager();
$page = $em->getRepository(Post::class)->findOneBySlug('mentions-legales');
return $this->render('front/pages/static-pages.html.twig', [
'page' => $page
]);
}
/**
* @Route("/cgv", name="page_cgv")
* Method ({"GET", "POST"})
*/
public function cgv(): Response
{
$em = $this->getDoctrine()->getManager();
$page = $em->getRepository(Post::class)->findOneBySlug('cgv');
return $this->render('front/pages/static-pages.html.twig', [
'page' => $page
]);
}
/**
* @Route("/prise-en-charge-formation", name="page_prise_en_charge_formation")
* Method ({"GET", "POST"})
*/
public function priseEnChargeFormation(): Response
{
$em = $this->getDoctrine()->getManager();
$page = $em->getRepository(Post::class)->findOneBySlug('prise-en-charge-formation');
return $this->render('front/pages/static-pages.html.twig', [
'page' => $page
]);
}
/**
* @Route("/donnes-personnelles", name="page_vos_donnes_personnelles")
* Method ({"GET", "POST"})
*/
public function personalData(): Response
{
$em = $this->getDoctrine()->getManager();
$page = $em->getRepository(Post::class)->findOneBySlug('personal-data');
return $this->render('front/pages/static-pages.html.twig', [
'page' => $page
]);
}
/**
* @Route("/cookies", name="page_politique_cookies")
* Method ({"GET", "POST"})
*/
public function cookies(): Response
{
$em = $this->getDoctrine()->getManager();
$page = $em->getRepository(Post::class)->findOneBySlug('cookies');
return $this->render('front/pages/static-pages.html.twig', [
'page' => $page
]);
}
/**
* @Route("/presentation-academy", name="page_presentation_academy")
* Method ({"GET", "POST"})
*/
public function presentationAcademy(): Response
{
$em = $this->getDoctrine()->getManager();
$page = $em->getRepository(Post::class)->findOneBySlug('presentation-academy');
return $this->render('front/pages/presentation_academy.html.twig', [
'page' => $page,
'blocs' => $this->pagesManager->getPageBlocs($page)
]);
}
/**
* @Route("/presentation", name="page_presentation")
* Method ({"GET", "POST"})
*/
public function presentation(): Response
{
$em = $this->getDoctrine()->getManager();
$page = $em->getRepository(Post::class)->findOneBySlug('presentation');
return $this->render('front/pages/presentation.html.twig', [
'page' => $page,
'blocs' => $this->pagesManager->getPageBlocs($page)
]);
}
/**
* @Route("/sitemap.xml", name="sitemap", defaults={"_format"="xml"})
*/
public function siteMap(Request $request): Response
{
// Nous récupérons le nom d'hôte depuis l'URL
$hostname = $request->getSchemeAndHttpHost();
$urls = $this->pagesManager->siteMapGenerator();
// Fabrication de la réponse XML
$response = new Response(
$this->renderView('front/pages/sitemap.html.twig', ['urls' => $urls,
'hostname' => $hostname]),
200
);
// Ajout des entêtes
$response->headers->set('Content-Type', 'text/xml');
// On envoie la réponse
return $response;
}
}