src/Twig/Extension/GeneraleExtension.php line 569

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