<?php
/**
* @author Antony Tkachenko <at@canaryknight.ru>
*/
namespace App\Controller;
use App\Entity\BlogTag;
use App\Entity\ModulePage;
use App\Helper\LastModifyHelper;
use App\Repository\BlogPostRepository;
use App\Repository\ModulePageRepository;
use App\Repository\ReviewRepository;
use App\Services\WalletRedirect\WalletRedirectService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Annotation\Route;
class MainController extends AbstractController
{
/** @var WalletRedirectService */
private $walletRedirectService;
private LastModifyHelper $tracker;
public function __construct(WalletRedirectService $walletRedirectService, KernelInterface $appKernel)
{
$this->walletRedirectService = $walletRedirectService;
$this->tracker = new LastModifyHelper($appKernel);
}
/**
* @Route("/", name="home", methods={"GET"}, requirements={"_locale":"ru"})
*/
public function index(
ReviewRepository $reviewRepository,
BlogPostRepository $blogPostRepository
): Response
{
$reviews = $reviewRepository->findAllOrdered();
$query = $blogPostRepository->onlyPublishedSelective();
$posts = $query->getQuery()->getResult();
$template = 'main/index.html.twig';
$modified = $this->tracker->get($template);
$response = $this->render($template, [
'reviews' => $reviews,
'posts' => $posts,
'modified' => $modified,
]);
$response->headers->set('Last-Modified', $modified);
return $response;
}
/**
* @Route("/tariff", name="tariff.ru", methods={"GET"}, requirements={"_locale":"ru"})
*/
public function tariff(): Response
{
$redirectRoute = $this->walletRedirectService->getWalletTariffRouteName();
if ($redirectRoute){
return $this->redirectToRoute($redirectRoute);
}
$template = 'main/tariff.html.twig';
$modified = $this->tracker->get($template);
$response = $this->render($template, ['modified' => $modified]);
$response->headers->set('Last-Modified', $modified);
return $response;
}
/**
* @Route("/register", name="register", methods={"GET"})
*/
public function register(): Response
{
$promo = $this->walletRedirectService->checkSource(WalletRedirectService::SOURCE_GPB) ? "Газпромбанк" : "";
$template = 'main/register.html.twig';
$modified = $this->tracker->get($template);
$response = $this->render($template, ['promo' => $promo, 'modified' => $modified]);
$response->headers->set('Last-Modified', $modified);
return $response;
}
/**
* @Route("/sitemap", name="sitemap.page", methods={"GET"}, requirements={"_locale":"ru"})
*/
public function mapPage(
BlogPostRepository $blogPostRepository,
ModulePageRepository $modulePageRepository
): Response
{
$template = 'main/sitemap.html.twig';
$modified = $this->tracker->get($template);
$posts = $blogPostRepository->onlyPublished()->getQuery()->getResult();
$pages = $modulePageRepository->findAllForMenu();
$response = $this->render(
$template, [
'modified' => $modified,
'posts' => $posts,
'pages' => $pages,
]);
$response->headers->set('Last-Modified', $modified);
return $response;
}
/**
* @Route("/", name="home.en", methods={"GET"}, requirements={"_locale":"en"})
*/
public function indexEn()
{
return $this->redirect('/wallet');
}
}