src/Controller/ComplainController.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Complain;
  4. use App\Form\ComplainType;
  5. use App\Repository\ComplainRepository;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. #[Route('/complain')]
  12. class ComplainController extends AbstractController
  13. {
  14.     #[Route('/'name'app_complain_index'methods: ['GET'])]
  15.     public function index(ComplainRepository $complainRepository): Response
  16.     {
  17.         return $this->render('complain/index.html.twig', [
  18.             'complains' => $complainRepository->findByTypeField('complain'),
  19.             'feedbacks' => $complainRepository->findByTypeField('feedback'),
  20.             'wishes' => $complainRepository->findByTypeField('wish'),
  21.         ]);
  22.     }
  23.     #[Route('/new'name'app_complain_new'methods: ['GET''POST'])]
  24.     public function new(Request $requestEntityManagerInterface $entityManager): Response
  25.     {
  26.         $complain = new Complain();
  27.         $form $this->createForm(ComplainType::class, $complain);
  28.         $form->handleRequest($request);
  29.         if ($form->isSubmitted() && $form->isValid()) {
  30.             $entityManager->persist($complain);
  31.             $entityManager->flush();
  32.             return $this->redirectToRoute('app_complain_index', [], Response::HTTP_SEE_OTHER);
  33.         }
  34.         return $this->renderForm('complain/new.html.twig', [
  35.             'complain' => $complain,
  36.             'form' => $form,
  37.         ]);
  38.     }
  39.     #[Route('/{id}'name'app_complain_show'methods: ['GET'])]
  40.     public function show(Complain $complain): Response
  41.     {
  42.         return $this->render('complain/show.html.twig', [
  43.             'complain' => $complain,
  44.         ]);
  45.     }
  46.     #[Route('/{id}/edit'name'app_complain_edit'methods: ['GET''POST'])]
  47.     public function edit(Request $requestComplain $complainEntityManagerInterface $entityManager): Response
  48.     {
  49.         $form $this->createForm(ComplainType::class, $complain);
  50.         $form->handleRequest($request);
  51.         if ($form->isSubmitted() && $form->isValid()) {
  52.             $entityManager->flush();
  53.             return $this->redirectToRoute('app_complain_index', [], Response::HTTP_SEE_OTHER);
  54.         }
  55.         return $this->renderForm('complain/edit.html.twig', [
  56.             'complain' => $complain,
  57.             'form' => $form,
  58.         ]);
  59.     }
  60.     #[Route('/{id}'name'app_complain_delete'methods: ['POST'])]
  61.     public function delete(Request $requestComplain $complainEntityManagerInterface $entityManager): Response
  62.     {
  63.         if ($this->isCsrfTokenValid('delete'.$complain->getId(), $request->request->get('_token'))) {
  64.             $entityManager->remove($complain);
  65.             $entityManager->flush();
  66.         }
  67.         return $this->redirectToRoute('app_complain_index', [], Response::HTTP_SEE_OTHER);
  68.     }
  69. }