<?php
namespace App\Controller;
use App\Entity\Complain;
use App\Form\ComplainType;
use App\Repository\ComplainRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/complain')]
class ComplainController extends AbstractController
{
#[Route('/', name: 'app_complain_index', methods: ['GET'])]
public function index(ComplainRepository $complainRepository): Response
{
return $this->render('complain/index.html.twig', [
'complains' => $complainRepository->findByTypeField('complain'),
'feedbacks' => $complainRepository->findByTypeField('feedback'),
'wishes' => $complainRepository->findByTypeField('wish'),
]);
}
#[Route('/new', name: 'app_complain_new', methods: ['GET', 'POST'])]
public function new(Request $request, EntityManagerInterface $entityManager): Response
{
$complain = new Complain();
$form = $this->createForm(ComplainType::class, $complain);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($complain);
$entityManager->flush();
return $this->redirectToRoute('app_complain_index', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('complain/new.html.twig', [
'complain' => $complain,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_complain_show', methods: ['GET'])]
public function show(Complain $complain): Response
{
return $this->render('complain/show.html.twig', [
'complain' => $complain,
]);
}
#[Route('/{id}/edit', name: 'app_complain_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, Complain $complain, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(ComplainType::class, $complain);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();
return $this->redirectToRoute('app_complain_index', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('complain/edit.html.twig', [
'complain' => $complain,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_complain_delete', methods: ['POST'])]
public function delete(Request $request, Complain $complain, EntityManagerInterface $entityManager): Response
{
if ($this->isCsrfTokenValid('delete'.$complain->getId(), $request->request->get('_token'))) {
$entityManager->remove($complain);
$entityManager->flush();
}
return $this->redirectToRoute('app_complain_index', [], Response::HTTP_SEE_OTHER);
}
}