src/Twig/Extension/GeneraleExtension.php line 613

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: MohamedAli
  5.  * Date: 21/04/2020
  6.  * Time: 01:46
  7.  */
  8. namespace App\Twig\Extension;
  9. use App\Controller\Generale\IndexController;
  10. use App\Service\Generale;
  11. use App\Service\WSCMS;
  12. use App\Service\WSEspaceAffilie;
  13. use App\Service\WSMaritime;
  14. use App\Service\WSSejourHotel;
  15. use App\Service\WSTransfert;
  16. use Doctrine\ORM\EntityManagerInterface;
  17. use Symfony\Component\HttpFoundation\Session\SessionInterface as Session;
  18. use Twig\TwigFilter;
  19. use Twig\TwigFunction;
  20. use Twig\Extension\AbstractExtension;
  21. class GeneraleExtension extends AbstractExtension
  22. {
  23.     /**
  24.      * GeneraleExtension constructor.
  25.      * @param $em
  26.      * @param $sejourHotel
  27.      * @param $cms
  28.      * @param $maritime
  29.      */
  30.     public function __construct(EntityManagerInterface $em, WSSejourHotel $sejourHotel, WSCMS $cms, WSEspaceAffilie $espaceAffilie, Session $session, Generale $service, WSTransfert $transfert, WSMaritime $maritime)
  31.     {
  32.         $this->em = $em;
  33.         $this->service = $service;
  34.         $this->sejourHotel = $sejourHotel;
  35.         $this->cms = $cms;
  36.         $this->espaceAffilie = $espaceAffilie;
  37.         $this->transfert = $transfert;
  38.         $this->session = $session;
  39.         $this->maritime = $maritime;
  40.     }
  41.     public function getFilters()
  42.     {
  43.         return array(
  44.             new TwigFilter('devise', array($this, 'devise')),
  45.             new TwigFilter('array_group_by', array($this, 'array_group_by')),
  46.             new TwigFilter('array_unique', 'array_unique'),
  47.             new TwigFilter('array_chunk', 'array_chunk'),
  48.             new TwigFilter('json_decode', 'json_decode'),
  49.             new TwigFilter('remove_size_styles', array($this, 'removeSizeStyles')),
  50.             new TwigFilter('changeDeviseInString', array($this, 'changeDeviseInString'))
  51.         );
  52.     }
  53.     public function getFunctions()
  54.     {
  55.         return [
  56.             new TwigFunction('getHotelIdsByFrontBlocSlug', [$this, 'getHotelIdsByFrontBlocSlug']),
  57.             new TwigFunction('group_periodes', [$this, 'groupPeriodes']),
  58.             new TwigFunction('getArrangements', [$this, 'getArrangements']),
  59.             new TwigFunction('listeAffilies', [$this, 'listeAffilies']),
  60.             new TwigFunction('referencementByRoute', [$this, 'referencementByRoute']),
  61.             new TwigFunction('rand_chaine', [$this, 'genererChaineAleatoire']),
  62.             new TwigFunction('getVillesHotels', [$this, 'getVillesHotels']),
  63.             new TwigFunction('getHotelsEquivalents', [$this, 'getHotelsEquivalents']),
  64.             new TwigFunction('getHotelEtiquette', [$this, 'getHotelEtiquette']),
  65.             new TwigFunction('getAllHotels', [$this, 'getAllHotels']),
  66.             new TwigFunction('getTopDestinations', [$this, 'getTopDestinations']),
  67.             new TwigFunction('getDestinations', [$this, 'getDestinations']),
  68.             new TwigFunction('getReferencement', [$this, 'getReferencement']),
  69.             new TwigFunction('getConfigurationPayement', [$this, 'getConfigurationPayement']),
  70.             new TwigFunction('roomsToArray', [$this, 'roomsToArray']),
  71.             new TwigFunction('file_exists', 'file_exists'),
  72.             new TwigFunction('html_entity_decode', 'html_entity_decode'),
  73.             new TwigFunction('file_get_contents', 'file_get_contents'),
  74.             new TwigFunction('getAgence', [$this, 'getAgence']),
  75.             new TwigFunction('getPointVente', [$this, 'getPointVente']),
  76.             new TwigFunction('getPartenaire', [$this, 'getPartenaire']),
  77.             new TwigFunction('getlienUtils', [$this, 'getlienUtils']),
  78.             new TwigFunction('ArticlesElement', [$this, 'ArticlesElement']),
  79.             new TwigFunction('getReseauxSociaux', [$this, 'getReseauxSociaux']),
  80.             new TwigFunction('getDevise', [$this, 'getDevise']),
  81.             new TwigFunction('deviseSelected', [$this, 'getDeviseSelected']),
  82.             new TwigFunction('deviseAgence', [$this, 'getDeviseAgence']),
  83.             new TwigFunction('getCoursEchange', [$this, 'getCoursEchange']),
  84.             new TwigFunction('getConfigAffichage', [$this, 'getConfigAffichage']),
  85.             new TwigFunction('getLanguesTraduction', [$this, 'getLanguesTraduction']),
  86.             new TwigFunction('checkCustomTemplate', [$this, 'checkCustomTemplate']),
  87.             new TwigFunction('method_exists', [$this, 'method_exists']),
  88.             new TwigFunction('checkActionInIndexController', [$this, 'checkActionInIndexController']),
  89.             new TwigFunction('getVille', [$this, 'getVille']),
  90.             new TwigFunction('getAmicale', [$this, 'getAmicale']),
  91.             new TwigFunction('domaineBack', [$this, 'domaineBack']),
  92.             new TwigFunction('routeReservation', [$this, 'routeReservation']),
  93.             new TwigFunction('hasModule', [$this, 'hasModule']),
  94.             new TwigFunction('configAmicale', [$this, 'configAmicale']),
  95.             new TwigFunction('usortPrices', [$this, 'usortPrices']),
  96.             new TwigFunction('getPrix', [$this, 'getPrix']),
  97.             new TwigFunction('getRouteById', [$this, 'getRouteById']),
  98.             new TwigFunction('getRouteByCode', [$this, 'getRouteByCode']),
  99.             new TwigFunction('getPort', [$this, 'getPort']),
  100.             new TwigFunction('getPrixCabine', [$this, 'getPrixCabine']),
  101.             new TwigFunction('getListPays', [$this, 'getListPays']),
  102.             new TwigFunction('getFlashPromo', [$this, 'getFlashPromo']),
  103.             new TwigFunction('GroupeVillesHotels', [$this, 'GroupeVillesHotels']),
  104.             new TwigFunction('contactPerso', [$this, 'contactPerso']),
  105.             new TwigFunction('getAccessControl', [$this, 'getAccessControl']),
  106.             new TwigFunction('getCityDetailsFromFrontBlocSlug', [$this, 'getCityDetailsFromFrontBlocSlug'])
  107.         ];
  108.     }
  109.     /**
  110.      * Transforme le paramètre hotel :
  111.      * - si c'est déjà une liste d'IDs (ex: "456-487-456-879") retourne tel quel
  112.      * - sinon considère que c'est un slug frontBloc, récupère les blocs et retourne
  113.      *   une chaîne d'IDs jointe par '-' si trouvée, sinon retourne la valeur d'origine
  114.      *
  115.      * @param string|null $hotel
  116.      * @return string|null
  117.      */
  118.     public function getHotelIdsByFrontBlocSlug($hotel)
  119.     {
  120.         if (preg_match('/^\d+(?:-\d+)*$/', $hotel)) {// 👉 Liste d'IDs ex: 456-487-456-879
  121.         } else {// 👉 Slug frontBloc ex: nos-soirees-reveillon-2026
  122.             $frontBlocs = $this->sejourHotel->FrontBlocs(['devise' => $this->session->get('devise'), 'version' => 'blocs']);
  123.             $frontBloc = array_column($frontBlocs, null, 'slug');
  124.             if (isset($frontBloc[$hotel]))
  125.                 return implode('-', explode(';', rtrim($frontBloc[$hotel]['hotelslistid'], ';')));
  126.         }
  127.         return $hotel;
  128.     }
  129.     /**
  130.      * Récupère les détails complets de la ville à partir du slug du FrontBloc
  131.      * Optimisé : utilise getAllHotels avec le premier ID hotel pour extraire l'ID ville
  132.      *
  133.      * @param string $hotelSlug Slug du FrontBloc (ex: 'hammamet')
  134.      * @return array|null Détails de la ville avec l'ID et toutes les informations
  135.      */
  136.     public function getCityDetailsFromFrontBlocSlug($hotelSlug)
  137.     {
  138.         $frontBlocs = $this->sejourHotel->FrontBlocs(['devise' => $this->session->get('devise'), 'version' => 'blocs']);
  139.         $frontBloc = array_column($frontBlocs, null, 'slug');
  140.         // Récupérer le FrontBloc par slug
  141.         if (!isset($frontBloc[$hotelSlug])) {
  142.             return null;
  143.         }
  144.         $bloc = $frontBloc[$hotelSlug];
  145.         // Extraire le premier ID hotel du FrontBloc
  146.         if (!isset($bloc['hotelslistidarray']) || empty($bloc['hotelslistidarray'])) {
  147.             return null;
  148.         }
  149.         // Récupérer le premier ID hotel
  150.         $hotelIds = $bloc['hotelslistidarray'];
  151.         $firstHotelId = reset($hotelIds); // Récupère le premier élément du tableau
  152.         // Récupérer les détails complets de ce hotel
  153.         $hotel = $this->getAllHotels($firstHotelId);
  154.         if (!$hotel) {
  155.             return null;
  156.         }
  157.         // Récupérer et retourner les détails complets de la ville
  158.         return $this->getVille($hotel['ville_id']);
  159.     }
  160.     public function getAccessControl()
  161.     {
  162.         return $_SESSION['APP_ACCESS_CONTROL'];
  163.     }
  164.     public function contactPerso()
  165.     {
  166.         return $this->cms->ContactPerso();
  167.     }
  168.     public function method_exists($object, $method_name)
  169.     {
  170.         return method_exists($object, $method_name);
  171.     }
  172.     public function listeAffilies()
  173.     {
  174.         return $this->espaceAffilie->ListeAffilies();
  175.     }
  176.     public function getArrangements()
  177.     {
  178.         return $this->sejourHotel->Arrangements()['ListBoarding'];
  179.     }
  180.     public function configAmicale($amicale)
  181.     {
  182.         $configAmicale = [];
  183.         if (file_exists('cache-webservices/configAmicale.php'))
  184.             $configAmicale = include 'cache-webservices/configAmicale.php';
  185.         return isset($configAmicale[$amicale]) ? $configAmicale[$amicale] : [];
  186.     }
  187.     public function checkActionInIndexController($action)
  188.     {
  189.         return method_exists(IndexController::class, $action);
  190.     }
  191.     public function roomsToArray($rooms)
  192.     {
  193.         $occChambre = explode(';', $rooms);
  194.         $rooms = [];
  195.         foreach ($occChambre as $occChr) {
  196.             $occPax = explode(',', $occChr);
  197.             if ($occPax[0] == "")
  198.                 $occPax[0] = "0";
  199.             $occPaxEnf = array_slice($occPax, 1);
  200.             $rooms[] = [
  201.                 'Adult' => $occPax[0],
  202.                 'children' => count($occPaxEnf),
  203.                 'Child' => $occPaxEnf
  204.             ];
  205.         }
  206.         return $rooms;
  207.     }
  208.     public function getReferencement()
  209.     {
  210.         return $this->cms->Referencement()['Referencement'];
  211.     }
  212.     public function getConfigurationPayement()
  213.     {
  214.         return $this->cms->ConfigurationPayement()['ConfigurationPayement'];
  215.     }
  216.     public function getFlashPromo()
  217.     {
  218.         return $this->sejourHotel->FlashPromo()['FlashPromo'];
  219.     }
  220.     public function getConfigAffichage()
  221.     {
  222.         if (!is_null($_configAffichage = $this->cms->ConfigFrontOffice()))
  223.             return $_configAffichage['ConfigFrontOffice'];
  224.     }
  225.     public function getCoursEchange()
  226.     {
  227.         $default_devise = [
  228.             "code" => "TND",
  229.             "montant" => 1,
  230.             "scale" => 3,
  231.             "symbole" => "DT",
  232.             "tndToDevise" => true,
  233.             "periodes" => []
  234.         ];
  235.         $devises = array_column($this->cms->Devise()['Devises'], null, 'code');
  236.         $devise = $this->session->get('devise', $default_devise);
  237.         if (isset($devises[$devise['code']]))
  238.             $devise = $devises[$devise['code']];
  239.         $_devise = array_filter($devise['periodes'], function ($d) {
  240.             $today = new \DateTime();
  241.             return new \DateTime($d['dateDebut']) <= $today && new \DateTime($d['dateFin']) >= $today;
  242.         });
  243.         if (!empty($_devise)) {
  244.             $devise['montant'] = current($_devise)['montant'];
  245.             $devise['tndToDevise'] = current($_devise)['tndToDevise'];
  246.         }
  247.         return [
  248.             'operation' => $devise['tndToDevise'] ? '*' : '/',
  249.             'montant' => $devise['montant'] ? $devise['montant'] : 1,
  250.             'symbole' => $devise['symbole'],
  251.             'scale' => $devise['scale']
  252.         ];
  253.     }
  254.     public function devise($montant, $showSymbole = false, $round = false)
  255.     {
  256.         if (!is_null($montant) && (is_float($montant) || is_numeric($montant))) {
  257.             $devise = self::getCoursEchange();
  258.             if ($round)
  259.                 $devise['scale'] = 0;
  260.             $symbole = "";
  261.             if ($showSymbole)
  262.                 $symbole = " {$devise['symbole']}";
  263.             eval("\$montant = $montant{$devise['operation']}{$devise['montant']};");
  264.             return number_format($montant, $devise['scale'], '.', '') . $symbole;
  265.         } else
  266.             return $montant;
  267.     }
  268.     function array_group_by($array, $key)
  269.     {
  270.         return $this->service->array_group_by($key, $array);
  271.     }
  272.     public function changeDeviseInString($str, $round = false)
  273.     {
  274.         $tabStr = explode(" ", $str);
  275.         $tabFinal = [];
  276.         foreach ($tabStr as $value) {
  277.             if (strtoupper($value) !== "DT" && strtoupper($value) !== "TND") {
  278.                 if (filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)) {
  279.                     array_push($tabFinal, $this->devise(filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION), true, $round));
  280.                 } else {
  281.                     array_push($tabFinal, $value);
  282.                 }
  283.             }
  284.         }
  285.         $res = implode(" ", $tabFinal);
  286.         return $res;
  287.     }
  288.     public function hasModule($module)
  289.     {
  290.         return $this->service->hasModule($module);
  291.     }
  292.     public function getDestinations()
  293.     {
  294.         return $this->transfert->Destination()['Destinations'];
  295.     }
  296.     public function getHotelsEquivalents()
  297.     {
  298.         return $this->cms->HotelsEquivalent()['HotelsEquivalent'];
  299.     }
  300.     public function getHotelEtiquette()
  301.     {
  302.         return $this->cms->HotelEtiquette()['Etiquettes'];
  303.     }
  304.     public function getAllHotels($id = null, $withEtiquette = false, $appartement = false)
  305.     {
  306.         $hotels = $this->cms->Hotel($appartement)['Hotels'];
  307.         if ($withEtiquette) {
  308.             $etiquettes = $this->cms->HotelEtiquette()['Etiquettes'];
  309.             $hotels = array_map(function ($hotel) use ($etiquettes) {
  310.                 $hotel['etiquettes'] = isset($etiquettes['etiquettes'][$hotel['id']]) ? $etiquettes['etiquettes'][$hotel['id']] : [];
  311.                 $hotel['etiquettesSaison'] = isset($etiquettes['etiquettesSaison'][$hotel['id']]) ? $etiquettes['etiquettesSaison'][$hotel['id']] : [];
  312.                 $hotel['etiquettesEmplacement'] = isset($etiquettes['etiquettesEmplacement'][$hotel['id']]) ? $etiquettes['etiquettesEmplacement'][$hotel['id']] : [];
  313.                 return $hotel;
  314.             }, $hotels);
  315.         }
  316.         // Optimisé : utilise array_column pour index par ID, plus rapide que array_filter
  317.         if (is_numeric($id)) {
  318.             $hotelsByIndex = array_column($hotels, null, 'id');
  319.             return $hotelsByIndex[$id] ?? null;
  320.         }
  321.         if (is_array($id)) {
  322.             // Optimisé : array_intersect_key est plus rapide que array_filter + in_array
  323.             $hotelsByIndex = array_column($hotels, null, 'id');
  324.             $idKeys = array_flip($id); // Convertir IDs en clés pour array_intersect_key
  325.             return array_intersect_key($hotelsByIndex, $idKeys);
  326.         }
  327.         return $hotels;
  328.     }
  329.     public function getTopDestinations()
  330.     {
  331.         return $this->cms->TopDestinations()['TopDestinations'];
  332.     }
  333.     public function getVillesHotels($produit = 'SHT', $onlySearchCity = false, $destination = '', $format = 'typeahead', $appartement = false)
  334.     {
  335.         $villes_hotels = [];
  336.         if ($produit == 'SHT') {
  337.             $villes_hotels = $this->cms->Ville()['Villes'];
  338.             if (!$onlySearchCity)
  339.                 $villes_hotels = array_merge($villes_hotels, $this->cms->Hotel($appartement)['Hotels']);
  340.         }
  341.         $_destination = explode('-', $destination);
  342.         $array_filter = [];
  343.         if (count($_destination) == 2) {
  344.             $type = $_destination[0];
  345.             $id = $_destination[1];
  346.             if ($produit == 'SHE')
  347.                 $villes_hotels = $this->sejourHotel->ListCityHotel([
  348.                     'Keywords' => $id,
  349.                     'onlySearchCity' => $onlySearchCity
  350.                 ])['ListCityHotel'];
  351.             $array_filter = array_filter($villes_hotels, function ($item) use ($type, $id) {
  352.                 return $item['type'] == $type and $item['id'] == $id;
  353.             });
  354.         }
  355.         if (!empty($array_filter))
  356.             $selected_destination = current($array_filter);
  357.         else {
  358.             $search_recommended = explode('###', $this->cms->ConfigFrontOffice()['ConfigFrontOffice']['HOTEL']['SEARCH_RECOMMENDED']);
  359.             if (count($search_recommended) > 1 && $destination == "all")
  360.                 $search_recommended = $search_recommended[1];
  361.             else
  362.                 $search_recommended = $search_recommended[0];
  363.             $key = array_search($search_recommended, array_column($villes_hotels, 'name'));
  364.             $selected_destination = $key !== false ? $villes_hotels[$key] : null;
  365.         }
  366.         if ($format == 'jsuites') {
  367.             $villes_hotels = array_merge(
  368.                 array_map("self::format_jsuites", $this->cms->GroupeVillesHotels()['GroupeVillesHotels']),
  369.                 array_map("self::format_jsuites", $villes_hotels)
  370.             );
  371.         }
  372.         return [
  373.             'destinations' => $villes_hotels,
  374.             'selected_destination' => $selected_destination
  375.         ];
  376.     }
  377.     function format_jsuites($item)
  378.     {
  379.         $_item = [
  380.             'pays' => $item['pays'],
  381.             'ville' => $item['ville'],
  382.             'group' => isset($item['group']) ? $item['group'] : ['v' => 'Ville', 'h' => 'Hôtel'][$item['type']],
  383.             'value' => "{$item['type']}-{$item['id']}",
  384.             'text' => "{$item['name']}, {$item['destination']}",
  385.             'image' => ['v' => "/assets-commun/images/icons-jsuites/map.svg", 'h' => "/assets-commun/images/icons-jsuites/chambre.svg"][$item['type']],
  386.         ];
  387.         if (isset($item['hotel'])) {
  388.             $_item['hotel'] = $item['hotel'];
  389.             $_item['ville_id'] = $item['ville_id'];
  390.             $_item['ville_name'] = $item['ville_name'];
  391.             $_item['hotel_id'] = $item['id'];
  392.             $_item['hotel_name'] = $item['name'];
  393.         } else {
  394.             $_item['ville_id'] = $item['id'];
  395.             $_item['ville_name'] = $item['name'];
  396.         }
  397.         return $_item;
  398.     }
  399.     function GroupeVillesHotels($version = 1)
  400.     {
  401.         if ($version == 2) {
  402.             $groupes = [];
  403.             foreach ($this->cms->GroupeVillesHotels()['GroupeVillesHotels'] as $item) {
  404.                 if (in_array($item ['group'], ['Top Ville', 'Top Hôtel'])) {
  405.                     $groupes[] = [
  406.                         'id' => $item['id'],
  407.                         'id_group' => $item['id_group'],
  408.                         'name' => $item ['name'],
  409.                         'destination' => $item ['destination'],
  410.                         'hotels' => $item ['hotels'],
  411.                         'code' => $item ['group']
  412.                     ];
  413.                 } else {
  414.                     if (!isset($groupes[$item ['group']]))
  415.                         $groupes[$item ['group']] = [
  416.                             'id' => $item['id'],
  417.                             'id_group' => $item['id_group'],
  418.                             'name' => $item ['group'],
  419.                             'destination' => $item ['destination'],
  420.                             'hotels' => $item ['hotels'],
  421.                             'code' => 'Top Destination'
  422.                         ];
  423.                     else {
  424.                         $groupes[$item ['group']]['id'] .= "-{$item['id']}";
  425.                         $groupes[$item ['group']]['hotels'] = implode('-', array_merge(explode('-', $groupes[$item ['group']]['hotels']), explode('-', $item['hotels'])));
  426.                     }
  427.                 }
  428.             }
  429.             return array_values($groupes);
  430.         }
  431.         return $this->cms->GroupeVillesHotels()['GroupeVillesHotels'];
  432.     }
  433.     public function checkCustomTemplate($template)
  434.     {
  435.         return $this->service->checkCustomTemplate($template);
  436.     }
  437.     public function getAgence()
  438.     {
  439.         return $this->cms->Agence()['Agence'];
  440.     }
  441.     public function getAmicale()
  442.     {
  443.         return $this->cms->Amicale();
  444.     }
  445.     public function domaineBack($domaine_back = null)
  446.     {
  447.         return $this->service->domaineBack($domaine_back);
  448.     }
  449.     public function getPointVente($franchise = true, $id = null)
  450.     {
  451.         $pointvente = $this->cms->PointVente(['franchis' => $franchise])['PointsVente'];
  452.         if ($id)
  453.             return array_column($pointvente, null, 'id')[$id];
  454.         return $pointvente;
  455.     }
  456.     public function getPartenaire()
  457.     {
  458.         $partenaire = $this->cms->Partenaire()['Partenaires'];
  459.         return $partenaire;
  460.     }
  461.     public function getlienUtils()
  462.     {
  463.         $lienutils = $this->cms->LienElement()['LiensElement'];
  464.         return $lienutils;
  465.     }
  466.     public
  467.     function referencementByRoute($route, $path, $balise)
  468.     {
  469.         $referencements = $this->cms->ReferencementRoute();
  470.         if (!isset($referencements['ReferencementRoute']))
  471.             return "";
  472.         $referencements = array_filter($referencements['ReferencementRoute'], function ($referencement) use ($route, $path) {
  473.             return (is_null($referencement['path']) or
  474.                 ($referencement['avecParams'] and $path === $referencement['path']) or
  475.                 //($referencement['avecParams'] and strpos($path, rtrim($referencement['path'], '/')) === 0) or
  476.                 (!$referencement['avecParams'] and $referencement['route'] == $route));
  477.         });
  478.         $injection = "";
  479.         foreach ($referencements as $referencement)
  480.             if ($_injection = $referencement["injection"][$balise])
  481.                 if ($balise == "h1")
  482.                     $injection .= "<h1>$_injection</h1>";
  483.                 elseif ($referencement["injection"]["mode_$balise"] == "css")
  484.                     $injection .= "<style>$_injection</style>";
  485.                 elseif ($referencement["injection"]["mode_$balise"] == "javascript")
  486.                     $injection .= "<script>$_injection</script>";
  487.                 else
  488.                     $injection .= $_injection;
  489.         return $injection;
  490.     }
  491.     public function ArticlesElement($domaine_back = null)
  492.     {
  493.         $article = $this->cms->ArticlesElement($domaine_back)['ArticlesElement'];
  494.         return $article;
  495.     }
  496.     public function getReseauxSociaux()
  497.     {
  498.         $reseauxsociaux = $this->cms->ReseauxSociaux()['ReseauxSociaux'];
  499.         return $reseauxsociaux;
  500.     }
  501.     public function getDevise()
  502.     {
  503.         $devise = $this->cms->Devise()['Devises'];
  504.         return $devise;
  505.     }
  506.     public function getVille($id = null)
  507.     {
  508.         $villes = $this->cms->Ville()['Villes'];
  509.         if ($id) return array_column($villes, null, 'id')[$id];
  510.         return $villes;
  511.     }
  512.     public function getDeviseSelected()
  513.     {
  514.         return $this->session->get('devise');
  515.     }
  516.     public function getDeviseAgence()
  517.     {
  518.         return $this->session->get('devise-agence');
  519.     }
  520.     public function getLanguesTraduction()
  521.     {
  522.         $langues = array(
  523.             'af' =>
  524.                 array(
  525.                     'flag' => 'af',
  526.                     'libelle' => 'Afrikanns',
  527.                 ),
  528.             'sq' =>
  529.                 array(
  530.                     'flag' => 'sq',
  531.                     'libelle' => 'Albanais',
  532.                 ),
  533.             'ar' =>
  534.                 array(
  535.                     'flag' => 'tn',
  536.                     'libelle' => 'Arabe',
  537.                 ),
  538.             'hy' =>
  539.                 array(
  540.                     'flag' => 'hy',
  541.                     'libelle' => 'Arménien',
  542.                 ),
  543.             'eu' =>
  544.                 array(
  545.                     'flag' => 'eu',
  546.                     'libelle' => 'Basque',
  547.                 ),
  548.             'bn' =>
  549.                 array(
  550.                     'flag' => 'bn',
  551.                     'libelle' => 'Bengali',
  552.                 ),
  553.             'bg' =>
  554.                 array(
  555.                     'flag' => 'bg',
  556.                     'libelle' => 'Bulgare',
  557.                 ),
  558.             'ca' =>
  559.                 array(
  560.                     'flag' => 'ca',
  561.                     'libelle' => 'Catalan',
  562.                 ),
  563.             'km' =>
  564.                 array(
  565.                     'flag' => 'km',
  566.                     'libelle' => 'Cambodgien',
  567.                 ),
  568.             'zh' =>
  569.                 array(
  570.                     'flag' => 'zh',
  571.                     'libelle' => 'Mandarin Chinois)',
  572.                 ),
  573.             'hr' =>
  574.                 array(
  575.                     'flag' => 'hr',
  576.                     'libelle' => 'Croation',
  577.                 ),
  578.             'cs' =>
  579.                 array(
  580.                     'flag' => 'cs',
  581.                     'libelle' => 'Tchèque',
  582.                 ),
  583.             'da' =>
  584.                 array(
  585.                     'flag' => 'da',
  586.                     'libelle' => 'Danois',
  587.                 ),
  588.             'nl' =>
  589.                 array(
  590.                     'flag' => 'nl',
  591.                     'libelle' => 'Néerlandais',
  592.                 ),
  593.             'en' =>
  594.                 array(
  595.                     'flag' => 'us',
  596.                     'libelle' => 'Anglais',
  597.                 ),
  598.             'et' =>
  599.                 array(
  600.                     'flag' => 'et',
  601.                     'libelle' => 'Estonien',
  602.                 ),
  603.             'fj' =>
  604.                 array(
  605.                     'flag' => 'fj',
  606.                     'libelle' => 'Fidji',
  607.                 ),
  608.             'fi' =>
  609.                 array(
  610.                     'flag' => 'fi',
  611.                     'libelle' => 'Finlandais',
  612.                 ),
  613.             'fr' =>
  614.                 array(
  615.                     'flag' => 'fr',
  616.                     'libelle' => 'Français',
  617.                 ),
  618.             'ka' =>
  619.                 array(
  620.                     'flag' => 'ka',
  621.                     'libelle' => 'Géorgien',
  622.                 ),
  623.             'de' =>
  624.                 array(
  625.                     'flag' => 'de',
  626.                     'libelle' => 'Allemand',
  627.                 ),
  628.             'el' =>
  629.                 array(
  630.                     'flag' => 'el',
  631.                     'libelle' => 'Grec',
  632.                 ),
  633.             'gu' =>
  634.                 array(
  635.                     'flag' => 'gu',
  636.                     'libelle' => 'Gujarati',
  637.                 ),
  638.             'he' =>
  639.                 array(
  640.                     'flag' => 'he',
  641.                     'libelle' => 'Hébreu',
  642.                 ),
  643.             'hi' =>
  644.                 array(
  645.                     'flag' => 'hi',
  646.                     'libelle' => 'Hindi',
  647.                 ),
  648.             'hu' =>
  649.                 array(
  650.                     'flag' => 'hu',
  651.                     'libelle' => 'Hongrois',
  652.                 ),
  653.             'is' =>
  654.                 array(
  655.                     'flag' => 'is',
  656.                     'libelle' => 'Islandais',
  657.                 ),
  658.             'id' =>
  659.                 array(
  660.                     'flag' => 'id',
  661.                     'libelle' => 'Indonésien',
  662.                 ),
  663.             'ga' =>
  664.                 array(
  665.                     'flag' => 'ga',
  666.                     'libelle' => 'Irlandais',
  667.                 ),
  668.             'it' =>
  669.                 array(
  670.                     'flag' => 'it',
  671.                     'libelle' => 'Italien',
  672.                 ),
  673.             'ja' =>
  674.                 array(
  675.                     'flag' => 'ja',
  676.                     'libelle' => 'Japonais',
  677.                 ),
  678.             'jw' =>
  679.                 array(
  680.                     'flag' => 'jw',
  681.                     'libelle' => 'Javanais',
  682.                 ),
  683.             'ko' =>
  684.                 array(
  685.                     'flag' => 'ko',
  686.                     'libelle' => 'Coréen',
  687.                 ),
  688.             'la' =>
  689.                 array(
  690.                     'flag' => 'la',
  691.                     'libelle' => 'Latin',
  692.                 ),
  693.             'lv' =>
  694.                 array(
  695.                     'flag' => 'lv',
  696.                     'libelle' => 'Letton',
  697.                 ),
  698.             'lt' =>
  699.                 array(
  700.                     'flag' => 'lt',
  701.                     'libelle' => 'Lituanien',
  702.                 ),
  703.             'mk' =>
  704.                 array(
  705.                     'flag' => 'mk',
  706.                     'libelle' => 'Macédonien',
  707.                 ),
  708.             'ms' =>
  709.                 array(
  710.                     'flag' => 'ms',
  711.                     'libelle' => 'Malais',
  712.                 ),
  713.             'ml' =>
  714.                 array(
  715.                     'flag' => 'ml',
  716.                     'libelle' => 'Malayalam',
  717.                 ),
  718.             'mt' =>
  719.                 array(
  720.                     'flag' => 'mt',
  721.                     'libelle' => 'Maltais',
  722.                 ),
  723.             'mi' =>
  724.                 array(
  725.                     'flag' => 'mi',
  726.                     'libelle' => 'Maori',
  727.                 ),
  728.             'mr' =>
  729.                 array(
  730.                     'flag' => 'mr',
  731.                     'libelle' => 'Marathi',
  732.                 ),
  733.             'mn' =>
  734.                 array(
  735.                     'flag' => 'mn',
  736.                     'libelle' => 'Mongol',
  737.                 ),
  738.             'ne' =>
  739.                 array(
  740.                     'flag' => 'ne',
  741.                     'libelle' => 'Népalais',
  742.                 ),
  743.             'no' =>
  744.                 array(
  745.                     'flag' => 'no',
  746.                     'libelle' => 'Norvégien',
  747.                 ),
  748.             'fa' =>
  749.                 array(
  750.                     'flag' => 'fa',
  751.                     'libelle' => 'Persan',
  752.                 ),
  753.             'pl' =>
  754.                 array(
  755.                     'flag' => 'pl',
  756.                     'libelle' => 'Polonais',
  757.                 ),
  758.             'pt' =>
  759.                 array(
  760.                     'flag' => 'pt',
  761.                     'libelle' => 'Portugais',
  762.                 ),
  763.             'pa' =>
  764.                 array(
  765.                     'flag' => 'pa',
  766.                     'libelle' => 'Punjabi',
  767.                 ),
  768.             'qu' =>
  769.                 array(
  770.                     'flag' => 'qu',
  771.                     'libelle' => 'Quechua',
  772.                 ),
  773.             'ro' =>
  774.                 array(
  775.                     'flag' => 'ro',
  776.                     'libelle' => 'Roumain',
  777.                 ),
  778.             'ru' =>
  779.                 array(
  780.                     'flag' => 'ru',
  781.                     'libelle' => 'Russe',
  782.                 ),
  783.             'sm' =>
  784.                 array(
  785.                     'flag' => 'sm',
  786.                     'libelle' => 'Samoan',
  787.                 ),
  788.             'sr' =>
  789.                 array(
  790.                     'flag' => 'sr',
  791.                     'libelle' => 'Serbe',
  792.                 ),
  793.             'sk' =>
  794.                 array(
  795.                     'flag' => 'sk',
  796.                     'libelle' => 'Slovaque',
  797.                 ),
  798.             'sl' =>
  799.                 array(
  800.                     'flag' => 'sl',
  801.                     'libelle' => 'Slovène',
  802.                 ),
  803.             'es' =>
  804.                 array(
  805.                     'flag' => 'es',
  806.                     'libelle' => 'Espanol',
  807.                 ),
  808.             'sw' =>
  809.                 array(
  810.                     'flag' => 'sw',
  811.                     'libelle' => 'Swahili',
  812.                 ),
  813.             'sv' =>
  814.                 array(
  815.                     'flag' => 'sv',
  816.                     'libelle' => 'Suédois',
  817.                 ),
  818.             'ta' =>
  819.                 array(
  820.                     'flag' => 'ta',
  821.                     'libelle' => 'Tamil',
  822.                 ),
  823.             'tt' =>
  824.                 array(
  825.                     'flag' => 'tt',
  826.                     'libelle' => 'Tatar',
  827.                 ),
  828.             'te' =>
  829.                 array(
  830.                     'flag' => 'te',
  831.                     'libelle' => 'Telugu',
  832.                 ),
  833.             'th' =>
  834.                 array(
  835.                     'flag' => 'th',
  836.                     'libelle' => 'Thaïlandais',
  837.                 ),
  838.             'bo' =>
  839.                 array(
  840.                     'flag' => 'bo',
  841.                     'libelle' => 'Tibétain',
  842.                 ),
  843.             'to' =>
  844.                 array(
  845.                     'flag' => 'to',
  846.                     'libelle' => 'Tonga',
  847.                 ),
  848.             'tr' =>
  849.                 array(
  850.                     'flag' => 'tr',
  851.                     'libelle' => 'Turc',
  852.                 ),
  853.             'uk' =>
  854.                 array(
  855.                     'flag' => 'uk',
  856.                     'libelle' => 'Ukrainien',
  857.                 ),
  858.             'ur' =>
  859.                 array(
  860.                     'flag' => 'ur',
  861.                     'libelle' => 'Ourdou',
  862.                 ),
  863.             'uz' =>
  864.                 array(
  865.                     'flag' => 'uz',
  866.                     'libelle' => 'Ouzbek',
  867.                 ),
  868.             'vi' =>
  869.                 array(
  870.                     'flag' => 'vi',
  871.                     'libelle' => 'Vietnamien',
  872.                 ),
  873.             'cy' =>
  874.                 array(
  875.                     'flag' => 'cy',
  876.                     'libelle' => 'Gallois',
  877.                 ),
  878.             'xh' =>
  879.                 array(
  880.                     'flag' => 'xh',
  881.                     'libelle' => 'Xhosa',
  882.                 )
  883.         );
  884.         if (file_exists("langues-traduction.php"))
  885.             $langues = include "langues-traduction.php";
  886.         return $langues;
  887.     }
  888.     function genererChaineAleatoire($longueur = 10)
  889.     {
  890.         $caracteres = 'abcdefghijklmnopqrstuvwxyz';
  891.         $chaineAleatoire = '';
  892.         for ($i = 0; $i < $longueur; $i++)
  893.             $chaineAleatoire .= $caracteres[rand(0, strlen($caracteres) - 1)];
  894.         return $chaineAleatoire;
  895.     }
  896.     public function routeReservation()
  897.     {
  898.         $routes = [];
  899.         if ($this->hasModule('sejour'))
  900.             $routes[] = [
  901.                 'libelle' => 'Séjour',
  902.                 'route_liste' => 'espace_affilie_reservations',
  903.                 'route_details' => 'espace_affilie_reservation_detail'
  904.             ];
  905.         if ($this->hasModule('voyages-organise')) {
  906.             $routes[] = [
  907.                 'libelle' => 'Voyages',
  908.                 'route_liste' => 'espace_affilie_reservations_voyageorganise',
  909.                 'route_details' => 'espace_affilie_reservation_detail_voyageorganise'
  910.             ];
  911.             $routes[] = [
  912.                 'libelle' => 'Omra',
  913.                 'route_liste' => 'espace_affilie_reservations_omraorganise',
  914.                 'route_details' => 'espace_affilie_reservation_detail_omraorganise'
  915.             ];
  916.             $routes[] = [
  917.                 'libelle' => 'Circuits',
  918.                 'route_liste' => 'espace_affilie_reservations_circuitorganise',
  919.                 'route_details' => 'espace_affilie_reservation_detail_circuitorganise'
  920.             ];
  921.             $routes[] = [
  922.                 'libelle' => 'Croisières',
  923.                 'route_liste' => 'espace_affilie_reservations_croisieres',
  924.                 'route_details' => 'espace_affilie_reservation_detail_croisieres'
  925.             ];
  926.             $routes[] = [
  927.                 'libelle' => 'Transfert',
  928.                 'route_liste' => 'espace_affilie_reservations_transfert',
  929.                 'route_details' => 'espace_affilie_detail_reservation_transfert'
  930.             ];
  931.             $routes[] = [
  932.                 'libelle' => 'Liste',
  933.                 'route_liste' => 'espace_affilie_reservations_liste',
  934.             ];
  935.         }
  936.         if ($this->hasModule('voyages-package'))
  937.             $routes[] = [
  938.                 'libelle' => 'Package',
  939.                 'route_liste' => 'espace_affilie_reservations_package',
  940.                 'route_details' => 'espace_affilie_reservation_detail_package'
  941.             ];
  942.         return $routes;
  943.     }
  944.     public function usortPrices($sailings)
  945.     {
  946.         $sort_prices = $sailings['prices'];
  947.         usort($sort_prices, function ($a, $b) {
  948.             return $a['TicketTotal'] > $b['TicketTotal'];
  949.         });
  950.         return $sort_prices;
  951.     }
  952.     public function getPrix($sailings, $type = 'TicketTotal')
  953.     {
  954.         $prix = 0;
  955.         $array = array();
  956.         $sort_array = array();
  957.         foreach ($sailings as $k => $sailing) {
  958.             foreach ($sailing["prices"] as $price) {
  959.                 $array[$k][$price["Index"]]['TicketTotal'] = $price["TicketTotal"];
  960.                 $array[$k][$price["Index"]]['GrossTotal'] = $price["GrossTotal"];
  961.             }
  962.         }
  963.         foreach ($array as $value) {
  964.             usort($value, function ($a, $b) {
  965.                 //return $a['TicketTotal'] > $b['TicketTotal'];
  966.             });
  967.             $sort_array[] = $value;
  968.         }
  969.         foreach ($sort_array as $value) {
  970.             $prix += $value[0][$type];
  971.         }
  972.         return $prix;
  973.     }
  974.     public function getRouteById($id, $provider = null)
  975.     {
  976.         $param = [
  977.             'id' => $id,
  978.             'provider' => $provider
  979.         ];
  980.         $route = $this->maritime->getRoute($param);
  981.         return $route['Route'];
  982.     }
  983.     public function getRouteByCode($code, $provider = null)
  984.     {
  985.         $param = [
  986.             'code' => $code,
  987.             'provider' => $provider
  988.         ];
  989.         $route = $this->maritime->getRoute($param);
  990.         return $route['Route'];
  991.     }
  992.     public function getPort($code, $provider = null)
  993.     {
  994.         $param = [
  995.             'code' => $code,
  996.             'provider' => $provider
  997.         ];
  998.         $port = $this->maritime->getPort($param);
  999.         return $port['Port'];
  1000.     }
  1001.     public function getPrixCabine($sailings, $cabines)
  1002.     {
  1003.         $prix = 0;
  1004.         $currency = null;
  1005.         $array = array();
  1006.         $arrayCabine = explode(',', $cabines);
  1007.         foreach ($sailings as $k => $sailing) {
  1008.             $prix += $sailing["prices"][$arrayCabine[$k]]["TicketTotal"];
  1009.         }
  1010.         foreach ($array as $value) {
  1011.             $prix += min($value);
  1012.         }
  1013.         return $prix;
  1014.     }
  1015.     public function getListPays()
  1016.     {
  1017.         return $this->cms->Pays()['Pays'];
  1018.     }
  1019.     public function removeSizeStyles($html)
  1020.     {
  1021.         // Supprime tous les attributs class
  1022.         $html = preg_replace('/\s*class\s*=\s*["\'][^"\']*["\']/i', '', $html);
  1023.         // Supprime les propriétés de taille dans les attributs style
  1024.         $html = preg_replace_callback(
  1025.             '/style\s*=\s*["\'][^"\']*?(width|height|min-width|min-height|max-width|max-height)\s*:\s*[^;"\']+;?\s*[^"\']*?["\']/i',
  1026.             function ($match) {
  1027.                 // Supprime les propriétés de taille tout en préservant les autres styles
  1028.                 $cleaned = preg_replace(
  1029.                     '/(width|height|min-width|min-height|max-width|max-height)\s*:\s*[^;"\']+;?\s*/i',
  1030.                     '',
  1031.                     $match[0]
  1032.                 );
  1033.                 // Supprime les attributs style vides
  1034.                 return preg_replace('/\s*style\s*=\s*["\']\s*["\']/i', '', $cleaned);
  1035.             },
  1036.             $html
  1037.         );
  1038.         // Convertit &lt;, &gt;, &amp;, etc. en leurs caractères réels
  1039.         return html_entity_decode($html, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  1040.     }
  1041.     /**
  1042.      * Regroupe les périodes par mois/année et ville de départ
  1043.      * Ajoute le minPrix pour chaque pack
  1044.      *
  1045.      * @param array $periodes
  1046.      * @return array Tableau des périodes regroupées
  1047.      */
  1048.     public function groupPeriodes(array $periodes): array
  1049.     {
  1050.         $months = [
  1051.             1 => 'Janvier', 2 => 'Février', 3 => 'Mars', 4 => 'Avril',
  1052.             5 => 'Mai', 6 => 'Juin', 7 => 'Juillet', 8 => 'Août',
  1053.             9 => 'Septembre', 10 => 'Octobre', 11 => 'Novembre', 12 => 'Décembre'
  1054.         ];
  1055.         $grouped = [];
  1056.         foreach ($periodes as $periode) {
  1057.             // Créer la clé de regroupement
  1058.             $dateDebut = new \DateTime($periode['du']);
  1059.             $monthNumber = (int)$dateDebut->format('n');
  1060.             $mois = $months[$monthNumber] ?? '';
  1061.             $annee = $dateDebut->format('Y');
  1062.             $ville = isset($periode['plans'][0]['ville']) ? $periode['plans'][0]['ville'] : 'Non défini';
  1063.             $groupKey = $mois . ' ' . $annee . ' au départ de ' . $ville;
  1064.             // Initialiser le groupe s'il n'existe pas
  1065.             if (!isset($grouped[$groupKey])) {
  1066.                 $grouped[$groupKey] = [];
  1067.             }
  1068.             // Traiter les packs de la période pour ajouter minPrix
  1069.             if (isset($periode['PACKS']) && is_array($periode['PACKS'])) {
  1070.                 foreach ($periode['PACKS'] as $index => $pack) {
  1071.                     $prices = [];
  1072.                     $tarifs = $pack['tarifs'] ?? [];
  1073.                     // Collecter les prix des chambres adultes
  1074.                     foreach (['single', 'double', 'triple', 'quadruple'] as $type) {
  1075.                         if (isset($tarifs[$type])) {
  1076.                             $prices[] = (float)$tarifs[$type]['vente'];
  1077.                         }
  1078.                     }
  1079.                     // Calculer le prix minimum
  1080.                     $periode['PACKS'][$index]['minPrix'] = !empty($prices) ? min($prices) : null;
  1081.                 }
  1082.             }
  1083.             // Ajouter la période au groupe
  1084.             $grouped[$groupKey][] = $periode;
  1085.         }
  1086.         // Transformer en tableau avec structure claire
  1087.         $result = [];
  1088.         foreach ($grouped as $libelle => $periodes) {
  1089.             $result[] = [
  1090.                 'libelle' => $libelle,
  1091.                 'periodes' => $periodes
  1092.             ];
  1093.         }
  1094.         return $result;
  1095.     }
  1096. }