<?php
namespace App\Controller\Page;
use App\Entity\Club;
use App\Entity\Country;
use App\Entity\Game;
use App\Form\CountryFilterType;
use App\Renderer\Page;
use App\Templating\Decorator;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;
class CountryController extends AbstractController
{
/**
* @var Page
*/
protected $renderer;
/**
* @var Decorator
*/
protected $decorator;
/**
* CompetitionController constructor.
*/
public function __construct(Page $renderer, Decorator $decorator)
{
$this->renderer = $renderer;
$this->decorator = $decorator;
}
/**
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
*
* @return Response
*/
public function indexAction()
{
$form = $this->createForm(CountryFilterType::class);
return $this->renderer
->renderPage(
'{countries}',
$this->decorator->getTemplate('pages/countries_overview.html.twig'),
['form' => $form->createView()]
);
}
/**
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
*/
public function detailAction(int $id): Response
{
if (!$country = $this->getDoctrine()->getRepository(Country::class)->find($id)) {
throw new NotFoundHttpException('Could not find country');
}
// get all clubs for this country
$clubs = $this->getDoctrine()->getRepository(Club::class)->findAllWithHomematchesFromCountry($country);
// ophalen alle matches die ook bookable zijn
$matches = $this->getDoctrine()->getRepository(Game::class)->findMatchesOfCountry($country, true);
return $this
->renderer
->renderPage(
'{country}',
$this->decorator->getTemplate('pages/country_detail.html.twig'),
[
'country' => $country,
'clubs' => $clubs,
'matches' => $matches,
],
[],
[
'metaTitle' => $country->getMetaTitle(),
'metaDescription' => $country->getMetaDescription(),
]
);
}
}