2020-01-30 11:28:24 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
|
|
|
use App\Entity\Poll;
|
2020-10-26 11:39:04 +01:00
|
|
|
use App\Form\PollType;
|
|
|
|
use App\Repository\PollRepository;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
2020-01-30 11:28:24 +01:00
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2020-04-26 12:33:11 +02:00
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2020-10-26 11:39:04 +01:00
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
2020-01-30 11:28:24 +01:00
|
|
|
|
|
|
|
/**
|
2020-10-26 11:39:04 +01:00
|
|
|
* @Route("/poll")
|
2020-01-30 11:28:24 +01:00
|
|
|
*/
|
2020-10-26 11:39:04 +01:00
|
|
|
class PollController extends AbstractController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @Route("/", name="poll_index", methods={"GET"})
|
|
|
|
*/
|
|
|
|
public function index(PollRepository $pollRepository): Response
|
|
|
|
{
|
|
|
|
return $this->render('poll/index.html.twig', [
|
|
|
|
'polls' => $pollRepository->findAll(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/new", name="poll_new", methods={"GET","POST"})
|
|
|
|
*/
|
|
|
|
public function new(Request $request): Response
|
|
|
|
{
|
|
|
|
$poll = new Poll();
|
|
|
|
$form = $this->createForm(PollType::class, $poll);
|
|
|
|
$form->handleRequest($request);
|
|
|
|
|
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
|
|
$entityManager = $this->getDoctrine()->getManager();
|
|
|
|
$entityManager->persist($poll);
|
|
|
|
$entityManager->flush();
|
|
|
|
|
|
|
|
return $this->redirectToRoute('poll_index');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render('poll/new.html.twig', [
|
|
|
|
'poll' => $poll,
|
|
|
|
'form' => $form->createView(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/{id}", name="poll_show", methods={"GET"})
|
|
|
|
*/
|
|
|
|
public function show(Poll $poll): Response
|
|
|
|
{
|
|
|
|
return $this->render('poll/show.html.twig', [
|
|
|
|
'poll' => $poll,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/{id}/edit", name="poll_edit", methods={"GET","POST"})
|
|
|
|
*/
|
|
|
|
public function edit(Request $request, Poll $poll): Response
|
|
|
|
{
|
|
|
|
$form = $this->createForm(PollType::class, $poll);
|
|
|
|
$form->handleRequest($request);
|
|
|
|
|
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
|
|
$this->getDoctrine()->getManager()->flush();
|
|
|
|
|
|
|
|
return $this->redirectToRoute('poll_index');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render('poll/edit.html.twig', [
|
|
|
|
'poll' => $poll,
|
|
|
|
'form' => $form->createView(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/{id}", name="poll_delete", methods={"DELETE"})
|
|
|
|
*/
|
|
|
|
public function delete(Request $request, Poll $poll): Response
|
|
|
|
{
|
|
|
|
if ($this->isCsrfTokenValid('delete'.$poll->getId(), $request->request->get('_token'))) {
|
|
|
|
$entityManager = $this->getDoctrine()->getManager();
|
|
|
|
$entityManager->remove($poll);
|
|
|
|
$entityManager->flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->redirectToRoute('poll_index');
|
|
|
|
}
|
2020-01-30 11:28:24 +01:00
|
|
|
}
|