Linux SRV-16 6.18.44-paas #1 SMP PREEMPT_DYNAMIC Thu Aug 13 10:08:12 UTC 2026 x86_64
/
srv
/
data
/
web
/
vhosts
/
716cf56cb2.url-de-test.ws
/
htdocs
/
src
/
Controller
/
Back
/
/srv/data/web/vhosts/716cf56cb2.url-de-test.ws/htdocs/src/Controller/Back/SaisonController.php
<?php namespace App\Controller\Back; use App\Entity\Saison; use App\Form\SaisonType; use App\Repository\SaisonRepository; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; /** * @Route("/admin/saisons") */ class SaisonController extends AbstractController { protected $em; protected $saisonRepository; public function __construct(EntityManagerInterface $em, SaisonRepository $saisonRepository) { $this->em = $em; $this->saisonRepository = $saisonRepository; } /** * @Route("/", name="app_search_saison") */ public function index() { $saisons = $this->saisonRepository->findAll(); $events = []; foreach ($saisons as $saison) { $date = $saison->getDate()->format('Y-m-d'); $events[] = [ 'id' => $saison->getId(), 'start' => $saison->getDate()->format('Y-m-d'), 'end' => $saison->getDate()->format('Y-m-d'), 'title' => $saison->getName() == Saison::HAUTE_SAISON ? $saison->getName() : '', 'display' => "background", 'backgroundColor' => $saison->getName() == Saison::HAUTE_SAISON ? 'lightGreen':'white', 'textColor' => 'black' ]; } $data = json_encode($events); return $this->render("Back/Saison/search.html.twig", [ "saisons" => $saisons, 'data' => compact('data'), ]); } /** * @Route("/update", name="app_update_saison") */ public function update(Request $request) { $form = $this->createForm(SaisonType::class); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $start = new \DateTime($form->getData()['date']->format('d-m-Y')); $end = new \DateTime($form->getData()['date2']->format('d-m-Y')); // check all prices defined for dates $existingSaisons = $this->saisonRepository->findAll(); $existingDates = []; foreach ($existingSaisons as $existingSaison) { $existingDates[$existingSaison->getDate()->format('Y-m-d')] = $existingSaison; } $currentDate = $start; while ($currentDate <= $end) { if (isset($existingDates[$currentDate->format('Y-m-d')])) { // update existing saison $existingSaison = $existingDates[$currentDate->format('Y-m-d')]; $existingSaison ->setDate(new \DateTimeImmutable($currentDate->format('d-m-Y'))) ->setName($form->getData()['name']); $this->em->persist($existingSaison); } else { // create new saison for date $saison = new Saison(); $saison->setDate(new \DateTimeImmutable($currentDate->format('d-m-Y'))) ->setName($form->getData()['name']); $this->em->persist($saison); } $currentDate->modify('+1 day'); } $this->em->flush(); $this->addFlash('success', "saison ajouté avec succès"); return $this->redirectToRoute("app_search_saison"); } return $this->render("Back/Saison/create.html.twig", [ "form" => $form->createView() ]); } }