src/Controller/Admin/ObjetValeur/PositionController.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin\ObjetValeur;
  3. use App\Entity\Position;
  4. use App\Form\PositionType;
  5. use App\Repository\PositionRepository;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. /**
  11.  * @Route("/position")
  12.  */
  13. class PositionController extends AbstractController
  14. {
  15.     /**
  16.      * @Route("/", name="position_index", methods={"GET"})
  17.      */
  18.     public function index(PositionRepository $positionRepository): Response
  19.     {
  20.         return $this->render('admin/position/index.html.twig', [
  21.             'positions' => $positionRepository->findAll(),
  22.             'countPosition' => count($positionRepository->findAll()),
  23.         ]);
  24.     }
  25.     /**
  26.      * @Route("/new", name="position_new", methods={"GET","POST"})
  27.      */
  28.     public function new(Request $request): Response
  29.     {
  30.         $position = new Position();
  31.         $form $this->createForm(PositionType::class, $position);
  32.         $form->handleRequest($request);
  33.         if ($form->isSubmitted() && $form->isValid()) {
  34.             $entityManager $this->getDoctrine()->getManager();
  35.             $entityManager->persist($position);
  36.             $entityManager->flush();
  37.             $this->addFlash('success','Enregistrement fait avec succès.');
  38.             return $this->redirectToRoute('position_index');
  39.         }
  40.         return $this->render('admin/position/new.html.twig', [
  41.             'position' => $position,
  42.             'form' => $form->createView(),
  43.         ]);
  44.     }
  45.     /**
  46.      * @Route("/{id}", name="position_show", methods={"GET"})
  47.      */
  48.     public function show(Position $position): Response
  49.     {
  50.         return $this->render('admin/position/show.html.twig', [
  51.             'position' => $position,
  52.         ]);
  53.     }
  54.     /**
  55.      * @Route("/{id}/edit", name="position_edit", methods={"GET","POST"})
  56.      */
  57.     public function edit(Request $requestPosition $position): Response
  58.     {
  59.         $form $this->createForm(PositionType::class, $position);
  60.         $form->handleRequest($request);
  61.         if ($form->isSubmitted() && $form->isValid()) {
  62.             $this->getDoctrine()->getManager()->flush();
  63.             return $this->redirectToRoute('position_index');
  64.         }
  65.         return $this->render('admin/position/edit.html.twig', [
  66.             'position' => $position,
  67.             'form' => $form->createView(),
  68.         ]);
  69.     }
  70.     /**
  71.      * @Route("/{id}", name="position_delete", methods={"DELETE"})
  72.      */
  73.     public function delete(Request $requestPosition $position): Response
  74.     {
  75.         if ($this->isCsrfTokenValid('delete'.$position->getId(), $request->request->get('_token'))) {
  76.             $entityManager $this->getDoctrine()->getManager();
  77.             $entityManager->remove($position);
  78.             $entityManager->flush();
  79.         }
  80.         return $this->redirectToRoute('position_index');
  81.     }
  82. }