Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 29 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
SeasonController | |
0.00% |
0 / 29 |
|
0.00% |
0 / 5 |
110 | |
0.00% |
0 / 1 |
index | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
new | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
show | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
edit | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
delete | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace App\Controller\Back; |
4 | |
5 | use App\Entity\Season; |
6 | use App\Form\SeasonType; |
7 | use App\Repository\SeasonRepository; |
8 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
9 | use Symfony\Component\HttpFoundation\Request; |
10 | use Symfony\Component\HttpFoundation\Response; |
11 | use Symfony\Component\Routing\Annotation\Route; |
12 | |
13 | /** |
14 | * @Route("/back/season", name="app_back_season_") |
15 | */ |
16 | class SeasonController extends AbstractController |
17 | { |
18 | /** |
19 | * @Route("/", name="index", methods={"GET"}) |
20 | */ |
21 | public function index(SeasonRepository $seasonRepository): Response |
22 | { |
23 | return $this->render('back/season/index.html.twig', [ |
24 | 'seasons' => $seasonRepository->findAll(), |
25 | ]); |
26 | } |
27 | |
28 | /** |
29 | * @Route("/new", name="new", methods={"GET", "POST"}) |
30 | */ |
31 | public function new(Request $request, SeasonRepository $seasonRepository): Response |
32 | { |
33 | $season = new Season(); |
34 | $form = $this->createForm(SeasonType::class, $season); |
35 | $form->handleRequest($request); |
36 | |
37 | if ($form->isSubmitted() && $form->isValid()) { |
38 | $seasonRepository->add($season, true); |
39 | |
40 | // TODO j'ajoute un flash message de réussite |
41 | $this->addFlash("success", "Votre Saison a bien été ajoutée."); |
42 | |
43 | return $this->redirectToRoute('app_back_season_index', [], Response::HTTP_SEE_OTHER); |
44 | } |
45 | |
46 | return $this->renderForm('back/season/new.html.twig', [ |
47 | 'season' => $season, |
48 | 'form' => $form, |
49 | ]); |
50 | } |
51 | |
52 | /** |
53 | * @Route("/{id}", name="show", methods={"GET"}) |
54 | */ |
55 | public function show(Season $season): Response |
56 | { |
57 | return $this->render('back/season/show.html.twig', [ |
58 | 'season' => $season, |
59 | ]); |
60 | } |
61 | |
62 | /** |
63 | * @Route("/{id}/edit", name="edit", methods={"GET", "POST"}) |
64 | */ |
65 | public function edit(Request $request, Season $season, SeasonRepository $seasonRepository): Response |
66 | { |
67 | $form = $this->createForm(SeasonType::class, $season); |
68 | $form->handleRequest($request); |
69 | |
70 | if ($form->isSubmitted() && $form->isValid()) { |
71 | $seasonRepository->add($season, true); |
72 | |
73 | return $this->redirectToRoute('app_back_season_index', [], Response::HTTP_SEE_OTHER); |
74 | } |
75 | |
76 | return $this->renderForm('back/season/edit.html.twig', [ |
77 | 'season' => $season, |
78 | 'form' => $form, |
79 | ]); |
80 | } |
81 | |
82 | /** |
83 | * @Route("/{id}", name="delete", methods={"POST"}) |
84 | */ |
85 | public function delete(Request $request, Season $season, SeasonRepository $seasonRepository): Response |
86 | { |
87 | if ($this->isCsrfTokenValid('delete'.$season->getId(), $request->request->get('_token'))) { |
88 | $seasonRepository->remove($season, true); |
89 | } |
90 | |
91 | return $this->redirectToRoute('app_back_season_index', [], Response::HTTP_SEE_OTHER); |
92 | } |
93 | } |