src/Controller/Page/CountryController.php line 45

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\CountryFilterType;
  7. use App\Renderer\Page;
  8. use App\Templating\Decorator;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Twig_Error_Loader;
  12. use Twig_Error_Runtime;
  13. use Twig_Error_Syntax;
  14. class CountryController extends AbstractController
  15. {
  16.     /**
  17.      * @var Page
  18.      */
  19.     protected $renderer;
  20.     /**
  21.      * @var Decorator
  22.      */
  23.     protected $decorator;
  24.     /**
  25.      * CompetitionController constructor.
  26.      */
  27.     public function __construct(Page $rendererDecorator $decorator)
  28.     {
  29.         $this->renderer $renderer;
  30.         $this->decorator $decorator;
  31.     }
  32.     /**
  33.      * @throws Twig_Error_Loader
  34.      * @throws Twig_Error_Runtime
  35.      * @throws Twig_Error_Syntax
  36.      *
  37.      * @return Response
  38.      */
  39.     public function indexAction()
  40.     {
  41.         $form $this->createForm(CountryFilterType::class);
  42.         return $this->renderer
  43.             ->renderPage(
  44.                 '{countries}',
  45.                 $this->decorator->getTemplate('pages/countries_overview.html.twig'),
  46.                 ['form' => $form->createView()]
  47.             );
  48.     }
  49.     /**
  50.      * @throws Twig_Error_Loader
  51.      * @throws Twig_Error_Runtime
  52.      * @throws Twig_Error_Syntax
  53.      */
  54.     public function detailAction(int $id): Response
  55.     {
  56.         if (!$country $this->getDoctrine()->getRepository(Country::class)->find($id)) {
  57.             throw new NotFoundHttpException('Could not find country');
  58.         }
  59.         // get all clubs for this country
  60.         $clubs $this->getDoctrine()->getRepository(Club::class)->findAllWithHomematchesFromCountry($country);
  61.         // ophalen alle matches die ook bookable zijn
  62.         $matches $this->getDoctrine()->getRepository(Game::class)->findMatchesOfCountry($countrytrue);
  63.         return $this
  64.             ->renderer
  65.             ->renderPage(
  66.                 '{country}',
  67.                 $this->decorator->getTemplate('pages/country_detail.html.twig'),
  68.                 [
  69.                     'country' => $country,
  70.                     'clubs' => $clubs,
  71.                     'matches' => $matches,
  72.                 ],
  73.                 [],
  74.                 [
  75.                     'metaTitle' => $country->getMetaTitle(),
  76.                     'metaDescription' => $country->getMetaDescription(),
  77.                 ]
  78.             );
  79.     }
  80. }