<?php
namespace App\Controller\Page;
use App\Entity\Club;
use App\Entity\Competition;
use App\Entity\Game;
use App\Form\CompetitionFilterType;
use App\Renderer\Page as PageRenderer;
use App\Templating\Decorator;
use App\Util\Translation;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;
class CompetitionController extends AbstractController
{
/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;
/**
* @var PageRenderer
*/
private $pageRenderer;
/**
* @var Decorator
*/
private $decorator;
public function __construct(
EventDispatcherInterface $eventDispatcher,
PageRenderer $pageRenderer,
Decorator $decorator,
Translation $translation,
) {
$this->eventDispatcher = $eventDispatcher;
$this->pageRenderer = $pageRenderer;
$this->decorator = $decorator;
$this->translation = $translation;
}
/**
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
*
* @return Response
*/
public function indexAction()
{
$form = $this->createForm(CompetitionFilterType::class);
return $this->pageRenderer
->renderPage(
'{competitions}',
$this->decorator->getTemplate('pages/competitions_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 (!$competition = $this->getDoctrine()->getRepository(Competition::class)->find($id)) {
throw new NotFoundHttpException('Could not find competition');
}
// clubs ophalen die alleen thuis wedstirjden hebben
$clubs = $this->getDoctrine()->getRepository(Club::class)->findAllToShow($competition);
// alle matcvhes ophalen voor de competitie alleen die nog bookable zijn
$matches = $this->getDoctrine()->getRepository(Game::class)->findMatchesOfCompetition($competition, true);
return $this
->pageRenderer
->renderPage(
'{competition}',
$this->decorator->getTemplate('pages/competitions_detail.html.twig'),
[
'competition' => $competition,
'matches' => $matches,
'clubs' => $clubs,
],
[],
[
'metaTitle' => $competition->getMetaTitle(),
'metaDescription' => $competition->getMetaDescription(),
]
);
}
}