<?php
namespace App\Controller\Page;
use App\Entity\Club;
use App\Entity\Country;
use App\Entity\Game;
use App\Form\ClubFilterType;
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\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;
class ClubController 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
*/
#[Route(path: '/', name: 'clubs')]
public function indexAction(Request $request): Response
{
$clubs = $this->getDoctrine()->getRepository(Club::class)->findAllWithHomematches();
$countries = $this->getDoctrine()->getRepository(Country::class)->findAll();
$form = $this->createForm(ClubFilterType::class);
return $this
->pageRenderer
->renderPage(
'{clubs}',
$this->decorator->getTemplate('pages/clubs_overview.html.twig'),
[
'clubs' => $clubs,
'countries' => $countries,
'form' => $form->createView(),
]
);
}
/**
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
*/
public function detail(int $id): Response
{
if (!$club = $this->getDoctrine()->getRepository(Club::class)->find($id)) {
throw new NotFoundHttpException('Could not find club');
}
// find matches for this club, only bookalbe matches
$matches = $this->getDoctrine()->getRepository(Game::class)->findMatchesOfClub($club, true);
return $this
->pageRenderer
->renderPage(
'{club}',
$this->decorator->getTemplate('pages/clubs_detail.html.twig'),
[
'club' => $club,
'matches' => $matches,
],
[],
[
'metaTitle' => $club->getMetaTitle(),
'metaDescription' => $club->getMetaDescription(),
]
);
}
}