<?php
namespace App\Controller\Front;
use App\Entity\Elearning;
use App\Entity\LiveSession;
use App\Entity\Post;
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 DateTime;
class FormationLiveController extends AbstractController
{
/**
* @Route("/nos-formations-live", name="page_nos_formations_live")
* Method ({"GET", "POST"})
*/
public function index(Request $request, PagesManager $pagesManager): Response
{
$em = $this->getDoctrine()->getManager();
$page = $request->get('page', 1);
$limit = $request->get('limit', 9);
$keywords = $request->get('keywords', '');
$date = ($request->get('date', null)) ? DateTime::createFromFormat('d/m/Y', $request->get('date', null)) : DateTime::createFromFormat('d/m/Y', date('d/m/Y'));
$formations = $em->getRepository(LiveSession::class)->search($page, $limit, $keywords, $date);
$formationPage = $em->getRepository(Post::class)->findOneBySlug('nos-formations-live');
$videos = $em->getRepository(Elearning::class)->search(1, 3, null);
return $this->render('front/formation_live/index.html.twig', [
'blocs' => $pagesManager->getPageBlocs($formationPage),
'formations' => $formations,
'videos' => $videos,
'page' => ($page+1),
'limit' => $limit
]);
}
/**
* @Route("/nos-formations-live-paginate", name="page_nos_formations_live_paginate", options={"expose"=true})
* Method ({"GET", "POST"})
*/
public function paginate(Request $request): Response
{
$em = $this->getDoctrine()->getManager();
$page = $request->get('page', 1);
$limit = $request->get('limit', 3);
$keywords = $request->get('keywords', '');
$date = ($request->get('date', null)) ? DateTime::createFromFormat('d/m/Y', $request->get('date', null)) : DateTime::createFromFormat('d/m/Y', date('d/m/Y'));
$formations = $em->getRepository(LiveSession::class)->search($page, $limit, $keywords, $date);
return $this->render('front/formation_live/formation_live_ajax.html.twig', [
'formations' => $formations
]);
}
/**
* @Route("/formation-live/{slug}", name="page_formation_live_single")
* Method ({"GET", "POST"})
*/
public function show($slug, PagesManager $pagesManager): Response
{
$em = $this->getDoctrine()->getManager();
$formation = $em->getRepository(LiveSession::class)->findOneBySlug($slug);
$toSee = $em->getRepository(LiveSession::class)->getToSee($formation->getCategory(), $slug);
$formationPage = $em->getRepository(Post::class)->findOneBySlug('nos-formations-live');
return $this->render('front/formation_live/show.html.twig', [
'blocs' => $pagesManager->getPageBlocs($formationPage),
'formation' => $formation,
'toSee' => $toSee,
]);
}
}