src/Controller/DefaultController.php line 150

  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.         $host $request->getHost();
  38.         if($host == $this->getParameter('de_host')){
  39.             return $this->forward('App\Controller\LandingController::landingVerdeAmore', [
  40.         '_route' => $request->get('_route')
  41. ]);
  42.         }
  43.         if ($request->getLocale() == 'de') {
  44.             // TODO RIATTIVA PER DE
  45.             // if ($host == $this->getParameter('base_host')) {
  46.                 $scheme $request->getScheme();  // http o https
  47.                 $redirectUrl $scheme '://' $this->getParameter('de_host').'/de';
  48.                 return new RedirectResponse($redirectUrl301); // redirect permanente.'/de'
  49.             // }
  50.         }
  51.         list ($metatags$hreflangs) = $this->getStaticPageMetatagsAndHreflangs($request$em$this->getParameter('locales'));
  52.         /** @var MagazineRepository  $magazineRepository */
  53.         $magazineRepository $this->em->getRepository(Magazine::class);
  54.         $magazine $magazineRepository->findOneBy([
  55.             'type' => 'MAGAZINE',
  56.             'isEnabled' => true,
  57.             'locale' => $request->getLocale()
  58.         ],
  59.         [
  60.             // 'id' => 'DESC'
  61.             'sortablePosition' => 'DESC',
  62.         ]);
  63.         /** @var RecipeRepository  $recipeRepository */
  64.         $recipeRepository $this->em->getRepository(Recipe::class);
  65.         $recipe $recipeRepository->findOneBy([
  66.             'isEnabled' => true,
  67.             'isInHome' => true,
  68.             'locale' => $request->getLocale()
  69.         ],
  70.         [
  71.             'id' => 'DESC'
  72.         ]);
  73.         $productCategories $this->em->getRepository(ProductCategory::class)->findBy([
  74.             'locale' => $request->getLocale(),
  75.             'enabled' => 1,
  76.             'parent' => null
  77.         ],
  78.             [
  79.                 'sortablePosition' => 'ASC'
  80.             ]);
  81.         $productTypes $this->em->getRepository(ProductType::class)->findBy([
  82.             'enabled' => true,
  83.             'locale' => $request->getLocale()
  84.         ],
  85.             [
  86.                 'sortablePosition' => 'ASC'
  87.             ]);
  88.         // foreach ($productTypes as $key => $pT){
  89.         //     if ($pT->getName() == 'Spalmabile'){
  90.         //         unset($productTypes[$key]);
  91.         //     }
  92.         // }
  93.         $template 'default/index.html.twig';
  94.         if ($request->getLocale() == 'it') {
  95.             $template 'default/index_it.html.twig';
  96.         }
  97.         return $this->render($template, [
  98.             'magazine' => $magazine,
  99.             'recipe' => $recipe,
  100.             'productCategories' => $productCategories,
  101.             'productTypes' => $productTypes,
  102.             'metatags' => $metatags,
  103.             'hreflangs' => $hreflangs
  104.         ]);
  105.     }
  106.     public function headerAction(Request $requeststring $route null){
  107.         $productCategories $this->em->getRepository(ProductCategory::class)->findBy([
  108.             'locale' => $request->getLocale(),
  109.             'enabled' => 1,
  110.             'parent' => null
  111.         ],
  112.         [
  113.             'sortablePosition' => 'ASC'
  114.         ]);
  115.         $productTypes $this->em->getRepository(ProductType::class)->findBy([
  116.             'enabled' => true,
  117.             'locale' => $request->getLocale()
  118.         ],
  119.             [
  120.                 'sortablePosition' => 'ASC'
  121.             ]);
  122.         return $this->render('partials/layout/_header.html.twig', [
  123.             'productCategories' => $productCategories,
  124.             'current_route' => $route,
  125.             'productTypes' => $productTypes,
  126.         ]);
  127.     }
  128.     public function footerAction(Request $request$banner$color$spalmabile$currentPath null){
  129.         $productCategories $this->em->getRepository(ProductCategory::class)->findBy([
  130.             'locale' => $request->getLocale(),
  131.             'enabled' => 1,
  132.             'parent' => null
  133.         ],
  134.             [
  135.                 'sortablePosition' => 'ASC'
  136.             ]);
  137.         if ($currentPath != 'homepage'){
  138.             $currentPath NULL;
  139.         }
  140.         return $this->render('partials/layout/_footer.html.twig', [
  141.             'productCategories' => $productCategories,
  142.             'banner' => $banner,
  143.             'color' => $color,
  144.             'spalmabile' => $spalmabile,
  145.             'currentPath' => $currentPath
  146.         ]);
  147.     }
  148. }