src/Controller/HomeController.php line 38

  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\ArticleRepository;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use App\Service\TextManipulationService;
  7. use App\Service\ConstantsService;
  8. use App\Service\GetImageSizeService;
  9. use App\Service\LinkedDatasJsonService;
  10. use App\Service\ConfigurationService;
  11. use Knp\Component\Pager\PaginatorInterface
  12. class HomeController extends AbstractController
  13. {
  14.     private $articleRepository;
  15.     private $textManipulationService;
  16.     private $paginator;
  17.     
  18.     public function __construct(
  19.         ArticleRepository $articleRepository,
  20.         TextManipulationService $textManipulationService,
  21.         PaginatorInterface $paginator,
  22.         GetImageSizeService $getImageSizeService,
  23.         ConfigurationService $configurationService,
  24.         LinkedDatasJsonService $linkedDatasJsonService
  25.     ){
  26.         $this->articleRepository $articleRepository;
  27.         $this->textManipulationService $textManipulationService;
  28.         $this->paginator $paginator;
  29.         $this->getImageSizeService $getImageSizeService;
  30.         $this->configurationService $configurationService;
  31.         $this->linkedDatasJsonService $linkedDatasJsonService;
  32.     }
  33.     #[Route('/{page}'name'home'requirements: ['page'=> '\d+'])]
  34.     public function index(int $page 1)
  35.     {
  36.         $lastArticle $this->articleRepository->findOneBy(array(), array("creationDate" => "DESC"));
  37.         if ($lastArticle !== null && $lastArticle->getMedia() !== null) {
  38.             $lastArticleImageSize $this->getImageSizeService->getSize("build/images/".$lastArticle->getMedia()->getMediaName());
  39.         } else {
  40.             $lastArticleImageSize null;
  41.         }
  42.         $featuredArticles $this->articleRepository->findBy(array("featured" => 1), array("creationDate" => "DESC"));
  43.         $articlesList $this->articleRepository->findBy(array("featured" => 0), array("creationDate" => "DESC"));
  44.         $articles $this->paginator->paginate(
  45.             $articlesList,
  46.             $page,
  47.             ConstantsService::ARTICLES_PER_PAGE
  48.         );
  49.         $articles->setCustomParameters([
  50.             'align' => 'center'# center|right (for template: twitter_bootstrap_v4_pagination)
  51.             'style' => 'bottom',
  52.             'class' => 'text-dark',
  53.         ]);
  54.         //dump($this->configurationService->getConfiguration());
  55.         //die();
  56.         $jsonld $this->linkedDatasJsonService-> getWebPageJsonLd(
  57.             $this->configurationService->getConfiguration()->getWebsiteName(),
  58.             $this->configurationService->getConfiguration()->getMetaDescription(),
  59.             $this->configurationService->getConfiguration()->getAuthor()
  60.         );
  61.         //return $this->render('home/index.html.twig', [  TRY SOME OTHER STYLE IN TEMPLATE
  62.         $response $this->render('home/twoColumns.html.twig', [
  63.             'controller_name' => 'HomeController',
  64.             'lastArticle' => $lastArticle,
  65.             'featuredArticles' => $featuredArticles,
  66.             'articles' => $articles,
  67.             'textManipulationService' => $this->textManipulationService,
  68.             'page' => $page,
  69.             "lastArticleImageSize" => $lastArticleImageSize,
  70.             "jsonld" => $jsonld
  71.         ]);
  72.         $response->setSharedMaxAge(3600);
  73.         return $response;
  74.     }
  75.     #[Route('amp/{page}'name'home_amp'requirements: ['page'=> '\d+'])]
  76.     public function indexAmp(int $page 1)
  77.     {
  78.         $lastArticle $this->articleRepository->findOneBy(array(), array("creationDate" => "DESC"));
  79.         $featuredArticles $this->articleRepository->findBy(array("featured" => 1), array("creationDate" => "DESC"));
  80.         $articlesList $this->articleRepository->findBy(array("featured" => 0), array("creationDate" => "DESC"));
  81.         if ($lastArticle->getMedia() !== null) {
  82.             $lastArticleImageSize $this->getImageSizeService->getSize("build/images/".$lastArticle->getMedia()->getMediaName());
  83.         } else {
  84.             $lastArticleImageSize null;
  85.         }
  86.         $articles $this->paginator->paginate(
  87.             $articlesList,
  88.             $page,
  89.             ConstantsService::ARTICLES_PER_PAGE
  90.         );
  91.         $articles->setCustomParameters([
  92.             'align' => 'center'# center|right (for template: twitter_bootstrap_v4_pagination)
  93.             'style' => 'bottom',
  94.             'class' => 'text-dark',
  95.         ]);
  96.         
  97.         $jsonld $this->linkedDatasJsonService-> getWebPageJsonLd(
  98.             $this->configurationService->getConfiguration()->getWebsiteName(),
  99.             $this->configurationService->getConfiguration()->getMetaDescription(),
  100.             $this->configurationService->getConfiguration()->getAuthor()
  101.         );
  102.         //return $this->render('home/index.html.twig', [  TRY SOME OTHER STYLE IN TEMPLATE
  103.         $response =  $this->render('home/twoColumns.amp.html.twig', [
  104.             'controller_name' => 'HomeController',
  105.             'lastArticle' => $lastArticle,
  106.             'featuredArticles' => $featuredArticles,
  107.             'articles' => $articles,
  108.             'textManipulationService' => $this->textManipulationService,
  109.             'page' => $page,
  110.             "lastArticleImageSize" => $lastArticleImageSize,
  111.             "jsonld" => $jsonld
  112.         ]);
  113.         $response->setSharedMaxAge(3600);
  114.         return $response;
  115.     }
  116. }