src/Controller/Page/CompetitionController.php line 64

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Page;
  3. use App\Entity\Club;
  4. use App\Entity\Competition;
  5. use App\Entity\Game;
  6. use App\Form\CompetitionFilterType;
  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\Response;
  13. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  14. use Twig_Error_Loader;
  15. use Twig_Error_Runtime;
  16. use Twig_Error_Syntax;
  17. class CompetitionController extends AbstractController
  18. {
  19.     /**
  20.      * @var EventDispatcherInterface
  21.      */
  22.     private $eventDispatcher;
  23.     /**
  24.      * @var PageRenderer
  25.      */
  26.     private $pageRenderer;
  27.     /**
  28.      * @var Decorator
  29.      */
  30.     private $decorator;
  31.     public function __construct(
  32.         EventDispatcherInterface $eventDispatcher,
  33.         PageRenderer $pageRenderer,
  34.         Decorator $decorator,
  35.         Translation $translation,
  36.     ) {
  37.         $this->eventDispatcher $eventDispatcher;
  38.         $this->pageRenderer $pageRenderer;
  39.         $this->decorator $decorator;
  40.         $this->translation $translation;
  41.     }
  42.     /**
  43.      * @throws Twig_Error_Loader
  44.      * @throws Twig_Error_Runtime
  45.      * @throws Twig_Error_Syntax
  46.      *
  47.      * @return Response
  48.      */
  49.     public function indexAction()
  50.     {
  51.         $form $this->createForm(CompetitionFilterType::class);
  52.         return $this->pageRenderer
  53.             ->renderPage(
  54.                 '{competitions}',
  55.                 $this->decorator->getTemplate('pages/competitions_overview.html.twig'),
  56.                 ['form' => $form->createView()]
  57.             );
  58.     }
  59.     /**
  60.      * @throws Twig_Error_Loader
  61.      * @throws Twig_Error_Runtime
  62.      * @throws Twig_Error_Syntax
  63.      */
  64.     public function detailAction(int $id): Response
  65.     {
  66.         if (!$competition $this->getDoctrine()->getRepository(Competition::class)->find($id)) {
  67.             throw new NotFoundHttpException('Could not find competition');
  68.         }
  69.         // clubs ophalen die alleen thuis wedstirjden hebben
  70.         $clubs $this->getDoctrine()->getRepository(Club::class)->findAllToShow($competition);
  71.         // alle matcvhes ophalen voor de competitie alleen die nog bookable zijn
  72.         $matches $this->getDoctrine()->getRepository(Game::class)->findMatchesOfCompetition($competitiontrue);
  73.         return $this
  74.             ->pageRenderer
  75.             ->renderPage(
  76.                 '{competition}',
  77.                 $this->decorator->getTemplate('pages/competitions_detail.html.twig'),
  78.                 [
  79.                     'competition' => $competition,
  80.                     'matches' => $matches,
  81.                     'clubs' => $clubs,
  82.                 ],
  83.                 [],
  84.                 [
  85.                     'metaTitle' => $competition->getMetaTitle(),
  86.                     'metaDescription' => $competition->getMetaDescription(),
  87.                 ]
  88.             );
  89.     }
  90. }