src/Controller/OperationsController.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Operations;
  4. use App\Form\OperationsType;
  5. use App\Repository\OperationsRepository;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. /**
  12.  * @Route("/operations")
  13.  */
  14. class OperationsController extends AbstractController
  15. {
  16.     /**
  17.      * @Route("/", name="app_operations_index", methods={"GET"})
  18.      */
  19.     public function index(OperationsRepository $operationsRepository): Response
  20.     {
  21.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  22.         return $this->render('operations/index.html.twig', [
  23.             'operations' => $operationsRepository->findAll(),
  24.         ]);
  25.     }
  26.     /**
  27.      * @Route("/new", name="app_operations_new", methods={"GET", "POST"})
  28.      */
  29.     // public function new(Request $request, OperationsRepository $operationsRepository, Security $security): Response
  30.     public function new(Request $requestEntityManagerInterface $entityManager ): Response
  31.     {
  32.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  33.         // $operation = new Operations($security);
  34.         $operation = new Operations();
  35.         $form $this->createForm(OperationsType::class, $operation);
  36.         $form->handleRequest($request);
  37.         if ($form->isSubmitted() && $form->isValid()) {            
  38.             
  39.             // $operationsRepository->add($operation, true, $security);
  40.             $operation->setUsers($this->getUser());
  41.             $entityManager->persist($operation);
  42.             $entityManager->flush();
  43.             return $this->redirectToRoute('app_operations_index', [], Response::HTTP_SEE_OTHER);
  44.         }
  45.         return $this->renderForm('operations/new.html.twig', [
  46.             'operation' => $operation,
  47.             'form' => $form,
  48.         ]);
  49.     }
  50.     /**
  51.      * @Route("/{id}", name="app_operations_show", methods={"GET"})
  52.      */
  53.     public function show(Operations $operation): Response
  54.     {
  55.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  56.         return $this->render('operations/show.html.twig', [
  57.             'operation' => $operation,
  58.         ]);
  59.     }
  60.     /**
  61.      * @Route("/{id}/edit", name="app_operations_edit", methods={"GET", "POST"})
  62.      */
  63.     public function edit(Request $requestOperations $operationEntityManagerInterface $entityManager ): Response
  64.     {
  65.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  66.         $form $this->createForm(OperationsType::class, $operation);
  67.         $form->handleRequest($request);
  68.         if ($form->isSubmitted() && $form->isValid()) {
  69.             // $operationsRepository->add($operation, true);
  70.             $operation->setUpdatedAt(new \DateTimeImmutable());
  71.             $entityManager->persist($operation);
  72.             $entityManager->flush();
  73.             return $this->redirectToRoute('app_operations_index', [], Response::HTTP_SEE_OTHER);
  74.         }
  75.         return $this->renderForm('operations/edit.html.twig', [
  76.             'operation' => $operation,
  77.             'form' => $form,
  78.         ]);
  79.     }
  80.     /**
  81.      * @Route("/{id}", name="app_operations_delete", methods={"POST"})
  82.      */
  83.     public function delete(Request $requestOperations $operationOperationsRepository $operationsRepository): Response
  84.     {
  85.         $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
  86.         if ($this->isCsrfTokenValid('delete'.$operation->getId(), $request->request->get('_token'))) {
  87.             $operationsRepository->remove($operationtrue);
  88.         }
  89.         return $this->redirectToRoute('app_operations_index', [], Response::HTTP_SEE_OTHER);
  90.     }
  91. }