src/Controller/PromosController.php line 194

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  11. use Symfony\Component\HttpFoundation\Cookie;
  12. use Symfony\Component\Yaml\Yaml;
  13. use Symfony\Component\Yaml\Exception\ParseException;
  14. use Symfony\Component\Yaml\Exception;
  15. use Symfony\Component\String\UnicodeString;
  16. use Symfony\Contracts\Translation\TranslatorInterface;
  17. use Symfony\Component\HttpKernel\KernelInterface;
  18. use App\Entity\TemporaryReservation;
  19. use App\Entity\Promo;
  20. use App\Entity\Venteflash;
  21. use App\Entity\Residence;
  22. use App\Entity\mediaResidence;
  23. use App\Entity\Language;
  24. use App\Services\SeasonService;
  25. use App\Services\ToolService;
  26. use Liip\ImagineBundle\Imagine\Cache\CacheManager;
  27. use Vich\UploaderBundle\Templating\Helper\UploaderHelper;
  28. /**
  29.  * @Route("/{_locale}/promos", requirements={"_locale": "en|fr"})
  30.  */
  31. class PromosController extends AbstractController
  32. {
  33.     /**
  34.      * @var EntityManagerInterface
  35.      */
  36.     private $em;
  37.     private $session;
  38.     private $flashbag;
  39.     private $user;
  40.     private $filtre;
  41.     private $seasonService;
  42.     private $toolService;
  43.     private $cacheManager;
  44.     private $helper;
  45.     private $translator;
  46.     private $appKernel;
  47.     function __construct(EntityManagerInterface $em,  SessionInterface $sessionSeasonService $seasonServiceToolService $toolServiceCacheManager $cacheManagerUploaderHelper $helperTranslatorInterface $translatorKernelInterface $appKernel) {
  48.         $this->em $em;
  49.         $this->session $session;
  50.         $this->flashbag $this->session->getFlashBag();
  51.         $this->seasonService $seasonService;
  52.         $this->toolService $toolService;
  53.         $this->cacheManager $cacheManager;
  54.         $this->helper $helper;
  55.         $this->translator $translator;
  56.         $this->appKernel $appKernel;
  57.         $this->filtre = [
  58.             'environnement' => 'environnement',
  59.             'lieu' => 'slug_lieu',
  60.             'ville' => 'slug_ville',
  61.             'region' => 'slug_region'
  62.         ];
  63.     }
  64.     /**
  65.      * @Route("/", name="_list")
  66.      */
  67.     public function promosList (Request $request)
  68.     {
  69.         $promos $this->em->getRepository(Promo::class)->findAll();
  70.         $photoProfil = [];
  71.         foreach($promos as $promo) {
  72.            
  73.             $residence $this->em->getRepository(Residence::class)->findOneByIdiresa($promo->getIdLieuHebergement());
  74.             
  75.             if($residence instanceof residence) {
  76.                 $season $this->seasonService->getSeason();
  77.                 $slider $this->em->getRepository(mediaResidence::class)->findOneByLocation($residence->getId(), "content"$lang$season);
  78.                 if($slider instanceof mediaResidence) {
  79.                     $image_path $this->helper->asset($slider'imageFile');
  80.                     $image_link $this->cacheManager->getBrowserPath($image_path'offre');
  81.                     $photoProfil[$promo->getId()] = $image_link;
  82.                 }
  83.             }
  84.         }
  85.         $vars = [
  86.             "page_code" => "promo",
  87.             "filtres" => false,
  88.             "category" => "all",
  89.             "promos" => $promos,
  90.             "photoProfil" => $photoProfil
  91.         ];
  92.         return $this->render('/front/Promos/index.html.twig'$vars);
  93.     }
  94.     /**
  95.      * @Route("/{offre_category}", name="ac_platform_promos_category_list", options={"expose"=true})
  96.      */
  97.     public function promosCategoryList (Request $request$offre_category)
  98.     {
  99.         $locale $request->getLocale();
  100.         $lang  $this->em->getRepository(Language::class)->findOneByCode($locale);
  101.         $lang_default  $this->em->getRepository(Language::class)->findOneByCode('fr');
  102.         $method $this->toolService->snakeToCamelCase('get-'$offre_category);
  103.         $repository $this->em->getRepository(Promo::class);
  104.         if(!method_exists$repository$method)) {
  105.             $vars = [
  106.                 "category" => 'error.unknown',
  107.                 "promos" => []
  108.             ];
  109.             return $this->render('/front/Promos/index.html.twig'$vars); 
  110.         }
  111.         $promos $repository->{$method}();
  112.         $environnements = [];
  113.         $regions = [];
  114.         $villes = [];
  115.         $photoProfil = [];
  116.         $listPromos = [];
  117.         foreach($promos as $promo) {
  118.             if(!in_array(ucfirst($promo->getEnvironnement()), $environnements)) {
  119.                 $environnements$promo->getEnvironnement()] = ucfirst($promo->getEnvironnement());
  120.             }
  121.             if(!in_array($promo->getRegion(), $regions)) {
  122.                 $regions[$promo->getSlugRegion()] = $promo->getRegion();
  123.             }
  124.             if(!in_array($promo->getVille(), $villes)) {
  125.                 $villes[$promo->getSlugVille()] = $promo->getVille();
  126.             }
  127.             $residence $this->em->getRepository(Residence::class)->findOneByIdiresa($promo->getIdLieuHebergement());
  128.             
  129.             if($residence instanceof residence) {
  130.                 $season $this->seasonService->getSeason();
  131.                 $slider $this->em->getRepository(mediaResidence::class)->findOneByLocation($residence->getId(), "content"$lang$season);
  132.                 if($slider instanceof mediaResidence) {
  133.                     $image_path $this->helper->asset($slider'imageFile');
  134.                     $image_link $this->cacheManager->getBrowserPath($image_path'offre');
  135.                     $photoProfil[$promo->getId()] = $image_link;
  136.                 }
  137.             }
  138.         }
  139.         asort($environnements);
  140.         asort($regions);
  141.         asort($villes);
  142.         if($offre_category == "ventes-flash") {
  143.             $parameter Yaml::parse(file_get_contents($this->appKernel->getProjectDir() .'/var/config/vente-flash.yaml'));
  144.             $venteFlash = new VenteFlash();
  145.             $venteFlash->setParameter($parameter);
  146.             $title $venteFlash->{'operationTitre' ucfirst($locale)};
  147.             $description =  $venteFlash->{'operationDescription' ucfirst($locale)};
  148.         } else {
  149.             $title $this->translator->trans("promos.".$offre_category ".title" , [], 'promos');
  150.             $description $this->translator->trans("promos.".$offre_category ".description" , [], 'promos');
  151.         }
  152.         $vars = [
  153.             "page_code" => "promo",
  154.             "filtres" => false,
  155.             "category" => $offre_category,
  156.             "promos" => $promos,
  157.             "environnements" => $environnements,
  158.             "regions" => $regions,
  159.             "villes" => $villes,
  160.             "photoProfil" => $photoProfil,
  161.             "title" => $title,
  162.             "description" => $description,
  163.         ];
  164.         return $this->render('/front/Promos/index.html.twig'$vars);
  165.     }
  166. }