<?php
namespace App\Controller\Company;
use App\Entity\Company\Presentation;
use App\Form\Company\PresentationType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Repository\Company\PresentationRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
/**
* @Route("/c/presentation")
*/
class PresentationController extends AbstractController
{
/**
* @Route("/", name="company.presentation.index", methods={"GET"})
*/
public function index(PresentationRepository $presentationRepository): Response
{
return $this->render('company/presentation/index.html.twig', [
'presentations' => $presentationRepository->findAll(),
]);
}
/**
* @Route("/new", name="company.presentation.new", methods={"GET","POST"})
* @IsGranted("IS_AUTHENTICATED_FULLY")
*/
public function new(Request $request): Response
{
$presentation = new Presentation();
$form = $this->createForm(PresentationType::class, $presentation);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($presentation);
$entityManager->flush();
return $this->redirectToRoute('company.presentation.index');
}
return $this->render('company/presentation/new.html.twig', [
'presentation' => $presentation,
'form' => $form->createView(),
]);
}
/**
* @Route("/{slug}", name="company.presentation.show", methods={"GET"})
*/
public function show(Presentation $presentation): Response
{
return $this->render('company/presentation/show.html.twig', [
'presentation' => $presentation,
]);
}
/**
* @Route("/{slug}/edit", name="company.presentation.edit", methods={"GET","POST"})
* @IsGranted("IS_AUTHENTICATED_FULLY")
*/
public function edit(Request $request, Presentation $presentation): Response
{
$form = $this->createForm(PresentationType::class, $presentation);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('company.presentation.index');
}
return $this->render('company/presentation/edit.html.twig', [
'presentation' => $presentation,
'form' => $form->createView(),
]);
}
/**
* @Route("/{slug}", name="company.presentation.delete", methods={"DELETE"})
* @IsGranted("IS_AUTHENTICATED_FULLY")
*/
public function delete(Request $request, Presentation $presentation): Response
{
if ($this->isCsrfTokenValid('delete'.$presentation->getId(), $request->request->get('_token'))) {
$entityManager = $this->getDoctrine()->getManager();
// $entityManager->remove($presentation);
$entityManager->flush();
}
return $this->redirectToRoute('company.presentation.index');
}
}