<?php
namespace App\Controller;
use App\Entity\DeathCertificate;
use App\Form\DeathCertificateType;
use App\Repository\DeathCertificateRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Form\TestType;
/**
* @Route("/death/certificate")
*/
class DeathCertificateController extends AbstractController
{
/**
* @Route("/", name="death_certificate_index", methods={"GET"})
*/
public function index(DeathCertificateRepository $deathCertificateRepository): Response
{
return $this->render('death_certificate/index.html.twig', [
'death_certificates' => $deathCertificateRepository->findAll(),
]);
}
/**
* @Route("/new", name="death_certificate_new", methods={"GET","POST"})
*/
public function new(Request $request): Response
{
$deathCertificate = new DeathCertificate();
$form = $this->createForm(DeathCertificateType::class, $deathCertificate);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($deathCertificate);
$entityManager->flush();
return $this->redirectToRoute('death_certificate_index');
}
return $this->render('death_certificate/new.html.twig', [
'death_certificate' => $deathCertificate,
'form' => $form->createView(),
]);
}
/**
* @Route("/complete_death", name="death_test", methods={"GET","POST"})
*/
public function test(Request $request){
$form = $this->createForm(TestType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$id = $form['id']->getData();
$val = intval($id);
return $this->redirectToRoute('death_certificate_edit', [
'id' => $val
]);
}
return $this->render('test/new.html.twig',[
'form'=>$form->createView()
]
);
}
/**
* @Route("/{id}", name="death_certificate_show", methods={"GET"})
*/
public function show(DeathCertificate $deathCertificate): Response
{
return $this->render('death_certificate/show.html.twig', [
'death_certificate' => $deathCertificate,
]);
}
/**
* @Route("/{id}/edit", name="death_certificate_edit", methods={"GET","POST"})
*/
public function edit(Request $request, DeathCertificate $deathCertificate): Response
{
$form = $this->createForm(DeathCertificateType::class, $deathCertificate);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('death_certificate_index');
}
return $this->render('death_certificate/edit.html.twig', [
'death_certificate' => $deathCertificate,
'form' => $form->createView(),
]);
}
/**
* @Route("/{id}", name="death_certificate_delete", methods={"DELETE"})
*/
public function delete(Request $request, DeathCertificate $deathCertificate): Response
{
if ($this->isCsrfTokenValid('delete'.$deathCertificate->getId(), $request->request->get('_token'))) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($deathCertificate);
$entityManager->flush();
}
return $this->redirectToRoute('death_certificate_index');
}
}