<?php
namespace App\Controller;
use App\Entity\Seance;
use App\Entity\SeanceDetail;
use App\Form\SeanceDetailType;
use App\Repository\SeanceDetailRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/seance/detail')]
class SeanceDetailController extends AbstractController
{
#[Route('/new/{id}', name: 'app_seance_detail_new', methods: ['GET', 'POST'])]
public function new(Seance $seance,Request $request, SeanceDetailRepository $seanceDetailRepository): Response
{
$seanceDetail = new SeanceDetail();
$form = $this->createForm(SeanceDetailType::class, $seanceDetail);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$seanceDetail->setRefSeance($seance);
$seanceDetailRepository->add($seanceDetail, true);
return $this->redirectToRoute('app_seance_show', ["id" => $seance->getId()], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('seance_detail/new.html.twig', [
'seance' => $seance,
'seance_detail' => $seanceDetail,
'form' => $form,
]);
}
#[Route('/{id}/edit', name: 'app_seance_detail_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, SeanceDetail $seanceDetail, SeanceDetailRepository $seanceDetailRepository): Response
{
$form = $this->createForm(SeanceDetailType::class, $seanceDetail);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$seanceDetailRepository->add($seanceDetail, true);
return $this->redirectToRoute('app_seance_show', ["id" => $seanceDetail->getRefSeance()->getId()], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('seance_detail/edit.html.twig', [
'seance_detail' => $seanceDetail,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_seance_detail_delete', methods: ['POST'])]
public function delete(Request $request, SeanceDetail $seanceDetail, SeanceDetailRepository $seanceDetailRepository): Response
{
if ($this->isCsrfTokenValid('delete'.$seanceDetail->getId(), $request->request->get('_token'))) {
$seanceDetailRepository->remove($seanceDetail, true);
}
return $this->redirectToRoute('app_seance_detail_index', [], Response::HTTP_SEE_OTHER);
}
}