src/Controller/DefaultController.php line 124

  1. <?php
  2. namespace App\Controller;
  3. use App\Controller\Traits\HreflangsControllerTrait;
  4. use App\Controller\Traits\MetatagsControllerTrait;
  5. use App\Controller\Traits\StaticPageHelperTrait;
  6. use App\Entity\Magazine;
  7. use App\Entity\PrivacyPolicy;
  8. use App\Entity\ProductCategory;
  9. use App\Entity\ProductType;
  10. use App\Entity\Recipe;
  11. use App\Entity\StaticPage;
  12. use App\Repository\MagazineRepository;
  13. use App\Repository\RecipeRepository;
  14. use Doctrine\ORM\EntityManagerInterface;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. use Symfony\Component\HttpFoundation\RedirectResponse;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  20. use Symfony\Contracts\Translation\TranslatorInterface;
  21. class DefaultController extends AbstractController
  22. {
  23.     use MetatagsControllerTraitHreflangsControllerTraitStaticPageHelperTrait;
  24.     private $em;
  25.     private $transalor;
  26.     public function __construct(EntityManagerInterface $emTranslatorInterface $translator){
  27.         $this->em $em;
  28.         $this->transalor $translator;
  29.     }
  30.     #[Route(['/',
  31.             'en' => '/en',
  32. //            'es' => '/es',
  33.             'de' => '/de',
  34.             ], name'homepage')]
  35.     public function homepage(Request $requestEntityManagerInterface $em)
  36.     {
  37.         
  38.         $host $request->getHost();
  39.         if($host == $this->getParameter('de_host')){
  40.             return $this->forward('App\Controller\LandingController::landingVerdeAmore', [
  41.         '_route' => $request->get('_route')
  42. ]);
  43.         }
  44.         if ($request->getLocale() == 'de') {
  45.             // TODO RIATTIVA PER DE
  46.             // if ($host == $this->getParameter('base_host')) {
  47.                 $scheme $request->getScheme();  // http o https
  48.                 $redirectUrl $scheme '://' $this->getParameter('de_host').'/de';
  49.                 return new RedirectResponse($redirectUrl301); // redirect permanente.'/de'
  50.             // }
  51.         }
  52.         list ($metatags$hreflangs) = $this->getStaticPageMetatagsAndHreflangs($request$em$this->getParameter('locales'));
  53.         /** @var MagazineRepository  $magazineRepository */
  54.         $magazineRepository $this->em->getRepository(Magazine::class);
  55.         $magazine $magazineRepository->findOneBy([
  56.             'type' => 'MAGAZINE',
  57.             'isEnabled' => true,
  58.             'locale' => $request->getLocale()
  59.         ],
  60.         [
  61.             // 'id' => 'DESC'
  62.             'sortablePosition' => 'DESC',
  63.         ]);
  64.         /** @var RecipeRepository  $recipeRepository */
  65.         $recipeRepository $this->em->getRepository(Recipe::class);
  66.         $recipe $recipeRepository->findOneBy([
  67.             'isEnabled' => true,
  68.             'isInHome' => true,
  69.             'locale' => $request->getLocale()
  70.         ],
  71.         [
  72.             'id' => 'DESC'
  73.         ]);
  74.         $productCategories $this->em->getRepository(ProductCategory::class)->findBy([
  75.             'locale' => $request->getLocale(),
  76.             'enabled' => 1,
  77.             'parent' => null
  78.         ],
  79.             [
  80.                 'sortablePosition' => 'ASC'
  81.             ]);
  82.         $productTypes $this->em->getRepository(ProductType::class)->findBy([
  83.             'enabled' => true,
  84.             'locale' => $request->getLocale()
  85.         ],
  86.             [
  87.                 'sortablePosition' => 'ASC'
  88.             ]);
  89.         // foreach ($productTypes as $key => $pT){
  90.         //     if ($pT->getName() == 'Spalmabile'){
  91.         //         unset($productTypes[$key]);
  92.         //     }
  93.         // }
  94.         $template 'default/index.html.twig';
  95.         if ($request->getLocale() == 'it') {
  96.             $template 'default/index_it.html.twig';
  97.         }
  98.         return $this->render($template, [
  99.             'magazine' => $magazine,
  100.             'recipe' => $recipe,
  101.             'productCategories' => $productCategories,
  102.             'productTypes' => $productTypes,
  103.             'metatags' => $metatags,
  104.             'hreflangs' => $hreflangs
  105.         ]);
  106.     }
  107.     public function headerAction(Request $requeststring $route null){
  108.         $productCategories $this->em->getRepository(ProductCategory::class)->findBy([
  109.             'locale' => $request->getLocale(),
  110.             'enabled' => 1,
  111.             'parent' => null
  112.         ],
  113.         [
  114.             'sortablePosition' => 'ASC'
  115.         ]);
  116.         $productTypes $this->em->getRepository(ProductType::class)->findBy([
  117.             'enabled' => true,
  118.             'locale' => $request->getLocale()
  119.         ],
  120.             [
  121.                 'sortablePosition' => 'ASC'
  122.             ]);
  123.         return $this->render('partials/layout/_header.html.twig', [
  124.             'productCategories' => $productCategories,
  125.             'current_route' => $route,
  126.             'productTypes' => $productTypes,
  127.         ]);
  128.     }
  129.     public function footerAction(Request $request$banner$color$currentPath null){
  130.         $productCategories $this->em->getRepository(ProductCategory::class)->findBy([
  131.             'locale' => $request->getLocale(),
  132.             'enabled' => 1,
  133.             'parent' => null
  134.         ],
  135.             [
  136.                 'sortablePosition' => 'ASC'
  137.             ]);
  138.         if ($currentPath != 'homepage'){
  139.             $currentPath NULL;
  140.         }
  141.         return $this->render('partials/layout/_footer.html.twig', [
  142.             'productCategories' => $productCategories,
  143.             'banner' => $banner,
  144.             'color' => $color,
  145.             'currentPath' => $currentPath
  146.         ]);
  147.     }
  148. }