<?php
namespace App\Controller;
use App\Entity\Category;
use App\Entity\ReturnConfig;
use App\Entity\ReturnSlide;
use App\Service\SlideService;
use Doctrine\ORM\EntityManager;
use App\Service\CategoryService;
use App\Service\SearchEngineService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class HomeController extends AbstractController
{
protected $categoryService;
protected $slideService;
protected $em;
public function __construct(
CategoryService $categoryService,
SlideService $slideService,
EntityManagerInterface $em
) {
$this->categoryService = $categoryService;
$this->slideService = $slideService;
$this->em = $em;
}
/**
* @Route("/")
*/
public function indexNoLocale(): Response
{
return $this->redirectToRoute('home', ['_locale' => 'fr']);
}
/**
* @Route({
* "fr": "/fr"
* }, name="home")
*/
public function index(CategoryService $categoryService, SearchEngineService $searchEngineService): Response
{
//if (isset($_GET['hook'])) {
// $categoryBase = $this->em->getRepository(Category::class)->findOneBy(
// [
// 'id' => 39
// ]
// );
// $contentBase = $categoryBase->getContent();
// $categories = $this->em->getRepository(Category::class)->findBy(
// [
// 'parentSlug' => 'rentrees'
// ]
// );
// foreach($categories as $category) {
// $explode = explode('conférence ', $category->getTitle());
// $newContent = str_replace('[BLOC_RETURN_SLIDE]', '[BLOC_RETURN_SLIDE_'.$explode[1].']', $contentBase);
// $category->setContent($newContent);
// $this->em->persist($category);
// }
// $this->em->flush();
// $returnConfigs = $this->em->getRepository(ReturnConfig::class)->findAll();
// foreach ($returnConfigs as $returnConfig) {
// $returnSlides = $this->em->getRepository(ReturnSlide::class)->findBy(
// [
// 'year' => $returnConfig->getYear(),
// 'online' => 1
// ],
// null,
// 3
// );
// $returnConfig
// ->setPagePhoto1(null)
// ->setPageTitlePhoto1(null)
// ->setPageSubtitle1Photo1(null)
// ->setPageSubtitle2Photo1(null);
// $returnConfig
// ->setPagePhoto2(null)
// ->setPageTitlePhoto2(null)
// ->setPageSubtitle1Photo2(null)
// ->setPageSubtitle2Photo2(null);
// $returnConfig
// ->setPagePhoto3(null)
// ->setPageTitlePhoto3(null)
// ->setPageSubtitle1Photo3(null)
// ->setPageSubtitle2Photo3(null);
// foreach ($returnSlides as $k => $returnSlide) {
// $fonction = $returnSlide->getFunction();
// $subFonction = $returnSlide->getFunction();
// if ($fonction == 'Ancien Secrétaire de la Conférence') {
// $fonction = 'Secrétaire de la Conférence';
// } else {
// $subFonction = '';
// }
// if ($k == 0) {
// $returnConfig
// ->setPagePhoto1($returnSlide->getPicture())
// ->setPageTitlePhoto1($fonction)
// ->setPageSubtitle1Photo1($returnSlide->getName())
// ->setPageSubtitle2Photo1($subFonction);
// }
// if ($k == 1) {
// $returnConfig
// ->setPagePhoto2($returnSlide->getPicture())
// ->setPageTitlePhoto2($fonction)
// ->setPageSubtitle1Photo2($returnSlide->getName())
// ->setPageSubtitle2Photo2($subFonction);
// }
// if ($k == 2) {
// $returnConfig
// ->setPagePhoto3($returnSlide->getPicture())
// ->setPageTitlePhoto3($fonction)
// ->setPageSubtitle1Photo3($returnSlide->getName())
// ->setPageSubtitle2Photo3($subFonction);
// }
// }
// $this->em->persist($returnConfig);
// // dump($returnConfig);
// }
// $this->em->flush();
//}
// dd($returnConfigs);
//$searchEngineService->initializeDatabase();
// $mobileTree = $this->categoryService->getMenuFrontMobile();
// $desktopTree = $this->categoryService->getMenuFrontDesktop();
// echo $desktopTree;
// $categoryService->getMenuForSelect();
//Récupération de la home page
$homePage = $this->em->getRepository(Category::class)->findOneBy([
'isHomePage' => 1
]);
$slides = $this->slideService->getSlides();
$pageParams = [
'controllerName' => 'Home',
'category' => $homePage,
// 'blocs' => $blocs,
'slides' => $slides
];
return $this->render('home/index.html.twig', $pageParams);
}
/**
* @Route("/admin/dashboard", name="home_admin_index")
*/
public function adminIndex(): Response
{
// $mobileTree = $this->categoryService->getMenuFrontMobile();
// $desktopTree = $this->categoryService->getMenuFrontDesktop();
// echo $desktopTree;
$slides = $this->slideService->getSlides();
return $this->render('home/index.html.twig', [
'slides' => $slides
]);
}
}