src/Controller/SeanceController.php line 57

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Seance;
  4. use App\Entity\Sequence;
  5. use App\Form\SeanceType;
  6. use App\Repository\SeanceRepository;
  7. use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
  8. use Knp\Snappy\Pdf;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. #[Route('/seance')]
  14. class SeanceController extends AbstractController
  15. {
  16.     #[Route('/'name'app_seance_index'methods: ['GET'])]
  17.     public function index(SeanceRepository $seanceRepository): Response
  18.     {
  19.         return $this->render('seance/index.html.twig', [
  20.             'seances' => $seanceRepository->findAll(),
  21.         ]);
  22.     }
  23.     #[Route('/new/{id}'name'app_seance_new'methods: ['GET''POST'])]
  24.     public function new(Sequence $sequence,Request $requestSeanceRepository $seanceRepository): Response
  25.     {
  26.         $seance = new Seance();
  27.         $form $this->createForm(SeanceType::class, $seance);
  28.         $form->handleRequest($request);
  29.         if ($form->isSubmitted() && $form->isValid()) {
  30.             $seance->setRefSequence($sequence);
  31.             $seanceRepository->add($seancetrue);
  32.             return $this->redirectToRoute('app_sequence_show', ["id" => $sequence->getId()], Response::HTTP_SEE_OTHER);
  33.         }
  34.         return $this->renderForm('seance/new.html.twig', [
  35.             'sequence' => $sequence,
  36.             'seance' => $seance,
  37.             'form' => $form,
  38.         ]);
  39.     }
  40.     #[Route('/{id}'name'app_seance_show'methods: ['GET'])]
  41.     public function show(Seance $seance): Response
  42.     {
  43.         return $this->render('seance/show.html.twig', [
  44.             'seance' => $seance,
  45.         ]);
  46.     }
  47.     #[Route('/{id}/edit'name'app_seance_edit'methods: ['GET''POST'])]
  48.     public function edit(Request $requestSeance $seanceSeanceRepository $seanceRepository): Response
  49.     {
  50.         $form $this->createForm(SeanceType::class, $seance);
  51.         $form->handleRequest($request);
  52.         if ($form->isSubmitted() && $form->isValid()) {
  53.             $seanceRepository->add($seancetrue);
  54.             return $this->redirectToRoute('app_seance_show', ["id" => $seance->getId()], Response::HTTP_SEE_OTHER);
  55.         }
  56.         return $this->renderForm('seance/edit.html.twig', [
  57.             'seance' => $seance,
  58.             'form' => $form,
  59.         ]);
  60.     }
  61.     #[Route('/{id}'name'app_seance_delete'methods: ['POST'])]
  62.     public function delete(Request $requestSeance $seanceSeanceRepository $seanceRepository): Response
  63.     {
  64.         if ($this->isCsrfTokenValid('delete'.$seance->getId(), $request->request->get('_token'))) {
  65.             $seanceRepository->remove($seancetrue);
  66.         }
  67.         return $this->redirectToRoute('app_seance_index', [], Response::HTTP_SEE_OTHER);
  68.     }
  69.     #[Route('/pdf/{id}'name'app_seance_pdf'methods: ['GET'])]
  70.     public function printInPdf(Pdf $pdf,Seance $seance): Response
  71.     {
  72.         $pageUrl $this->renderView('pdf/ficheSeance.html.twig', array(
  73.             'seance' => $seance,
  74.         ));
  75.         return new PdfResponse(
  76.             $pdf->getOutputFromHtml($pageUrl,[
  77.                 "orientation" => 'Landscape',
  78.                 "enable-local-file-access" => true,
  79.                 "enable-javascript" => true
  80.             ]),
  81.             iconv('UTF-8','ASCII//TRANSLIT',$seance->getTitre()) .'.pdf'
  82.         );
  83.     }
  84.     #[Route('/page/{id}'name'app_seance_page'methods: ['GET'])]
  85.     public function showInPdf(Pdf $pdf,Seance $seance): Response
  86.     {
  87.         return $this->render('pdf/ficheSeance.html.twig', array(
  88.             'seance' => $seance,
  89.         ));
  90.     }
  91. }