src/Controller/Page/ClubController.php line 59

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Page;
  3. use App\Entity\Club;
  4. use App\Entity\Country;
  5. use App\Entity\Game;
  6. use App\Form\ClubFilterType;
  7. use App\Renderer\Page as PageRenderer;
  8. use App\Templating\Decorator;
  9. use App\Util\Translation;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use Twig_Error_Loader;
  17. use Twig_Error_Runtime;
  18. use Twig_Error_Syntax;
  19. class ClubController extends AbstractController
  20. {
  21.     /**
  22.      * @var EventDispatcherInterface
  23.      */
  24.     private $eventDispatcher;
  25.     /**
  26.      * @var PageRenderer
  27.      */
  28.     private $pageRenderer;
  29.     /**
  30.      * @var Decorator
  31.      */
  32.     private $decorator;
  33.     public function __construct(
  34.         EventDispatcherInterface $eventDispatcher,
  35.         PageRenderer $pageRenderer,
  36.         Decorator $decorator,
  37.         Translation $translation,
  38.     ) {
  39.         $this->eventDispatcher $eventDispatcher;
  40.         $this->pageRenderer $pageRenderer;
  41.         $this->decorator $decorator;
  42.         $this->translation $translation;
  43.     }
  44.     /**
  45.      * @throws Twig_Error_Loader
  46.      * @throws Twig_Error_Runtime
  47.      * @throws Twig_Error_Syntax
  48.      */
  49.     #[Route(path'/'name'clubs')]
  50.     public function indexAction(Request $request): Response
  51.     {
  52.         $clubs $this->getDoctrine()->getRepository(Club::class)->findAllWithHomematches();
  53.         $countries $this->getDoctrine()->getRepository(Country::class)->findAll();
  54.         $form $this->createForm(ClubFilterType::class);
  55.         return $this
  56.             ->pageRenderer
  57.             ->renderPage(
  58.                 '{clubs}',
  59.                 $this->decorator->getTemplate('pages/clubs_overview.html.twig'),
  60.                 [
  61.                     'clubs' => $clubs,
  62.                     'countries' => $countries,
  63.                     'form' => $form->createView(),
  64.                 ]
  65.             );
  66.     }
  67.     /**
  68.      * @throws Twig_Error_Loader
  69.      * @throws Twig_Error_Runtime
  70.      * @throws Twig_Error_Syntax
  71.      */
  72.     public function detail(int $id): Response
  73.     {
  74.         if (!$club $this->getDoctrine()->getRepository(Club::class)->find($id)) {
  75.             throw new NotFoundHttpException('Could not find club');
  76.         }
  77.         // find matches for this club, only bookalbe matches
  78.         $matches $this->getDoctrine()->getRepository(Game::class)->findMatchesOfClub($clubtrue);
  79.         return $this
  80.             ->pageRenderer
  81.             ->renderPage(
  82.                 '{club}',
  83.                 $this->decorator->getTemplate('pages/clubs_detail.html.twig'),
  84.                 [
  85.                     'club' => $club,
  86.                     'matches' => $matches,
  87.                 ],
  88.                 [],
  89.                 [
  90.                     'metaTitle' => $club->getMetaTitle(),
  91.                     'metaDescription' => $club->getMetaDescription(),
  92.                 ]
  93.             );
  94.     }
  95. }