src/Controller/Frontend/Grouping/GroupingController.php line 25

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller\Frontend\Grouping;
  4. use App\Controller\Frontend\Grouping\Service\GroupingShow;
  5. use App\Controller\Shared\MatchPlay\RyderCup\RyderCupResultsData;
  6. use App\Entity\Backend\Competicion;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. #[Route('/agrupacion')]
  12. final class GroupingController extends AbstractController
  13. {
  14. public function __construct(
  15. private readonly GroupingShow $groupingShow,
  16. private readonly EntityManagerInterface $em,
  17. private readonly RyderCupResultsData $ryderCupResultsData,
  18. ) {}
  19. #[Route(path: '/{id}', name: 'frontend_grouping_show', methods: ['GET'])]
  20. public function show($id): Response
  21. {
  22. $response = $this->groupingShow->__invoke($id);
  23. if (isset($response["error"]) && $response["error"] && "no grouping" === $response["errorType"]) {
  24. $this->addFlash('error', 'No ha sido posible encontrar la agrupación seleccionada');
  25. return $this->redirect($this->generateUrl('portada'));
  26. }
  27. return $this->render('frontend/Agrupacion/show-grouping.html.twig', [
  28. 'grouping' => $response["grouping"],
  29. 'competitions' => $response["competitions"],
  30. 'miniature' => $response["miniature"],
  31. ]);
  32. }
  33. #[Route(path: '/competicion/{id}/resultados', name: 'frontend_grouping_competition_results', methods: ['GET'])]
  34. public function results(int $id): Response
  35. {
  36. $competition = $this->em->getRepository(Competicion::class)->find($id);
  37. if (!$competition || !$this->ryderCupResultsData->canShowRyderCupResults($competition)) {
  38. return $this->render('frontend/Competicion/components/results_ryder.html.twig', [
  39. 'results' => ['teams' => [], 'matches' => []]
  40. ]);
  41. }
  42. return $this->render('frontend/Competicion/components/results_ryder.html.twig', [
  43. 'results' => $this->ryderCupResultsData->__invoke($competition)
  44. ]);
  45. }
  46. }