<?php
namespace App\Controller\Page;
use App\Form\GameFilterType;
use App\Renderer\Page;
use App\Templating\Decorator;
use DateInterval;
use DatePeriod;
use DateTime;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;
class GameController extends AbstractController
{
/**
* @var Decorator
*/
protected $decorator;
/**
* @var Page
*/
protected $renderer;
/**
* MatchController constructor.
*/
public function __construct(Decorator $decorator, Page $renderer)
{
$this->decorator = $decorator;
$this->renderer = $renderer;
}
/**
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
*/
public function indexAction(): Response
{
$datePeroid = iterator_to_array(
new DatePeriod(
new DateTime(),
new DateInterval('P1M'),
new DateTime('+1 year')
)
);
$dates = [];
/** @var DateTime $date */
foreach ($datePeroid as $date) {
$dates[$date->format('m-Y')] = $date->getTimestamp();
}
$form = $this->createForm(GameFilterType::class, null, ['dates' => $dates]);
return $this->renderer
->renderPage(
'{matches}',
'pages/matches_overview.html.twig',
['form' => $form->createView()]
);
}
/**
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
*/
#[Route(path: '/favorites', name: 'system_favorites')]
public function favoritesOverviewAction(Request $request): Response
{
return $this
->renderer
->renderPage(
'{favorites}',
$this->decorator->getTemplate('pages/match_favorites.html.twig'),
[]
);
}
}