<?php
namespace App\Controller\Comun;
use App\Entity\Comun\Festivo;
use App\Form\Comun\FestivoType;
use App\Repository\Comun\FestivoRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\Admin\Empleada;
use App\Repository\Admin\EmpleadaRepository;
#[Route('/comun/festivo')]
class FestivoController extends AbstractController
{
#[Route('/', name: 'app_comun_festivo_index', methods: ['GET', 'POST'])]
public function index(Request $request, FestivoRepository $festivoRepository): Response
{
$empleada = $this->get('security.token_storage')->getToken()->getUser()->getEmpleada();
$festivos = $festivoRepository->findBy(['empleada' => $empleada], ['fecha' => 'ASC']);
$festivo = new Festivo();
$festivo->setEmpleada($empleada);
$form = $this->createForm(FestivoType::class, $festivo);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$festivoRepository->add($festivo);
return $this->redirectToRoute('app_comun_festivo_index', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('comun/festivo/index.html.twig', [
'festivos' => $festivos,
'festivo' => $festivo,
'form' => $form,
'empleada' => $empleada
]);
}
#[Route('/lista/{id}', name: 'app_comun_festivo_lista', methods: ['GET'])]
public function lista(FestivoRepository $festivoRepository, Empleada $empleada): Response
{
$festivos = $festivoRepository->findBy(['empleada' => $empleada], ['fecha' => 'ASC']);
return $this->renderForm('comun/festivo/lista.html.twig', [
'festivos' => $festivos,
]);
}
#[Route('/admin', name: 'app_comun_festivo_admin', methods: ['GET'])]
public function admin(EmpleadaRepository $er): Response
{
$empleadas = $er->findBy([], ['nombre' => 'ASC']);
return $this->renderForm('comun/festivo/admin.html.twig', [
'empleadas' => $empleadas,
]);
}
#[Route('/eliminar/{id}', name: 'app_comun_festivo_eliminar', methods: ['GET'])]
public function eliminar(FestivoRepository $festivoRepository, Festivo $festivo): Response
{
$festivoRepository->remove($festivo);
return $this->redirectToRoute('app_comun_festivo_index', [], Response::HTTP_SEE_OTHER);
}
#[Route('/new', name: 'app_comun_festivo_new', methods: ['GET', 'POST'])]
public function new(Request $request, FestivoRepository $festivoRepository): Response
{
$festivo = new Festivo();
$form = $this->createForm(FestivoType::class, $festivo);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$festivoRepository->add($festivo);
return $this->redirectToRoute('app_comun_festivo_index', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('comun/festivo/new.html.twig', [
'festivo' => $festivo,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_comun_festivo_show', methods: ['GET'])]
public function show(Festivo $festivo): Response
{
return $this->render('comun/festivo/show.html.twig', [
'festivo' => $festivo,
]);
}
#[Route('/{id}/edit', name: 'app_comun_festivo_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, Festivo $festivo, FestivoRepository $festivoRepository): Response
{
$form = $this->createForm(FestivoType::class, $festivo);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$festivoRepository->add($festivo);
return $this->redirectToRoute('app_comun_festivo_index', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('comun/festivo/edit.html.twig', [
'festivo' => $festivo,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_comun_festivo_delete', methods: ['POST'])]
public function delete(Request $request, Festivo $festivo, FestivoRepository $festivoRepository): Response
{
if ($this->isCsrfTokenValid('delete'.$festivo->getId(), $request->request->get('_token'))) {
$festivoRepository->remove($festivo);
}
return $this->redirectToRoute('app_comun_festivo_index', [], Response::HTTP_SEE_OTHER);
}
}