Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 33 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
MovieController | |
0.00% |
0 / 33 |
|
0.00% |
0 / 5 |
182 | |
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 / 4 |
|
0.00% |
0 / 1 |
6 | |||
edit | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
delete | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace App\Controller\Back; |
4 | |
5 | use App\Entity\Movie; |
6 | use App\Form\MovieType; |
7 | use App\Repository\MovieRepository; |
8 | use DateTime; |
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 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; |
14 | |
15 | /** |
16 | * en déclarant la route ici, on préfixe toutes les routes du controller |
17 | * @Route("/back/movie", name="app_back_movie_") |
18 | */ |
19 | class MovieController extends AbstractController |
20 | { |
21 | /** |
22 | * @Route("/", name="index", methods={"GET"}) |
23 | * |
24 | * @ IsGranted("ROLE_ADMIN") |
25 | */ |
26 | public function index(MovieRepository $movieRepository): Response |
27 | { |
28 | return $this->render('back/movie/index.html.twig', [ |
29 | 'movies' => $movieRepository->findAll(), |
30 | ]); |
31 | } |
32 | |
33 | /** |
34 | * @Route("/new", name="new", methods={"GET", "POST"}) |
35 | */ |
36 | public function new(Request $request, MovieRepository $movieRepository): Response |
37 | { |
38 | // TODO : on applique la sécurité |
39 | // il faut le ROLE_ADMIN pour acceder ici |
40 | // $this->denyAccessUnlessGranted("ROLE_ADMIN"); |
41 | // Si aucun voter ne sais gérer le droit, par défault t'a pas le droit |
42 | $this->denyAccessUnlessGranted("MOVIE_1430"); |
43 | |
44 | |
45 | $movie = new Movie(); |
46 | $form = $this->createForm(MovieType::class, $movie); |
47 | $form->handleRequest($request); |
48 | |
49 | if ($form->isSubmitted() && $form->isValid()) { |
50 | $movieRepository->add($movie, true); |
51 | |
52 | return $this->redirectToRoute('app_back_movie_index', [], Response::HTTP_SEE_OTHER); |
53 | } |
54 | |
55 | return $this->renderForm('back/movie/new.html.twig', [ |
56 | 'movie' => $movie, |
57 | 'form' => $form, |
58 | ]); |
59 | } |
60 | |
61 | /** |
62 | * @Route("/{id}", name="show", methods={"GET"}) |
63 | */ |
64 | public function show(?Movie $movie): Response |
65 | { |
66 | if ($movie === null){throw $this->createNotFoundException("ce film n'existe pas");} |
67 | |
68 | return $this->render('back/movie/show.html.twig', [ |
69 | 'movie' => $movie, |
70 | ]); |
71 | } |
72 | |
73 | /** |
74 | * @Route("/{id}/edit", name="edit", methods={"GET", "POST"}) |
75 | */ |
76 | public function edit(Request $request, ?Movie $movie, MovieRepository $movieRepository): Response |
77 | { |
78 | $this->denyAccessUnlessGranted("MOVIE_1430", $movie); |
79 | |
80 | if ($movie === null){throw $this->createNotFoundException("ce film n'existe pas");} |
81 | |
82 | $form = $this->createForm(MovieType::class, $movie); |
83 | $form->handleRequest($request); |
84 | |
85 | if ($form->isSubmitted() && $form->isValid()) { |
86 | $movieRepository->add($movie, true); |
87 | |
88 | return $this->redirectToRoute('app_back_movie_index', [], Response::HTTP_SEE_OTHER); |
89 | } |
90 | |
91 | return $this->renderForm('back/movie/edit.html.twig', [ |
92 | 'movie' => $movie, |
93 | 'form' => $form, |
94 | ]); |
95 | } |
96 | |
97 | /** |
98 | * @Route("/{id}", name="delete", methods={"POST"}) |
99 | */ |
100 | public function delete(Request $request, ?Movie $movie, MovieRepository $movieRepository): Response |
101 | { |
102 | if ($movie === null){throw $this->createNotFoundException("ce film n'existe pas");} |
103 | if ($this->isCsrfTokenValid('delete'.$movie->getId(), $request->request->get('_token'))) { |
104 | $movieRepository->remove($movie, true); |
105 | } |
106 | |
107 | return $this->redirectToRoute('app_back_movie_index', [], Response::HTTP_SEE_OTHER); |
108 | } |
109 | } |