<?php
declare(strict_types=1);
namespace App\Controller\Frontend\Grouping;
use App\Controller\Frontend\Grouping\Service\GroupingShow;
use App\Controller\Shared\MatchPlay\RyderCup\RyderCupResultsData;
use App\Entity\Backend\Competicion;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/agrupacion')]
final class GroupingController extends AbstractController
{
public function __construct(
private readonly GroupingShow $groupingShow,
private readonly EntityManagerInterface $em,
private readonly RyderCupResultsData $ryderCupResultsData,
) {}
#[Route(path: '/{id}', name: 'frontend_grouping_show', methods: ['GET'])]
public function show($id): Response
{
$response = $this->groupingShow->__invoke($id);
if (isset($response["error"]) && $response["error"] && "no grouping" === $response["errorType"]) {
$this->addFlash('error', 'No ha sido posible encontrar la agrupación seleccionada');
return $this->redirect($this->generateUrl('portada'));
}
return $this->render('frontend/Agrupacion/show-grouping.html.twig', [
'grouping' => $response["grouping"],
'competitions' => $response["competitions"],
'miniature' => $response["miniature"],
]);
}
#[Route(path: '/competicion/{id}/resultados', name: 'frontend_grouping_competition_results', methods: ['GET'])]
public function results(int $id): Response
{
$competition = $this->em->getRepository(Competicion::class)->find($id);
if (!$competition || !$this->ryderCupResultsData->canShowRyderCupResults($competition)) {
return $this->render('frontend/Competicion/components/results_ryder.html.twig', [
'results' => ['teams' => [], 'matches' => []]
]);
}
return $this->render('frontend/Competicion/components/results_ryder.html.twig', [
'results' => $this->ryderCupResultsData->__invoke($competition)
]);
}
}