<?php
namespace App\Controller;
use App\Entity\Cron;
use App\Form\CronType;
use App\Repository\CronRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/cron')]
class CronController extends AbstractController
{
#[Route('/', name: 'app_cron_index', methods: ['GET'])]
public function index(CronRepository $cronRepository): Response
{
return $this->render('cron/index.html.twig', [
'crons' => $cronRepository->findAll(),
]);
}
#[Route('/new', name: 'app_cron_new', methods: ['GET', 'POST'])]
public function new(Request $request, CronRepository $cronRepository): Response
{
$cron = new Cron();
$form = $this->createForm(CronType::class, $cron);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$cron->setAuthor($this->getUser()->getEmail());
$cronRepository->add($cron);
return $this->redirectToRoute('app_main', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('cron/new.html.twig', [
'cron' => $cron,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_cron_show', methods: ['GET'])]
public function show(Cron $cron): Response
{
return $this->render('cron/show.html.twig', [
'cron' => $cron,
]);
}
#[Route('/{id}/edit', name: 'app_cron_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, Cron $cron, CronRepository $cronRepository): Response
{
$form = $this->createForm(CronType::class, $cron);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$cronRepository->add($cron);
return $this->redirectToRoute('app_cron_index', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('cron/edit.html.twig', [
'cron' => $cron,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_cron_delete', methods: ['POST'])]
public function delete(Request $request, Cron $cron, CronRepository $cronRepository): Response
{
if ($this->isCsrfTokenValid('delete'.$cron->getId(), $request->request->get('_token'))) {
$cronRepository->remove($cron);
}
return $this->redirectToRoute('app_cron_index', [], Response::HTTP_SEE_OTHER);
}
}