src/Utils/Residences.php line 190

Open in your IDE?
  1. <?php
  2. namespace App\Utils;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  7. use Twig\Environment;
  8. use Symfony\Contracts\Translation\TranslatorInterface;
  9. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  10. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  11. use Symfony\Component\Routing\RouterInterface;
  12. use App\Services\ToolService;
  13. use App\Services\iresaService;
  14. use App\Utils\IresaManager;
  15. use App\Services\TravellerService;
  16. use App\Entity\assurance;
  17. use App\Entity\commande;
  18. use App\Entity\Destination;
  19. use App\Entity\Package;
  20. use App\Entity\InfosDiscover;
  21. use App\Entity\InfosDiscoverLink;
  22. use App\Entity\InfosEvent;
  23. use App\Entity\InfosFormuleBase;
  24. use App\Entity\InfosResidence;
  25. use App\Entity\OptionResidence;
  26. use App\Entity\Residence;
  27. use App\Entity\Service;
  28. use App\Entity\Typologie;
  29. use App\Entity\Language;
  30. class Residences
  31. {
  32.     const IRESA_LANG_DEFAULT 'fr';
  33.     private $em;
  34.     private $toolService;
  35.     private $iresaManager;
  36.     private $iresaService;
  37.     private $travellerService;
  38.     private $router;
  39.     private $locale;
  40.     private $lang;
  41.     private $langDefault;
  42.     private $twig;
  43.     private $packageIds;
  44.     private $session;
  45.     private $translator;
  46.     private $residences;
  47.     public function __construct(
  48.         EntityManagerInterface $em
  49.         ToolService $toolService
  50.         IresaManager $iresaManager
  51.         iresaService $iresaService
  52.         TravellerService $travellerService
  53.         Environment $twig
  54.         SessionInterface $session,
  55.         TranslatorInterface $translator
  56.         RouterInterface $router
  57.     ) {
  58.         $this->em $em;
  59.         $this->session $session;
  60.         $this->toolService $toolService;
  61.         $this->iresaService $iresaService;
  62.         $this->iresaManager $iresaManager;
  63.         $this->translator $translator;
  64.         $this->travellerService $travellerService;
  65.         $this->router $router;
  66.         $this->twig $twig;
  67.         $this->locale "fr";
  68.         $this->lang null;
  69.         $this->langDefault null;
  70.         $this->packageIds = [];
  71.     }
  72.     public function setLocale($locale) {
  73.         $this->locale $locale;
  74.         $this->lang  $this->em->getRepository(Language::class)->findOneByCode($locale);
  75.         $this->langDefault  $this->em->getRepository(Language::class)->findOneByCode('fr');
  76.     }
  77.     public function getPlanning($request$datearrivee$duree$type$delta$residence) {
  78.         $id $residence->getIdiresa();
  79.         $locale $this->locale;
  80.         $dispoPrestations = [];
  81.         $prestationDefault = [];
  82.         $planning = [];
  83.         $response =  [
  84.             "packages" => [],
  85.             "prestations" => [],
  86.             "listDatesDebut" => [],
  87.             "listDatesFin" => [],
  88.             "listDurees" => [],
  89.             "idPrestationDefault" => []
  90.         ];
  91.         
  92.         // les prestations de la date d'arrivée sélectionnée uniquement
  93.         $prestations $this->getPrestations($id$datearrivee$duree$locale$delta);
  94.         // Si pas de prestation avec la durée sélectionnée recherche sans préciser la durée
  95.         if(count($prestations['ListReponses']) == 0) { 
  96.             $message[] = "Pas de prestation sélectionnée avec cette date et cette durée";
  97.             $prestations $this->getPrestations($id$datearriveenull$locale$delta);
  98.         } 
  99.         
  100.         // Si toujours pas de réponse
  101.         if(count($prestations['ListReponses']) == 0) { 
  102.             
  103.             $travellers $this->travellerService->getTravellers();
  104.             $this->travellerService->init();
  105.             $response['redirect'] = true;
  106.             return $response;
  107.         }
  108.        
  109.         $packages $this->getPackages($id$prestations);
  110.         $idPrestationDefault $prestations['ListReponses'][0]['IdPrestation'];
  111.         
  112.         /*
  113.         foreach ($prestations['ListReponses'] as $prestation) { 
  114.             $dispoPrestations[] = $prestation;
  115.         }
  116.         if ($dispoPrestations) { 
  117.             $idPrestationDefault = $dispoPrestations[0]['IdPrestation'];
  118.             $message[] = "Prestations disponibles";
  119.             $idPrestationDefault = $dispoPrestations[0]['IdPrestation'];
  120.             $prestationDefault = [
  121.                 'id' => $idPrestationDefault,
  122.                 'nom_commercial' => $prestations[$idPrestationDefault]['zero']['nom_commercial'],
  123.                 'IdTypePrestation' => $dispoPrestations[0]['IdTypePrestation'],
  124.             ];
  125.         }
  126.         */
  127.         $now = new \DateTime();
  128.         $queryParams = [
  129.             'ListLieuHebergement' => $id
  130.             'IdPrestation' => $idPrestationDefault,
  131.             'noCache' => $now
  132.         ];
  133.         $planning $this->iresaManager->getPlanning($queryParams$datearrivee$type);
  134.         /*
  135.         if($request->isXmlHttpRequest()) {
  136.             // Si appel ajax, on a déjà le planning du mois, on recherche uniquement le planning pour le jour sélectionné
  137.             $planning = $this->iresaManager->getPlanning($queryParams, $datearrivee, "day");
  138.         } else {
  139.             // Si appel direct on veut connaitre le plannign du mois pour l'afficher
  140.             $planning = $this->iresaManager->getPlanning($queryParams, $datearrivee, "month");
  141.         }
  142.         */
  143.          
  144.         if(empty($planning['ListDatesDebut'])) {
  145.             if($request->isXmlHttpRequest()) {
  146.                 return $response;
  147.             }
  148.         }
  149.         $listDatesDebut = [];
  150.         foreach ($planning['ListDatesDebut'] as $date) {
  151.             $listDatesDebut[] = substr($date82) . '/'  .substr($date52) . '/' substr($date04);
  152.         }
  153.         $listDurees $planning['ListDurees'];
  154.         $listDatesFin = [];
  155.         foreach ($planning['ListDatesDebut'] as $date) {
  156.             foreach($listDurees as $duree) {
  157.                 // Ajouter la duree à la date et remplir le tableau $listDatesFin
  158.                 $dateFin = new \DateTime($date);
  159.                 $dateFin->add(new \DateInterval('P'.$duree.'D'));
  160.                 // push dateFin in french format to listrDatesFin if only it not present in array
  161.                 if(!in_array($dateFin->format('d/m/Y'), $listDatesFin)) {
  162.                     $listDatesFin[] = $dateFin->format('d/m/Y');
  163.                 }
  164.             }
  165.         }
  166.         $this->session->set('idPrestation'$idPrestationDefault);
  167.       
  168.         $response =  [
  169.             "packages" => $packages,
  170.             "prestations" => $prestations,
  171.             "listDatesDebut" => $listDatesDebut,
  172.             "listDatesFin" => $listDatesFin,
  173.             "listDurees" => $listDurees,
  174.             "idPrestationDefault" => $idPrestationDefault,
  175.             "queryParams" => $planning['queryParams']
  176.         ];
  177.         //throw $this->createNotFoundException('Résidence inexistante');
  178.         return $response;
  179.     }
  180.     public function getPackages($id$prestations) {
  181.         $residence =  $this->em->getRepository(Residence::class)->findOneBy(['idiresa' => $id]);
  182.         if(!$residence) {
  183.             return [];
  184.             //throw new \Exception('Résidence inexistante');
  185.         }
  186.         $params = [
  187.             'lang' => $this->lang,
  188.             'residence' => $residence
  189.         ];
  190.         $infosResidence $this->em->getRepository(InfosResidence::class)->findOneBy($params);
  191.         $formuleBase $this->em->getRepository(InfosFormuleBase::class)->findOneBy($params);
  192.         $params['commercialisation'] = true;
  193.         $listPackages $this->em->getRepository(Package::class)->findBy($params);
  194.         $packageIds = [];
  195.         foreach($listPackages as $package) {
  196.             $packageIds[] = $package->getIdIresa();
  197.         }
  198.         $packages = [];
  199.         $haslocative 0;
  200.         foreach ($prestations['ListReponses'] as $reponse) {
  201.             if( $reponse['IdPrestationHebergement'] != 0) {
  202.                 $idP $reponse['IdPrestationHebergement'];
  203.             } else {
  204.                 $idP $reponse['IdPrestation'];
  205.                 $haslocative 1;
  206.             }
  207.             if($haslocative == 1){
  208.                 $packages[0] = [
  209.                     'idIresa' => 0,
  210.                     'type' => 'formule_base',
  211.                     'entity' => $formuleBase,
  212.                     'nom' => $formuleBase->getNom(),
  213.                     'picto' => $formuleBase->getPicto(),
  214.                     'photoProfilDefault' => 'build/images/front/locatif-default.jpg',
  215.                     'photoProfil' => $formuleBase->getPhotoProfil(),
  216.                     'photoPopin' => $formuleBase->getPhotoPopin(),
  217.                     'descriptionPopin' => $formuleBase->getDescriptionPopin(),
  218.                     'prestaInc' => $formuleBase->getPrestaInc(),
  219.                     'prestaNoinc' => $formuleBase->getPrestaNoinc(),
  220.                     'serviceInc' => $formuleBase->getServiceInc(),
  221.                     'serviceNoinc' => $formuleBase->getServiceNoinc(),
  222.                     'description' =>  $formuleBase->getDescription(),
  223.                     //'resShortdesc' => $infosResidence->getResShortdesc(),
  224.                     'resBigdesc' => $infosResidence->getResBigdesc()
  225.                 ];
  226.             }
  227.         }
  228.         foreach($prestations['FichesPrestation'] as  $prestation) {
  229.             $package $this->em->getRepository(Package::class)->findOneBy([
  230.                 'lang' => $this->lang,
  231.                 'idIresa' => $prestation['IdElement'],
  232.                 'residence' => $residence
  233.             ]);
  234.             
  235.             if(array_key_exists("pack_heb"$prestation['ListFiches']) && in_array($package->getIdIresa(), $packageIds)) {
  236.                 $packages[] = [
  237.                     'idIresa' =>  $package->getIdIresa(),
  238.                     'type' => 'pack_heb',
  239.                     'entity' => $package,
  240.                     'nom' => $package->getNom(),
  241.                     'picto' => $package->getPicto(),
  242.                     'photoProfilDefault' => 'build/images/front/package-default.jpg',
  243.                     'photoProfil' => $package->getPhotoProfil(),
  244.                     'photoPopin' => $package->getPhotoPopin(),
  245.                     'descriptionPopin' => $package->getDescriptionPopin(),
  246.                     'prestaInc' => $formuleBase->getPrestaInc(),
  247.                     'prestaNoinc' => $formuleBase->getPrestaNoinc(),
  248.                     'serviceInc' => $package->getServiceInc(),
  249.                     'serviceNoinc' => $package->getServiceNoinc(),
  250.                     'description' =>  $package->getDescription(),
  251.                     //'resShortdesc' => $infosResidence->getResShortdesc(),
  252.                     'resBigdesc' => $infosResidence->getResBigdesc()
  253.                 ];
  254.             }
  255.             if(array_key_exists("pack_loisir"$prestation['ListFiches']) && in_array($package->getIdIresa(), $packageIds)) {
  256.                 $packages[] = [
  257.                     'idIresa' =>  $package->getIdIresa(),
  258.                     'type' => 'pack_loisir',
  259.                     'entity' => $package,
  260.                     'nom' => $package->getNom(),
  261.                     'picto' => $package->getPicto(),
  262.                     'photoProfilDefault' => 'build/images/front/package-default.jpg',
  263.                     'photoProfil' => $package->getPhotoProfil(),
  264.                     'photoPopin' => $package->getPhotoPopin(),
  265.                     'descriptionPopin' => $package->getDescriptionPopin(),
  266.                     'prestaInc' => $formuleBase->getPrestaInc(),
  267.                     'prestaNoinc' => $formuleBase->getPrestaNoinc(),
  268.                     'serviceInc' => $package->getServiceInc(),
  269.                     'serviceNoinc' => $package->getServiceNoinc(),
  270.                     'description' =>  $package->getDescription(),
  271.                     //'resShortdesc' => $infosResidence->getResShortdesc(),
  272.                     'resBigdesc' => $infosResidence->getResBigdesc()
  273.                 ];
  274.             }
  275.         }
  276.         return $packages;
  277.     }
  278.     public function getHebergements($prestations$selectedHebergementId$mode "") { 
  279.         $disabled "";
  280.         $formLoc "Formule temporaire";
  281.         $travellers $this->travellerService->getTravellers();
  282.         $nbPax $this->travellerService->travellers['nbPax'];
  283.         $dateArrivee $this->travellerService->travellers['actdatearrivee'] ;
  284.         $duree $this->travellerService->travellers['actnbnuits'] ;
  285.         $id =  $travellers['idResidence'];
  286.         $prestations $this->getPrestations($id$dateArrivee$duree$this->locale0);
  287.         $packages $this->getPackages($id$prestations);
  288.        
  289.         $contents "";
  290.         if(count($prestations['ListReponses']) > 0) {
  291.             $countHide 0;
  292.             foreach ($prestations['ListReponses'] as $key => $reponse) {
  293.                 if($reponse['IdPrestationHebergement'] == 0) {
  294.                     $idiresa $reponse['IdPrestation'];
  295.                 } else {
  296.                     $idiresa $reponse['IdPrestationHebergement'];
  297.                 }
  298.                 $params = [
  299.                     'lang' => $this->lang,
  300.                     'idiresa' => $idiresa
  301.                 ];
  302.         
  303.                 $typologie $this->em->getRepository(Typologie::class)->findOneBy($params);
  304.                 $typologie_nom "";
  305.                 $typologie_paxmax "";
  306.                 if($typologie instanceof Typologie) {
  307.                     $typologie_nom $typologie->getNom();
  308.                     $typologie_paxmax $typologie->getPaxMax();
  309.                 } else {
  310.                     $typologie "";
  311.                 }
  312.                 $prestations['ListReponses'][$key]['NomTypologie'] = $typologie_nom;
  313.                 $prestations['ListReponses'][$key]['PaxMax'] = $typologie_paxmax;
  314.             }
  315.             foreach ($prestations['Hebergements'] as $idPrestation => $ptsHeb) {
  316.                 foreach ($ptsHeb as $ptHeb) {
  317.                     $hebergement $prestations['ListReponses'][$ptHeb];
  318.                     if (array_key_exists('IdPrestationHebergement'$hebergement )) {
  319.                         
  320.                         if ($hebergement['IdPrestationHebergement'] == 0) {
  321.                             $idPrestationHebergement $hebergement['IdPrestation'];
  322.                             $idpack 0;
  323.                             $fichesPrestation =  $prestations['ListReponses'][$ptHeb];
  324.                             $formLoc =  $packages[0]['nom'];
  325.                         } else {
  326.                             $idPrestationHebergement $prestations['ListReponses'][$ptHeb];
  327.                             $idpack $hebergement['IdPrestation'];
  328.                             foreach($packages as $package) {
  329.                                 if($package['idIresa'] == $idpack) {
  330.                                     $formLoc =  $package['nom'];
  331.                                 }
  332.                             }
  333.                         }
  334.                         $capaciteMax $hebergement['CapaciteMax'];
  335.                       
  336.                         if ($nbPax <= $capaciteMax) {
  337.                             $contents .=  $this->twig->render('/front/Produit/recaptarif.html.twig', [
  338.                                 'hebergement' => $hebergement,
  339.                                 'idpack' => $idpack,
  340.                                 'formLoc' => $formLoc,
  341.                                 'paxMax' => $capaciteMax,
  342.                                 'selectedHebergement' => $selectedHebergementId,
  343.                                 'idPrestationHebergement' => $idPrestationHebergement                   
  344.                             ]);
  345.                         } else {
  346.                             echo "<!-- Hébergement: " $idPrestationHebergement " | PAX: " $nbPax " - CapaciteMax: " .  $capaciteMax " -->";
  347.                             $countHide++;
  348.                         }
  349.                     }
  350.                 }
  351.             }
  352.             if ( $countHide == count($prestations['ListReponses'])) {
  353.                 $contents .= '<div class="width-100 recherche-fp-tarif detailform margin-off">
  354.                     <p class="text-align-center">' $this->translator->trans('produit.residence.capacite_insufisante' , [], 'app') . '</p>
  355.                 </div>';
  356.                 $disabled "disabled";
  357.             }
  358.             
  359.             if(empty($travellerService->travellers['actdatearrivee'])) {
  360.                 $disabled "disabled";
  361.             }
  362.         }
  363.         
  364.         $contents .= '<div id="error-resa" class="error formule-bloc" style="display:none"></div>';
  365.         if($mode == "edit") {
  366.             $contents .= '<button type="submit" class="submitResaProduit" ' $disabled ' >' $this->translator->trans('ancre.actualiser_reservation' , [], 'app') . '</button>';
  367.         } else {
  368.             $contents .= '<button type="submit" class="submitResaProduit" ' $disabled ' >' $this->translator->trans('ancre.reserver' , [], 'app') . '</button>';
  369.         }
  370.         
  371.         return $contents;
  372.     }
  373.     function getPrestations($id$dateDebut$duree$locale$deltaJour) {
  374.         // Recherche formule locative
  375.         
  376.         $locale "fr";
  377.         $queryParams = [
  378.             'ListLieuHebergement' => $id
  379.             'DateDebut' => $dateDebut,
  380.             'DetailParPrestation' => 1,
  381.             'NbPages' => 50,
  382.             'NbDeltaJour' => $deltaJour,
  383.             'PageSize' => 360,
  384.             'Page' => 1
  385.         ];
  386.        
  387.         if ($duree ) {
  388.             $queryParams['Duree'] = $duree;  
  389.         }
  390.         $prestations $this->iresaManager->getAllPrestations($queryParams$locale);
  391.         
  392.         $this->packageIds $prestations['prestations'];
  393.         
  394.         $prestations['params'] =  $queryParams;
  395.         
  396.         return $prestations;
  397.     }
  398.     public function getFicheHebergement($detail) {
  399.         $details json_decode($detailtrue);
  400.         $reservation null;
  401.         $formule null;
  402.         if(!is_null($details)) {
  403.             $idPackage array_key_first($details['reservation']);
  404.             $reservation $details['reservation'][$idPackage];
  405.         }
  406.         $className $details['formule']['className'];
  407.         if($className != commande::FORMULE_UNKNOWN){
  408.             $formule $this->em->getRepository("App\\Entity\\{$className}")->findOneBy([
  409.                 'lang' => $this->lang,
  410.                 'id' => $details['residence'],
  411.                 'idIresa' => $details['formule']['idIresa']
  412.             ]);
  413.         }
  414.         
  415.         $typologie  $this->em->getRepository(Typologie::class)->findOneBy([
  416.             'lang' => $this->lang,
  417.             'idiresa' => $details['typologie']
  418.         ]);
  419.         $residence =  $this->em->getRepository(Residence::class)->findOneByIdiresa($reservation['idLieu']);
  420.         $fiche = [
  421.             "reservation" => $reservation,
  422.             "residence" => $residence,
  423.             "formule" => $formule,
  424.             "typologie" => $typologie
  425.         ];
  426.         return $fiche;
  427.     }
  428.     public function getSejours($hebergements$reponses$lang$nbPax 0) {
  429.         // On parcourt le tableau afin de ne garder que la typologie de CapaciteMax correspondant au nbPax et le tarif le plus petit pour la résidence
  430.         $fichesAll = [];
  431.         foreach ($reponses as $reponse) {
  432.             if($reponse['IdLieuHebergement'] > 0) {
  433.                 $idLieuHebergement $reponse['IdLieuHebergement'];
  434.                 $capaciteMax $reponse['CapaciteMax'];
  435.                 $prixTotal $reponse['PrixTotal'];
  436.                 // Si la capacité max est insuffisante, passer à l'itération suivante
  437.                 if (!($nbPax === || $capaciteMax >= $nbPax)) {
  438.                     continue;
  439.                 }
  440.                 // Si le lieu n'est pas encore enregistré ou si le prix est plus bas, on enregistre la réponse
  441.                 if (!isset($fichesAll[$idLieuHebergement]) || $prixTotal $fichesAll[$idLieuHebergement]['PrixTotal']) {
  442.                     $fichesAll[$idLieuHebergement] = $reponse;
  443.                 }
  444.             }
  445.         }
  446.         $fiches = [];
  447.         foreach($fichesAll as $idLieuHebergement => $fiche) {
  448.             $residence  $this->em->getRepository(Residence::class)->findOneEnabledByIdiresa($lang$idLieuHebergement);
  449.             if(!$residence) {
  450.                 continue;
  451.             }
  452.             $params = [
  453.                 'residence' => $residence,
  454.                 'lang_id' => $this->lang->getId()
  455.             ];
  456.             $infosResidence  $this->em->getRepository(InfosResidence::class)->findOneByLang($params);
  457.             $formuleBase  $this->em->getRepository(InfosFormuleBase::class)->findOneByLang($params);
  458.             $presta_inc = [];
  459.             $presta_noinc = [];
  460.             $nom "";
  461.             $res_lieu "";
  462.             $famille"";
  463.             $res_shortdesc "";
  464.             if(!is_null($formuleBase)) {
  465.                 $presta_inc = (Array) json_decode($formuleBase->getPrestaInc()); 
  466.                 $presta_noinc = (Array) json_decode($formuleBase->getPrestaNoinc());
  467.             }
  468.             
  469.            
  470.             //$famille = $hebergement['ListFiches']['zero']['famille'];
  471.             $nom $residence->getNom();
  472.             $res_lieu $infosResidence->getResLieu();
  473.             $res_shortdesc $infosResidence->getResShortdesc();
  474.             $infosHebergement = [
  475.                 'residence' => $residence,
  476.                 'presta_inc' => $presta_inc,
  477.                 'presta_noinc' => $presta_noinc,
  478.                 'nom' => $nom,
  479.                 'res_lieu' => $res_lieu,
  480.                 //'famille' => $famille,
  481.                 'res_shortdesc' => $res_shortdesc,
  482.             ];
  483.             
  484.             $fiches[] = array_merge($fiche$infosHebergement);
  485.         }
  486.         return $fiches;
  487.     }
  488.     public function getBreadCrumb($residence) {
  489.         $destinations[] = [
  490.             'nom' => strtolower($residence->getNom()),
  491.         ];
  492.         
  493.         $currentDestinationId $residence->getDestinationIdiresa();
  494.         if ($currentDestinationId != null) {
  495.             // get destination record width idiresa and lang
  496.             $currentDestination $this->em->getRepository(Destination::class)->findOneBy(['idIresa' => $currentDestinationId'lang' => $this->lang]);
  497.             $currentDestination $currentDestination->getParent();
  498.             // Tant que la destination actuelle a un parent, on continue de remonter
  499.             while ($currentDestination !== null) {
  500.                 // On ajoute la destination actuelle au début du tableau des destinations
  501.                 $destination = [
  502.                     'id' => $currentDestination->getId(),
  503.                     'nom' => strtolower($currentDestination->getTitreCourt()),
  504.                     'url' => $this->router->generate('ac_platform_destination_slug', [
  505.                         'slug' => $currentDestination->getCanonical()
  506.                     ])
  507.                 ];
  508.                 array_unshift($destinations$destination);
  509.                 // On remonte à la destination parente
  510.                 $currentDestination $currentDestination->getParent();
  511.                 
  512.             }
  513.         }
  514.         
  515.         $destination = [
  516.             'id' => 0,
  517.             'nom' => "Accueil",
  518.             'url' => $this->router->generate('ac_platform_homepage')
  519.         ];
  520.         array_unshift($destinations$destination);
  521.         return $destinations;
  522.     }
  523. }