src/Controller/DefaultController.php line 94

  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.         // foreach ($productTypes as $key => $pT){
  71.         //     if ($pT->getName() == 'Spalmabile'){
  72.         //         unset($productTypes[$key]);
  73.         //     }
  74.         // }
  75.         return $this->render('default/index.html.twig', [
  76.             'magazine' => $magazine,
  77.             'recipe' => $recipe,
  78.             'productCategories' => $productCategories,
  79.             'metatags' => $metatags,
  80.             'hreflangs' => $hreflangs
  81.         ]);
  82.     }
  83.     public function headerAction(Request $requeststring $route null){
  84.         $productCategories $this->em->getRepository(ProductCategory::class)->findBy([
  85.             'locale' => $request->getLocale(),
  86.             'enabled' => 1,
  87.             'parent' => null
  88.         ],
  89.         [
  90.             'sortablePosition' => 'ASC'
  91.         ]);
  92.         return $this->render('partials/layout/_header.html.twig', [
  93.             'productCategories' => $productCategories,
  94.             'current_route' => $route,
  95.         ]);
  96.     }
  97.     public function footerAction(Request $request$banner$color$currentPath null){
  98.         $productCategories $this->em->getRepository(ProductCategory::class)->findBy([
  99.             'locale' => $request->getLocale(),
  100.             'enabled' => 1,
  101.             'parent' => null
  102.         ],
  103.             [
  104.                 'sortablePosition' => 'ASC'
  105.             ]);
  106.         if ($currentPath != 'homepage'){
  107.             $currentPath NULL;
  108.         }
  109.         return $this->render('partials/layout/_footer.html.twig', [
  110.             'productCategories' => $productCategories,
  111.             'banner' => $banner,
  112.             'color' => $color,
  113.             'currentPath' => $currentPath
  114.         ]);
  115.     }
  116. }