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