src/Controller/Frontend/ExternalTournamentController.php line 30

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller\Frontend;
  4. use App\Entity\Backend\ExternalCompetition;
  5. use App\Entity\Backend\ExternalCompetitionPlayer;
  6. use App\Entity\Gestion\Ranking;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\RedirectResponse;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. /**
  13.  * @Route("/tour-external")
  14.  */
  15. final class ExternalTournamentController extends AbstractController
  16. {
  17.     public function __construct(
  18.         private readonly EntityManagerInterface $em
  19.     )
  20.     {
  21.     }
  22.     /**
  23.      * @Route("/{id}/{publi}", name="_external_tournament", requirements={"id": "\d+"}, options={"expose"=true}, defaults={"publi" = 0})
  24.      */
  25.     public function tournament(int $idint $publi): RedirectResponse|Response
  26.     {
  27.         $externalCompetition $this->em->getRepository(ExternalCompetition::class)->findOneBy([
  28.             'id' => $id,
  29.             'deleted_at' => null,
  30.         ]);
  31.         if (!$externalCompetition) {
  32.             $this->addFlash('error''El torneo buscado no existe');
  33.             return $this->redirect($this->generateUrl('portada'));
  34.         }
  35.         $players $this->em->getRepository(ExternalCompetitionPlayer::class)->resultsByExternalCompetitionForFrontend($id);
  36.         $rankings $this->em->getRepository(Ranking::class)->getRankingsByExternalCompetition($id);
  37.         $menu = [];
  38.         $order '';
  39.         if (count($players) > 0) {
  40.             $menu = [
  41.                 'inscritos' => [
  42.                     'name' => 'user',
  43.                     'clase' => 'user',
  44.                     'posN' => 1,
  45.                     'posL' => 3,
  46.                 ],
  47.             ];
  48.             $order 'inscritos';
  49.         }
  50.         return $this->render('frontend/Competicion/external-competition.html.twig', [
  51.             'competition' => $externalCompetition,
  52.             'players' => $players,
  53.             'rankings' => $rankings,
  54.             'menu' => $menu,
  55.             'orden' => $order,
  56.             'publi' => $publi,
  57.         ]);
  58.     }
  59. }