src/Controller/LogMailHistoryController.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\SiteMailLogs;
  4. use App\Form\LogMailSentsType;
  5. use Doctrine\ORM\EntityManagerInterface;
  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. use App\Form\Filters\LogMailSentFilter;
  11. use App\Repository\LogMailSentsRepository;
  12. #[Route('/log/mail/sent')]
  13. class LogMailHistoryController extends AbstractController
  14. {
  15.     #[Route('/'defaults: ['page' => '1'], methods: ['GET'], name'log_mail_sent_index')]
  16.     #[Route('/page/{page<[1-9]\d*>}'methods: ['GET'], name'log_mail_sent_index_paginated')]
  17.     #[Cache(smaxage10)]
  18.     public function index(Request $request,int $page,EntityManagerInterface $entityManager,LogMailSentsRepository $logMailSentsRepository): Response
  19.     {
  20.         $params $request->query->all();
  21.         $filter = [];
  22.         $filterForm $this->createForm(LogMailSentFilter::class, $params);
  23.         
  24.         $logHistory $logMailSentsRepository->adminPaginatorFetchAll($page$params);
  25.         return $this->render('log-mail-sent/index.html.twig', [
  26.             'paginator' => $logHistory,
  27.             'filter' => $params,
  28.             'form' => $filterForm->createView(),
  29.         ]);
  30.     }
  31.     #[Route('/new'name'log_mail_sent_new'methods: ['GET''POST'])]
  32.     public function new(Request $requestEntityManagerInterface $entityManager): Response
  33.     {
  34.         $logMailSent = new SiteMailLogs();
  35.         $form $this->createForm(LogMailSentsType::class, $logMailSent);
  36.         $form->handleRequest($request);
  37.         if ($form->isSubmitted() && $form->isValid()) {
  38.             $entityManager->persist($logMailSent);
  39.             $entityManager->flush();
  40.             return $this->redirectToRoute('log_mail_sent_index', [], Response::HTTP_SEE_OTHER);
  41.         }
  42.         return $this->renderForm('log-mail-sent/new.html.twig', [
  43.             'log_mail_sent' => $logMailSent,
  44.             'form' => $form,
  45.         ]);
  46.     }
  47.     #[Route('/{id}'name'log_mail_sent_show'methods: ['GET'])]
  48.     public function show(SiteMailLogs $logMailSent): Response
  49.     {
  50.         return $this->render('log-mail-sent/show.html.twig', [
  51.             'log_mail_sent' => $logMailSent,
  52.         ]);
  53.     }
  54.     #[Route('/{id}/edit'name'log_mail_sent_edit'methods: ['GET''POST'])]
  55.     public function edit(Request $requestSiteMailLogs $logMailSentEntityManagerInterface $entityManager): Response
  56.     {
  57.         $form $this->createForm(LogMailSentsType::class, $logMailSent);
  58.         $form->handleRequest($request);
  59.         if ($form->isSubmitted() && $form->isValid()) {
  60.             $entityManager->flush();
  61.             $this->addFlash('success''Update successfully.');
  62.             return $this->redirectToRoute('log_mail_sent_index', [], Response::HTTP_SEE_OTHER);
  63.         }
  64.         return $this->renderForm('log-mail-sent/edit.html.twig', [
  65.             'log_mail_sent' => $logMailSent,
  66.             'form' => $form,
  67.         ]);
  68.     }
  69.     #[Route('/{id}'name'log_mail_sent_delete'methods: ['POST'])]
  70.     public function delete(Request $requestSiteMailLogs $logMailSentEntityManagerInterface $entityManager): Response
  71.     {
  72.         if ($this->isCsrfTokenValid('delete'.$logMailSent->getId(), $request->request->get('_token'))) {
  73.             $entityManager->remove($logMailSent);
  74.             $entityManager->flush();
  75.         }
  76.         $this->addFlash('error''Delete successfully.');
  77.         return $this->redirectToRoute('log_mail_sent_index', [], Response::HTTP_SEE_OTHER);
  78.     }
  79. }