src/Controller/HomeController.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Category;
  4. use App\Entity\ReturnConfig;
  5. use App\Entity\ReturnSlide;
  6. use App\Service\SlideService;
  7. use Doctrine\ORM\EntityManager;
  8. use App\Service\CategoryService;
  9. use App\Service\SearchEngineService;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. class HomeController extends AbstractController
  15. {
  16.     protected $categoryService;
  17.     protected $slideService;
  18.     protected $em;
  19.     public function __construct(
  20.         CategoryService $categoryService,
  21.         SlideService $slideService,
  22.         EntityManagerInterface $em
  23.     ) {
  24.         $this->categoryService $categoryService;
  25.         $this->slideService $slideService;
  26.         $this->em $em;
  27.     }
  28.     /**
  29.      * @Route("/")
  30.      */
  31.     public function indexNoLocale(): Response
  32.     {
  33.         return $this->redirectToRoute('home', ['_locale' => 'fr']);
  34.     }
  35.     /**
  36.      * @Route({
  37.      *  "fr": "/fr"
  38.      * }, name="home")
  39.      */
  40.     public function index(CategoryService $categoryServiceSearchEngineService $searchEngineService): Response
  41.     {
  42.         //if (isset($_GET['hook'])) {
  43.         //    $categoryBase = $this->em->getRepository(Category::class)->findOneBy(
  44.         //        [
  45.         //            'id' => 39
  46.         //        ]
  47.         //    );
  48.         //    $contentBase = $categoryBase->getContent();
  49.         //    $categories = $this->em->getRepository(Category::class)->findBy(
  50.         //        [
  51.         //            'parentSlug' => 'rentrees'
  52.         //        ]
  53.         //    );
  54.         //    foreach($categories as $category) {
  55.         //        $explode = explode('conférence ', $category->getTitle());
  56.         //        $newContent = str_replace('[BLOC_RETURN_SLIDE]', '[BLOC_RETURN_SLIDE_'.$explode[1].']', $contentBase);
  57.         //        $category->setContent($newContent);
  58.         //        $this->em->persist($category);
  59.         //    }
  60.         //    $this->em->flush();
  61.         //     $returnConfigs = $this->em->getRepository(ReturnConfig::class)->findAll();
  62.         //     foreach ($returnConfigs as $returnConfig) {
  63.         //         $returnSlides = $this->em->getRepository(ReturnSlide::class)->findBy(
  64.         //             [
  65.         //                 'year' => $returnConfig->getYear(),
  66.         //                 'online' => 1
  67.         //             ],
  68.         //             null,
  69.         //             3
  70.         //         );
  71.         //         $returnConfig
  72.         //             ->setPagePhoto1(null)
  73.         //             ->setPageTitlePhoto1(null)
  74.         //             ->setPageSubtitle1Photo1(null)
  75.         //             ->setPageSubtitle2Photo1(null);
  76.         //         $returnConfig
  77.         //             ->setPagePhoto2(null)
  78.         //             ->setPageTitlePhoto2(null)
  79.         //             ->setPageSubtitle1Photo2(null)
  80.         //             ->setPageSubtitle2Photo2(null);
  81.         //         $returnConfig
  82.         //             ->setPagePhoto3(null)
  83.         //             ->setPageTitlePhoto3(null)
  84.         //             ->setPageSubtitle1Photo3(null)
  85.         //             ->setPageSubtitle2Photo3(null);
  86.         //         foreach ($returnSlides as $k => $returnSlide) {
  87.         //             $fonction = $returnSlide->getFunction();
  88.         //             $subFonction = $returnSlide->getFunction();
  89.         //             if ($fonction == 'Ancien Secrétaire de la Conférence') {
  90.         //                 $fonction = 'Secrétaire de la Conférence';
  91.         //             } else {
  92.         //                 $subFonction = '';
  93.         //             }
  94.         //             if ($k == 0) {
  95.         //                 $returnConfig
  96.         //                     ->setPagePhoto1($returnSlide->getPicture())
  97.         //                     ->setPageTitlePhoto1($fonction)
  98.         //                     ->setPageSubtitle1Photo1($returnSlide->getName())
  99.         //                     ->setPageSubtitle2Photo1($subFonction);
  100.         //             }
  101.         //             if ($k == 1) {
  102.         //                 $returnConfig
  103.         //                     ->setPagePhoto2($returnSlide->getPicture())
  104.         //                     ->setPageTitlePhoto2($fonction)
  105.         //                     ->setPageSubtitle1Photo2($returnSlide->getName())
  106.         //                     ->setPageSubtitle2Photo2($subFonction);
  107.         //             }
  108.         //             if ($k == 2) {
  109.         //                 $returnConfig
  110.         //                     ->setPagePhoto3($returnSlide->getPicture())
  111.         //                     ->setPageTitlePhoto3($fonction)
  112.         //                     ->setPageSubtitle1Photo3($returnSlide->getName())
  113.         //                     ->setPageSubtitle2Photo3($subFonction);
  114.         //             }
  115.         //         }
  116.         //         $this->em->persist($returnConfig);
  117.         //         // dump($returnConfig);
  118.         //     }
  119.         //     $this->em->flush();
  120.         //}
  121.         // dd($returnConfigs);
  122.         //$searchEngineService->initializeDatabase();
  123.         // $mobileTree = $this->categoryService->getMenuFrontMobile();
  124.         // $desktopTree = $this->categoryService->getMenuFrontDesktop();
  125.         // echo $desktopTree;
  126.         // $categoryService->getMenuForSelect();
  127.         //Récupération de la home page
  128.         $homePage $this->em->getRepository(Category::class)->findOneBy([
  129.             'isHomePage'    => 1
  130.         ]);
  131.         $slides $this->slideService->getSlides();
  132.         $pageParams = [
  133.             'controllerName' => 'Home',
  134.             'category' => $homePage,
  135.             // 'blocs' => $blocs,
  136.             'slides' => $slides
  137.         ];
  138.         return $this->render('home/index.html.twig'$pageParams);
  139.     }
  140.     /**
  141.      * @Route("/admin/dashboard", name="home_admin_index")
  142.      */
  143.     public function adminIndex(): Response
  144.     {
  145.         // $mobileTree = $this->categoryService->getMenuFrontMobile();
  146.         // $desktopTree = $this->categoryService->getMenuFrontDesktop();
  147.         // echo $desktopTree;
  148.         $slides $this->slideService->getSlides();
  149.         return $this->render('home/index.html.twig', [
  150.             'slides' => $slides
  151.         ]);
  152.     }
  153. }