src/Controller/DefaultController.php line 129

  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\Request;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. use Symfony\Contracts\Translation\TranslatorInterface;
  19. class DefaultController extends AbstractController
  20. {
  21.     use MetatagsControllerTraitHreflangsControllerTraitStaticPageHelperTrait;
  22.     private $em;
  23.     private $transalor;
  24.     public function __construct(EntityManagerInterface $emTranslatorInterface $translator){
  25.         $this->em $em;
  26.         $this->transalor $translator;
  27.     }
  28.     #[Route(['/',
  29.             'en' => '/en',
  30.             'es' => '/es',
  31.             'de' => '/de',
  32.             ], name'homepage')]
  33.     public function homepage(Request $requestEntityManagerInterface $em)
  34.     {
  35.         if ($request->getLocale() == 'de') {
  36.             return $this->forward('App\Controller\LandingController::landingVerdeAmore', [
  37.                 '_route' => $request->get('_route')
  38.             ]);
  39.         }
  40.         list ($metatags$hreflangs) = $this->getStaticPageMetatagsAndHreflangs($request$em$this->getParameter('locales'));
  41.         /** @var MagazineRepository  $magazineRepository */
  42.         $magazineRepository $this->em->getRepository(Magazine::class);
  43.         $magazine $magazineRepository->findOneBy([
  44.             'type' => 'MAGAZINE',
  45.             'isEnabled' => true,
  46.             'locale' => $request->getLocale()
  47.         ],
  48.         [
  49.             // 'id' => 'DESC'
  50.             'sortablePosition' => 'DESC',
  51.         ]);
  52.         /** @var RecipeRepository  $recipeRepository */
  53.         $recipeRepository $this->em->getRepository(Recipe::class);
  54.         $recipe $recipeRepository->findOneBy([
  55.             'isEnabled' => true,
  56.             'isInHome' => true,
  57.             'locale' => $request->getLocale()
  58.         ],
  59.         [
  60.             'id' => 'DESC'
  61.         ]);
  62.         $productCategories $this->em->getRepository(ProductCategory::class)->findBy([
  63.             'locale' => $request->getLocale(),
  64.             'enabled' => 1,
  65.             'parent' => null
  66.         ],
  67.             [
  68.                 'sortablePosition' => 'ASC'
  69.             ]);
  70.         $productTypes $this->em->getRepository(ProductType::class)->findBy([
  71.             'enabled' => true,
  72.             'locale' => $request->getLocale()
  73.         ],
  74.             [
  75.                 'sortablePosition' => 'ASC'
  76.             ]);
  77.         // foreach ($productTypes as $key => $pT){
  78.         //     if ($pT->getName() == 'Spalmabile'){
  79.         //         unset($productTypes[$key]);
  80.         //     }
  81.         // }
  82.         return $this->render('default/index.html.twig', [
  83.             'magazine' => $magazine,
  84.             'recipe' => $recipe,
  85.             'productCategories' => $productCategories,
  86.             'productTypes' => $productTypes,
  87.             'metatags' => $metatags,
  88.             'hreflangs' => $hreflangs
  89.         ]);
  90.     }
  91.     public function headerAction(Request $requeststring $route null){
  92.         $productCategories $this->em->getRepository(ProductCategory::class)->findBy([
  93.             'locale' => $request->getLocale(),
  94.             'enabled' => 1,
  95.             'parent' => null
  96.         ],
  97.         [
  98.             'sortablePosition' => 'ASC'
  99.         ]);
  100.         $productTypes $this->em->getRepository(ProductType::class)->findBy([
  101.             'enabled' => true,
  102.             'locale' => $request->getLocale()
  103.         ],
  104.             [
  105.                 'sortablePosition' => 'ASC'
  106.             ]);
  107.         return $this->render('partials/layout/_header.html.twig', [
  108.             'productCategories' => $productCategories,
  109.             'current_route' => $route,
  110.             'productTypes' => $productTypes,
  111.         ]);
  112.     }
  113.     public function footerAction(Request $request$banner$color$currentPath null){
  114.         $productCategories $this->em->getRepository(ProductCategory::class)->findBy([
  115.             'locale' => $request->getLocale(),
  116.             'enabled' => 1,
  117.             'parent' => null
  118.         ],
  119.             [
  120.                 'sortablePosition' => 'ASC'
  121.             ]);
  122.         if ($currentPath != 'homepage'){
  123.             $currentPath NULL;
  124.         }
  125.         return $this->render('partials/layout/_footer.html.twig', [
  126.             'productCategories' => $productCategories,
  127.             'banner' => $banner,
  128.             'color' => $color,
  129.             'currentPath' => $currentPath
  130.         ]);
  131.     }
  132. }