src/Controller/Company/PresentationController.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Company;
  3. use App\Entity\Company\Presentation;
  4. use App\Form\Company\PresentationType;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use App\Repository\Company\PresentationRepository;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. /**
  12.  * @Route("/c/presentation")
  13.  */
  14. class PresentationController extends AbstractController
  15. {
  16.     /**
  17.      * @Route("/", name="company.presentation.index", methods={"GET"})
  18.      */
  19.     public function index(PresentationRepository $presentationRepository): Response
  20.     {
  21.         return $this->render('company/presentation/index.html.twig', [
  22.             'presentations' => $presentationRepository->findAll(),
  23.         ]);
  24.     }
  25.     /**
  26.      * @Route("/new", name="company.presentation.new", methods={"GET","POST"})
  27.      * @IsGranted("IS_AUTHENTICATED_FULLY")
  28.      */
  29.     public function new(Request $request): Response
  30.     {
  31.         $presentation = new Presentation();
  32.         $form $this->createForm(PresentationType::class, $presentation);
  33.         $form->handleRequest($request);
  34.         if ($form->isSubmitted() && $form->isValid()) {
  35.             $entityManager $this->getDoctrine()->getManager();
  36.             $entityManager->persist($presentation);
  37.             $entityManager->flush();
  38.             return $this->redirectToRoute('company.presentation.index');
  39.         }
  40.         return $this->render('company/presentation/new.html.twig', [
  41.             'presentation' => $presentation,
  42.             'form' => $form->createView(),
  43.         ]);
  44.     }
  45.     /**
  46.      * @Route("/{slug}", name="company.presentation.show", methods={"GET"})
  47.      */
  48.     public function show(Presentation $presentation): Response
  49.     {
  50.         return $this->render('company/presentation/show.html.twig', [
  51.             'presentation' => $presentation,
  52.         ]);
  53.     }
  54.     /**
  55.      * @Route("/{slug}/edit", name="company.presentation.edit", methods={"GET","POST"})
  56.      * @IsGranted("IS_AUTHENTICATED_FULLY")
  57.      */
  58.     public function edit(Request $requestPresentation $presentation): Response
  59.     {
  60.         $form $this->createForm(PresentationType::class, $presentation);
  61.         $form->handleRequest($request);
  62.         if ($form->isSubmitted() && $form->isValid()) {
  63.             $this->getDoctrine()->getManager()->flush();
  64.             return $this->redirectToRoute('company.presentation.index');
  65.         }
  66.         return $this->render('company/presentation/edit.html.twig', [
  67.             'presentation' => $presentation,
  68.             'form' => $form->createView(),
  69.         ]);
  70.     }
  71.     /**
  72.      * @Route("/{slug}", name="company.presentation.delete", methods={"DELETE"})
  73.      * @IsGranted("IS_AUTHENTICATED_FULLY")
  74.      */
  75.     public function delete(Request $requestPresentation $presentation): Response
  76.     {
  77.         if ($this->isCsrfTokenValid('delete'.$presentation->getId(), $request->request->get('_token'))) {
  78.             $entityManager $this->getDoctrine()->getManager();
  79.             // $entityManager->remove($presentation);
  80.             $entityManager->flush();
  81.         }
  82.         return $this->redirectToRoute('company.presentation.index');
  83.     }
  84. }