<?php
namespace App\Controller;
use App\Entity\Seance;
use App\Entity\Sequence;
use App\Form\SeanceType;
use App\Repository\SeanceRepository;
use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
use Knp\Snappy\Pdf;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/seance')]
class SeanceController extends AbstractController
{
#[Route('/', name: 'app_seance_index', methods: ['GET'])]
public function index(SeanceRepository $seanceRepository): Response
{
return $this->render('seance/index.html.twig', [
'seances' => $seanceRepository->findAll(),
]);
}
#[Route('/new/{id}', name: 'app_seance_new', methods: ['GET', 'POST'])]
public function new(Sequence $sequence,Request $request, SeanceRepository $seanceRepository): Response
{
$seance = new Seance();
$form = $this->createForm(SeanceType::class, $seance);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$seance->setRefSequence($sequence);
$seanceRepository->add($seance, true);
return $this->redirectToRoute('app_sequence_show', ["id" => $sequence->getId()], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('seance/new.html.twig', [
'sequence' => $sequence,
'seance' => $seance,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_seance_show', methods: ['GET'])]
public function show(Seance $seance): Response
{
return $this->render('seance/show.html.twig', [
'seance' => $seance,
]);
}
#[Route('/{id}/edit', name: 'app_seance_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, Seance $seance, SeanceRepository $seanceRepository): Response
{
$form = $this->createForm(SeanceType::class, $seance);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$seanceRepository->add($seance, true);
return $this->redirectToRoute('app_seance_show', ["id" => $seance->getId()], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('seance/edit.html.twig', [
'seance' => $seance,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_seance_delete', methods: ['POST'])]
public function delete(Request $request, Seance $seance, SeanceRepository $seanceRepository): Response
{
if ($this->isCsrfTokenValid('delete'.$seance->getId(), $request->request->get('_token'))) {
$seanceRepository->remove($seance, true);
}
return $this->redirectToRoute('app_seance_index', [], Response::HTTP_SEE_OTHER);
}
#[Route('/pdf/{id}', name: 'app_seance_pdf', methods: ['GET'])]
public function printInPdf(Pdf $pdf,Seance $seance): Response
{
$pageUrl = $this->renderView('pdf/ficheSeance.html.twig', array(
'seance' => $seance,
));
return new PdfResponse(
$pdf->getOutputFromHtml($pageUrl,[
"orientation" => 'Landscape',
"enable-local-file-access" => true,
"enable-javascript" => true
]),
iconv('UTF-8','ASCII//TRANSLIT',$seance->getTitre()) .'.pdf'
);
}
#[Route('/page/{id}', name: 'app_seance_page', methods: ['GET'])]
public function showInPdf(Pdf $pdf,Seance $seance): Response
{
return $this->render('pdf/ficheSeance.html.twig', array(
'seance' => $seance,
));
}
}