src/Controller/HomeController.php line 38
<?php
namespace App\Controller;
use App\Repository\ArticleRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use App\Service\TextManipulationService;
use App\Service\ConstantsService;
use App\Service\GetImageSizeService;
use App\Service\LinkedDatasJsonService;
use App\Service\ConfigurationService;
use Knp\Component\Pager\PaginatorInterface;
class HomeController extends AbstractController
{
private $articleRepository;
private $textManipulationService;
private $paginator;
public function __construct(
ArticleRepository $articleRepository,
TextManipulationService $textManipulationService,
PaginatorInterface $paginator,
GetImageSizeService $getImageSizeService,
ConfigurationService $configurationService,
LinkedDatasJsonService $linkedDatasJsonService
){
$this->articleRepository = $articleRepository;
$this->textManipulationService = $textManipulationService;
$this->paginator = $paginator;
$this->getImageSizeService = $getImageSizeService;
$this->configurationService = $configurationService;
$this->linkedDatasJsonService = $linkedDatasJsonService;
}
#[Route('/{page}', name: 'home', requirements: ['page'=> '\d+'])]
public function index(int $page = 1)
{
$lastArticle = $this->articleRepository->findOneBy(array(), array("creationDate" => "DESC"));
if ($lastArticle !== null && $lastArticle->getMedia() !== null) {
$lastArticleImageSize = $this->getImageSizeService->getSize("build/images/".$lastArticle->getMedia()->getMediaName());
} else {
$lastArticleImageSize = null;
}
$featuredArticles = $this->articleRepository->findBy(array("featured" => 1), array("creationDate" => "DESC"));
$articlesList = $this->articleRepository->findBy(array("featured" => 0), array("creationDate" => "DESC"));
$articles = $this->paginator->paginate(
$articlesList,
$page,
ConstantsService::ARTICLES_PER_PAGE
);
$articles->setCustomParameters([
'align' => 'center', # center|right (for template: twitter_bootstrap_v4_pagination)
'style' => 'bottom',
'class' => 'text-dark',
]);
//dump($this->configurationService->getConfiguration());
//die();
$jsonld = $this->linkedDatasJsonService-> getWebPageJsonLd(
$this->configurationService->getConfiguration()->getWebsiteName(),
$this->configurationService->getConfiguration()->getMetaDescription(),
$this->configurationService->getConfiguration()->getAuthor()
);
//return $this->render('home/index.html.twig', [ TRY SOME OTHER STYLE IN TEMPLATE
$response = $this->render('home/twoColumns.html.twig', [
'controller_name' => 'HomeController',
'lastArticle' => $lastArticle,
'featuredArticles' => $featuredArticles,
'articles' => $articles,
'textManipulationService' => $this->textManipulationService,
'page' => $page,
"lastArticleImageSize" => $lastArticleImageSize,
"jsonld" => $jsonld
]);
$response->setSharedMaxAge(3600);
return $response;
}
#[Route('amp/{page}', name: 'home_amp', requirements: ['page'=> '\d+'])]
public function indexAmp(int $page = 1)
{
$lastArticle = $this->articleRepository->findOneBy(array(), array("creationDate" => "DESC"));
$featuredArticles = $this->articleRepository->findBy(array("featured" => 1), array("creationDate" => "DESC"));
$articlesList = $this->articleRepository->findBy(array("featured" => 0), array("creationDate" => "DESC"));
if ($lastArticle->getMedia() !== null) {
$lastArticleImageSize = $this->getImageSizeService->getSize("build/images/".$lastArticle->getMedia()->getMediaName());
} else {
$lastArticleImageSize = null;
}
$articles = $this->paginator->paginate(
$articlesList,
$page,
ConstantsService::ARTICLES_PER_PAGE
);
$articles->setCustomParameters([
'align' => 'center', # center|right (for template: twitter_bootstrap_v4_pagination)
'style' => 'bottom',
'class' => 'text-dark',
]);
$jsonld = $this->linkedDatasJsonService-> getWebPageJsonLd(
$this->configurationService->getConfiguration()->getWebsiteName(),
$this->configurationService->getConfiguration()->getMetaDescription(),
$this->configurationService->getConfiguration()->getAuthor()
);
//return $this->render('home/index.html.twig', [ TRY SOME OTHER STYLE IN TEMPLATE
$response = $this->render('home/twoColumns.amp.html.twig', [
'controller_name' => 'HomeController',
'lastArticle' => $lastArticle,
'featuredArticles' => $featuredArticles,
'articles' => $articles,
'textManipulationService' => $this->textManipulationService,
'page' => $page,
"lastArticleImageSize" => $lastArticleImageSize,
"jsonld" => $jsonld
]);
$response->setSharedMaxAge(3600);
return $response;
}
}