<?php
/**
* Created by PhpStorm.
* User: MohamedAli
* Date: 21/04/2020
* Time: 01:46
*/
namespace App\Twig\Extension;
use App\Controller\Generale\IndexController;
use App\Service\Generale;
use App\Service\WSCMS;
use App\Service\WSEspaceAffilie;
use App\Service\WSMaritime;
use App\Service\WSSejourHotel;
use App\Service\WSTransfert;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface as Session;
use Twig\TwigFilter;
use Twig\TwigFunction;
use Twig\Extension\AbstractExtension;
class GeneraleExtension extends AbstractExtension
{
/**
* GeneraleExtension constructor.
* @param $em
* @param $sejourHotel
* @param $cms
* @param $maritime
*/
public function __construct(EntityManagerInterface $em, WSSejourHotel $sejourHotel, WSCMS $cms, WSEspaceAffilie $espaceAffilie, Session $session, Generale $service, WSTransfert $transfert, WSMaritime $maritime)
{
$this->em = $em;
$this->service = $service;
$this->sejourHotel = $sejourHotel;
$this->cms = $cms;
$this->espaceAffilie = $espaceAffilie;
$this->transfert = $transfert;
$this->session = $session;
$this->maritime = $maritime;
}
public function getFilters()
{
return array(
new TwigFilter('devise', array($this, 'devise')),
new TwigFilter('array_group_by', array($this, 'array_group_by')),
new TwigFilter('array_unique', 'array_unique'),
new TwigFilter('array_chunk', 'array_chunk'),
new TwigFilter('json_decode', 'json_decode'),
new TwigFilter('remove_size_styles', array($this, 'removeSizeStyles')),
new TwigFilter('changeDeviseInString', array($this, 'changeDeviseInString'))
);
}
public function getFunctions()
{
return [
new TwigFunction('hotel_to_ids', [$this, 'hotelToIds']),
new TwigFunction('group_periodes', [$this, 'groupPeriodes']),
new TwigFunction('getArrangements', [$this, 'getArrangements']),
new TwigFunction('listeAffilies', [$this, 'listeAffilies']),
new TwigFunction('referencementByRoute', [$this, 'referencementByRoute']),
new TwigFunction('rand_chaine', [$this, 'genererChaineAleatoire']),
new TwigFunction('getVillesHotels', [$this, 'getVillesHotels']),
new TwigFunction('getHotelsEquivalents', [$this, 'getHotelsEquivalents']),
new TwigFunction('getHotelEtiquette', [$this, 'getHotelEtiquette']),
new TwigFunction('getAllHotels', [$this, 'getAllHotels']),
new TwigFunction('getTopDestinations', [$this, 'getTopDestinations']),
new TwigFunction('getDestinations', [$this, 'getDestinations']),
new TwigFunction('getReferencement', [$this, 'getReferencement']),
new TwigFunction('getConfigurationPayement', [$this, 'getConfigurationPayement']),
new TwigFunction('roomsToArray', [$this, 'roomsToArray']),
new TwigFunction('file_exists', 'file_exists'),
new TwigFunction('html_entity_decode', 'html_entity_decode'),
new TwigFunction('file_get_contents', 'file_get_contents'),
new TwigFunction('getAgence', [$this, 'getAgence']),
new TwigFunction('getPointVente', [$this, 'getPointVente']),
new TwigFunction('getPartenaire', [$this, 'getPartenaire']),
new TwigFunction('getlienUtils', [$this, 'getlienUtils']),
new TwigFunction('ArticlesElement', [$this, 'ArticlesElement']),
new TwigFunction('getReseauxSociaux', [$this, 'getReseauxSociaux']),
new TwigFunction('getDevise', [$this, 'getDevise']),
new TwigFunction('deviseSelected', [$this, 'getDeviseSelected']),
new TwigFunction('deviseAgence', [$this, 'getDeviseAgence']),
new TwigFunction('getCoursEchange', [$this, 'getCoursEchange']),
new TwigFunction('getConfigAffichage', [$this, 'getConfigAffichage']),
new TwigFunction('getLanguesTraduction', [$this, 'getLanguesTraduction']),
new TwigFunction('checkCustomTemplate', [$this, 'checkCustomTemplate']),
new TwigFunction('method_exists', [$this, 'method_exists']),
new TwigFunction('checkActionInIndexController', [$this, 'checkActionInIndexController']),
new TwigFunction('getVille', [$this, 'getVille']),
new TwigFunction('getAmicale', [$this, 'getAmicale']),
new TwigFunction('domaineBack', [$this, 'domaineBack']),
new TwigFunction('routeReservation', [$this, 'routeReservation']),
new TwigFunction('hasModule', [$this, 'hasModule']),
new TwigFunction('configAmicale', [$this, 'configAmicale']),
new TwigFunction('usortPrices', [$this, 'usortPrices']),
new TwigFunction('getPrix', [$this, 'getPrix']),
new TwigFunction('getRouteById', [$this, 'getRouteById']),
new TwigFunction('getRouteByCode', [$this, 'getRouteByCode']),
new TwigFunction('getPort', [$this, 'getPort']),
new TwigFunction('getPrixCabine', [$this, 'getPrixCabine']),
new TwigFunction('getListPays', [$this, 'getListPays']),
new TwigFunction('getFlashPromo', [$this, 'getFlashPromo']),
new TwigFunction('GroupeVillesHotels', [$this, 'GroupeVillesHotels']),
new TwigFunction('contactPerso', [$this, 'contactPerso']),
new TwigFunction('getAccessControl', [$this, 'getAccessControl'])
];
}
/**
* Transforme le paramètre hotel :
* - si c'est déjà une liste d'IDs (ex: "456-487-456-879") retourne tel quel
* - sinon considère que c'est un slug frontBloc, récupère les blocs et retourne
* une chaîne d'IDs jointe par '-' si trouvée, sinon retourne la valeur d'origine
*
* @param string|null $hotel
* @return string|null
*/
public function hotelToIds($hotel)
{
if (preg_match('/^\d+(?:-\d+)*$/', $hotel)) {// 👉 Liste d'IDs ex: 456-487-456-879
} else {// 👉 Slug frontBloc ex: nos-soirees-reveillon-2026
$frontBlocs = $this->sejourHotel->FrontBlocs(['devise' => $this->session->get('devise'), 'version' => 'blocs']);
$frontBloc = array_column($frontBlocs, null, 'slug');
if (isset($frontBloc[$hotel]))
return implode('-', array_column(array_column($frontBloc[$hotel]['hotels'], 'details'), 'id'));
}
return $hotel;
}
public function getAccessControl()
{
return $_SESSION['APP_ACCESS_CONTROL'];
}
public function contactPerso()
{
return $this->cms->ContactPerso();
}
public function method_exists($object, $method_name)
{
return method_exists($object, $method_name);
}
public function listeAffilies()
{
return $this->espaceAffilie->ListeAffilies();
}
public function getArrangements()
{
return $this->sejourHotel->Arrangements()['ListBoarding'];
}
public function configAmicale($amicale)
{
$configAmicale = [];
if (file_exists('cache-webservices/configAmicale.php'))
$configAmicale = include 'cache-webservices/configAmicale.php';
return isset($configAmicale[$amicale]) ? $configAmicale[$amicale] : [];
}
public function checkActionInIndexController($action)
{
return method_exists(IndexController::class, $action);
}
public function roomsToArray($rooms)
{
$occChambre = explode(';', $rooms);
$rooms = [];
foreach ($occChambre as $occChr) {
$occPax = explode(',', $occChr);
if ($occPax[0] == "")
$occPax[0] = "0";
$occPaxEnf = array_slice($occPax, 1);
$rooms[] = [
'Adult' => $occPax[0],
'children' => count($occPaxEnf),
'Child' => $occPaxEnf
];
}
return $rooms;
}
public function getReferencement()
{
return $this->cms->Referencement()['Referencement'];
}
public function getConfigurationPayement()
{
return $this->cms->ConfigurationPayement()['ConfigurationPayement'];
}
public function getFlashPromo()
{
return $this->sejourHotel->FlashPromo()['FlashPromo'];
}
public function getConfigAffichage()
{
if (!is_null($_configAffichage = $this->cms->ConfigFrontOffice()))
return $_configAffichage['ConfigFrontOffice'];
}
public function getCoursEchange()
{
$default_devise = [
"code" => "TND",
"montant" => 1,
"scale" => 3,
"symbole" => "DT",
"tndToDevise" => true,
"periodes" => []
];
$devises = array_column($this->cms->Devise()['Devises'], null, 'code');
$devise = $this->session->get('devise', $default_devise);
if (isset($devises[$devise['code']]))
$devise = $devises[$devise['code']];
$_devise = array_filter($devise['periodes'], function ($d) {
$today = new \DateTime();
return new \DateTime($d['dateDebut']) <= $today && new \DateTime($d['dateFin']) >= $today;
});
if (!empty($_devise)) {
$devise['montant'] = current($_devise)['montant'];
$devise['tndToDevise'] = current($_devise)['tndToDevise'];
}
return [
'operation' => $devise['tndToDevise'] ? '*' : '/',
'montant' => $devise['montant'] ? $devise['montant'] : 1,
'symbole' => $devise['symbole'],
'scale' => $devise['scale']
];
}
public function devise($montant, $showSymbole = false, $round = false)
{
if (!is_null($montant) && (is_float($montant) || is_numeric($montant))) {
$devise = self::getCoursEchange();
if ($round)
$devise['scale'] = 0;
$symbole = "";
if ($showSymbole)
$symbole = " {$devise['symbole']}";
eval("\$montant = $montant{$devise['operation']}{$devise['montant']};");
return number_format($montant, $devise['scale'], '.', '') . $symbole;
} else
return $montant;
}
function array_group_by($array, $key)
{
return $this->service->array_group_by($key, $array);
}
public function changeDeviseInString($str, $round = false)
{
$tabStr = explode(" ", $str);
$tabFinal = [];
foreach ($tabStr as $value) {
if (strtoupper($value) !== "DT" && strtoupper($value) !== "TND") {
if (filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)) {
array_push($tabFinal, $this->devise(filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION), true, $round));
} else {
array_push($tabFinal, $value);
}
}
}
$res = implode(" ", $tabFinal);
return $res;
}
public function hasModule($module)
{
return $this->service->hasModule($module);
}
public function getDestinations()
{
return $this->transfert->Destination()['Destinations'];
}
public function getHotelsEquivalents()
{
return $this->cms->HotelsEquivalent()['HotelsEquivalent'];
}
public function getHotelEtiquette()
{
return $this->cms->HotelEtiquette()['Etiquettes'];
}
public function getAllHotels($id = null, $withEtiquette = false, $appartement = false)
{
$hotels = $this->cms->Hotel($appartement)['Hotels'];
if ($withEtiquette) {
$etiquettes = $this->cms->HotelEtiquette()['Etiquettes'];
$hotels = array_map(function ($hotel) use ($etiquettes) {
$hotel['etiquettes'] = isset($etiquettes['etiquettes'][$hotel['id']]) ? $etiquettes['etiquettes'][$hotel['id']] : [];
$hotel['etiquettesSaison'] = isset($etiquettes['etiquettesSaison'][$hotel['id']]) ? $etiquettes['etiquettesSaison'][$hotel['id']] : [];
$hotel['etiquettesEmplacement'] = isset($etiquettes['etiquettesEmplacement'][$hotel['id']]) ? $etiquettes['etiquettesEmplacement'][$hotel['id']] : [];
return $hotel;
}, $hotels);
}
if (is_numeric($id))
return current(array_filter($hotels, function ($h) use ($id) {
return $h['id'] == $id;
}));
if (is_array($id))
return array_filter($hotels, function ($h) use ($id) {
return in_array($h['id'], $id);
});
else
return $hotels;
}
public function getTopDestinations()
{
return $this->cms->TopDestinations()['TopDestinations'];
}
public function getVillesHotels($produit = 'SHT', $onlySearchCity = false, $destination = '', $format = 'typeahead', $appartement = false)
{
$villes_hotels = [];
if ($produit == 'SHT') {
$villes_hotels = $this->cms->Ville()['Villes'];
if (!$onlySearchCity)
$villes_hotels = array_merge($villes_hotels, $this->cms->Hotel($appartement)['Hotels']);
}
$_destination = explode('-', $destination);
$array_filter = [];
if (count($_destination) == 2) {
$type = $_destination[0];
$id = $_destination[1];
if ($produit == 'SHE')
$villes_hotels = $this->sejourHotel->ListCityHotel([
'Keywords' => $id,
'onlySearchCity' => $onlySearchCity
])['ListCityHotel'];
$array_filter = array_filter($villes_hotels, function ($item) use ($type, $id) {
return $item['type'] == $type and $item['id'] == $id;
});
}
if (!empty($array_filter))
$selected_destination = current($array_filter);
else {
$search_recommended = explode('###', $this->cms->ConfigFrontOffice()['ConfigFrontOffice']['HOTEL']['SEARCH_RECOMMENDED']);
if (count($search_recommended) > 1 && $destination == "all")
$search_recommended = $search_recommended[1];
else
$search_recommended = $search_recommended[0];
$key = array_search($search_recommended, array_column($villes_hotels, 'name'));
$selected_destination = $key !== false ? $villes_hotels[$key] : null;
}
if ($format == 'jsuites') {
$villes_hotels = array_merge(
array_map("self::format_jsuites", $this->cms->GroupeVillesHotels()['GroupeVillesHotels']),
array_map("self::format_jsuites", $villes_hotels)
);
}
return [
'destinations' => $villes_hotels,
'selected_destination' => $selected_destination
];
}
function format_jsuites($item)
{
$_item = [
'pays' => $item['pays'],
'ville' => $item['ville'],
'group' => isset($item['group']) ? $item['group'] : ['v' => 'Ville', 'h' => 'Hôtel'][$item['type']],
'value' => "{$item['type']}-{$item['id']}",
'text' => "{$item['name']}, {$item['destination']}",
'image' => ['v' => "/assets-commun/images/icons-jsuites/map.svg", 'h' => "/assets-commun/images/icons-jsuites/chambre.svg"][$item['type']],
];
if (isset($item['hotel'])) {
$_item['hotel'] = $item['hotel'];
$_item['ville_id'] = $item['ville_id'];
$_item['ville_name'] = $item['ville_name'];
$_item['hotel_id'] = $item['id'];
$_item['hotel_name'] = $item['name'];
} else {
$_item['ville_id'] = $item['id'];
$_item['ville_name'] = $item['name'];
}
return $_item;
}
function GroupeVillesHotels($version = 1)
{
if ($version == 2) {
$groupes = [];
foreach ($this->cms->GroupeVillesHotels()['GroupeVillesHotels'] as $item) {
if (in_array($item ['group'], ['Top Ville', 'Top Hôtel'])) {
$groupes[] = [
'id' => $item['id'],
'id_group' => $item['id_group'],
'name' => $item ['name'],
'destination' => $item ['destination'],
'hotels' => $item ['hotels'],
'code' => $item ['group']
];
} else {
if (!isset($groupes[$item ['group']]))
$groupes[$item ['group']] = [
'id' => $item['id'],
'id_group' => $item['id_group'],
'name' => $item ['group'],
'destination' => $item ['destination'],
'hotels' => $item ['hotels'],
'code' => 'Top Destination'
];
else {
$groupes[$item ['group']]['id'] .= "-{$item['id']}";
$groupes[$item ['group']]['hotels'] = implode('-', array_merge(explode('-', $groupes[$item ['group']]['hotels']), explode('-', $item['hotels'])));
}
}
}
return array_values($groupes);
}
return $this->cms->GroupeVillesHotels()['GroupeVillesHotels'];
}
public function checkCustomTemplate($template)
{
return $this->service->checkCustomTemplate($template);
}
public function getAgence()
{
return $this->cms->Agence()['Agence'];
}
public function getAmicale()
{
return $this->cms->Amicale();
}
public function domaineBack($domaine_back = null)
{
return $this->service->domaineBack($domaine_back);
}
public function getPointVente($franchise = true, $id = null)
{
$pointvente = $this->cms->PointVente(['franchis' => $franchise])['PointsVente'];
if ($id)
return array_column($pointvente, null, 'id')[$id];
return $pointvente;
}
public function getPartenaire()
{
$partenaire = $this->cms->Partenaire()['Partenaires'];
return $partenaire;
}
public function getlienUtils()
{
$lienutils = $this->cms->LienElement()['LiensElement'];
return $lienutils;
}
public
function referencementByRoute($route, $path, $balise)
{
$referencements = $this->cms->ReferencementRoute();
if (!isset($referencements['ReferencementRoute']))
return "";
$referencements = array_filter($referencements['ReferencementRoute'], function ($referencement) use ($route, $path) {
return (is_null($referencement['path']) or
($referencement['avecParams'] and $path === $referencement['path']) or
//($referencement['avecParams'] and strpos($path, rtrim($referencement['path'], '/')) === 0) or
(!$referencement['avecParams'] and $referencement['route'] == $route));
});
$injection = "";
foreach ($referencements as $referencement)
if ($_injection = $referencement["injection"][$balise])
if ($balise == "h1")
$injection .= "<h1>$_injection</h1>";
elseif ($referencement["injection"]["mode_$balise"] == "css")
$injection .= "<style>$_injection</style>";
elseif ($referencement["injection"]["mode_$balise"] == "javascript")
$injection .= "<script>$_injection</script>";
else
$injection .= $_injection;
return $injection;
}
public function ArticlesElement($domaine_back = null)
{
$article = $this->cms->ArticlesElement($domaine_back)['ArticlesElement'];
return $article;
}
public function getReseauxSociaux()
{
$reseauxsociaux = $this->cms->ReseauxSociaux()['ReseauxSociaux'];
return $reseauxsociaux;
}
public function getDevise()
{
$devise = $this->cms->Devise()['Devises'];
return $devise;
}
public function getVille($id = null)
{
$villes = $this->cms->Ville()['Villes'];
if ($id) return array_column($villes, 'id')[$id];
return $villes;
}
public function getDeviseSelected()
{
return $this->session->get('devise');
}
public function getDeviseAgence()
{
return $this->session->get('devise-agence');
}
public function getLanguesTraduction()
{
$langues = array(
'af' =>
array(
'flag' => 'af',
'libelle' => 'Afrikanns',
),
'sq' =>
array(
'flag' => 'sq',
'libelle' => 'Albanais',
),
'ar' =>
array(
'flag' => 'tn',
'libelle' => 'Arabe',
),
'hy' =>
array(
'flag' => 'hy',
'libelle' => 'Arménien',
),
'eu' =>
array(
'flag' => 'eu',
'libelle' => 'Basque',
),
'bn' =>
array(
'flag' => 'bn',
'libelle' => 'Bengali',
),
'bg' =>
array(
'flag' => 'bg',
'libelle' => 'Bulgare',
),
'ca' =>
array(
'flag' => 'ca',
'libelle' => 'Catalan',
),
'km' =>
array(
'flag' => 'km',
'libelle' => 'Cambodgien',
),
'zh' =>
array(
'flag' => 'zh',
'libelle' => 'Mandarin Chinois)',
),
'hr' =>
array(
'flag' => 'hr',
'libelle' => 'Croation',
),
'cs' =>
array(
'flag' => 'cs',
'libelle' => 'Tchèque',
),
'da' =>
array(
'flag' => 'da',
'libelle' => 'Danois',
),
'nl' =>
array(
'flag' => 'nl',
'libelle' => 'Néerlandais',
),
'en' =>
array(
'flag' => 'us',
'libelle' => 'Anglais',
),
'et' =>
array(
'flag' => 'et',
'libelle' => 'Estonien',
),
'fj' =>
array(
'flag' => 'fj',
'libelle' => 'Fidji',
),
'fi' =>
array(
'flag' => 'fi',
'libelle' => 'Finlandais',
),
'fr' =>
array(
'flag' => 'fr',
'libelle' => 'Français',
),
'ka' =>
array(
'flag' => 'ka',
'libelle' => 'Géorgien',
),
'de' =>
array(
'flag' => 'de',
'libelle' => 'Allemand',
),
'el' =>
array(
'flag' => 'el',
'libelle' => 'Grec',
),
'gu' =>
array(
'flag' => 'gu',
'libelle' => 'Gujarati',
),
'he' =>
array(
'flag' => 'he',
'libelle' => 'Hébreu',
),
'hi' =>
array(
'flag' => 'hi',
'libelle' => 'Hindi',
),
'hu' =>
array(
'flag' => 'hu',
'libelle' => 'Hongrois',
),
'is' =>
array(
'flag' => 'is',
'libelle' => 'Islandais',
),
'id' =>
array(
'flag' => 'id',
'libelle' => 'Indonésien',
),
'ga' =>
array(
'flag' => 'ga',
'libelle' => 'Irlandais',
),
'it' =>
array(
'flag' => 'it',
'libelle' => 'Italien',
),
'ja' =>
array(
'flag' => 'ja',
'libelle' => 'Japonais',
),
'jw' =>
array(
'flag' => 'jw',
'libelle' => 'Javanais',
),
'ko' =>
array(
'flag' => 'ko',
'libelle' => 'Coréen',
),
'la' =>
array(
'flag' => 'la',
'libelle' => 'Latin',
),
'lv' =>
array(
'flag' => 'lv',
'libelle' => 'Letton',
),
'lt' =>
array(
'flag' => 'lt',
'libelle' => 'Lituanien',
),
'mk' =>
array(
'flag' => 'mk',
'libelle' => 'Macédonien',
),
'ms' =>
array(
'flag' => 'ms',
'libelle' => 'Malais',
),
'ml' =>
array(
'flag' => 'ml',
'libelle' => 'Malayalam',
),
'mt' =>
array(
'flag' => 'mt',
'libelle' => 'Maltais',
),
'mi' =>
array(
'flag' => 'mi',
'libelle' => 'Maori',
),
'mr' =>
array(
'flag' => 'mr',
'libelle' => 'Marathi',
),
'mn' =>
array(
'flag' => 'mn',
'libelle' => 'Mongol',
),
'ne' =>
array(
'flag' => 'ne',
'libelle' => 'Népalais',
),
'no' =>
array(
'flag' => 'no',
'libelle' => 'Norvégien',
),
'fa' =>
array(
'flag' => 'fa',
'libelle' => 'Persan',
),
'pl' =>
array(
'flag' => 'pl',
'libelle' => 'Polonais',
),
'pt' =>
array(
'flag' => 'pt',
'libelle' => 'Portugais',
),
'pa' =>
array(
'flag' => 'pa',
'libelle' => 'Punjabi',
),
'qu' =>
array(
'flag' => 'qu',
'libelle' => 'Quechua',
),
'ro' =>
array(
'flag' => 'ro',
'libelle' => 'Roumain',
),
'ru' =>
array(
'flag' => 'ru',
'libelle' => 'Russe',
),
'sm' =>
array(
'flag' => 'sm',
'libelle' => 'Samoan',
),
'sr' =>
array(
'flag' => 'sr',
'libelle' => 'Serbe',
),
'sk' =>
array(
'flag' => 'sk',
'libelle' => 'Slovaque',
),
'sl' =>
array(
'flag' => 'sl',
'libelle' => 'Slovène',
),
'es' =>
array(
'flag' => 'es',
'libelle' => 'Espanol',
),
'sw' =>
array(
'flag' => 'sw',
'libelle' => 'Swahili',
),
'sv' =>
array(
'flag' => 'sv',
'libelle' => 'Suédois',
),
'ta' =>
array(
'flag' => 'ta',
'libelle' => 'Tamil',
),
'tt' =>
array(
'flag' => 'tt',
'libelle' => 'Tatar',
),
'te' =>
array(
'flag' => 'te',
'libelle' => 'Telugu',
),
'th' =>
array(
'flag' => 'th',
'libelle' => 'Thaïlandais',
),
'bo' =>
array(
'flag' => 'bo',
'libelle' => 'Tibétain',
),
'to' =>
array(
'flag' => 'to',
'libelle' => 'Tonga',
),
'tr' =>
array(
'flag' => 'tr',
'libelle' => 'Turc',
),
'uk' =>
array(
'flag' => 'uk',
'libelle' => 'Ukrainien',
),
'ur' =>
array(
'flag' => 'ur',
'libelle' => 'Ourdou',
),
'uz' =>
array(
'flag' => 'uz',
'libelle' => 'Ouzbek',
),
'vi' =>
array(
'flag' => 'vi',
'libelle' => 'Vietnamien',
),
'cy' =>
array(
'flag' => 'cy',
'libelle' => 'Gallois',
),
'xh' =>
array(
'flag' => 'xh',
'libelle' => 'Xhosa',
)
);
if (file_exists("langues-traduction.php"))
$langues = include "langues-traduction.php";
return $langues;
}
function genererChaineAleatoire($longueur = 10)
{
$caracteres = 'abcdefghijklmnopqrstuvwxyz';
$chaineAleatoire = '';
for ($i = 0; $i < $longueur; $i++)
$chaineAleatoire .= $caracteres[rand(0, strlen($caracteres) - 1)];
return $chaineAleatoire;
}
public function routeReservation()
{
$routes = [];
if ($this->hasModule('sejour'))
$routes[] = [
'libelle' => 'Séjour',
'route_liste' => 'espace_affilie_reservations',
'route_details' => 'espace_affilie_reservation_detail'
];
if ($this->hasModule('voyages-organise')) {
$routes[] = [
'libelle' => 'Voyages',
'route_liste' => 'espace_affilie_reservations_voyageorganise',
'route_details' => 'espace_affilie_reservation_detail_voyageorganise'
];
$routes[] = [
'libelle' => 'Omra',
'route_liste' => 'espace_affilie_reservations_omraorganise',
'route_details' => 'espace_affilie_reservation_detail_omraorganise'
];
$routes[] = [
'libelle' => 'Circuits',
'route_liste' => 'espace_affilie_reservations_circuitorganise',
'route_details' => 'espace_affilie_reservation_detail_circuitorganise'
];
$routes[] = [
'libelle' => 'Croisières',
'route_liste' => 'espace_affilie_reservations_croisieres',
'route_details' => 'espace_affilie_reservation_detail_croisieres'
];
$routes[] = [
'libelle' => 'Transfert',
'route_liste' => 'espace_affilie_reservations_transfert',
'route_details' => 'espace_affilie_detail_reservation_transfert'
];
$routes[] = [
'libelle' => 'Liste',
'route_liste' => 'espace_affilie_reservations_liste',
];
}
if ($this->hasModule('voyages-package'))
$routes[] = [
'libelle' => 'Package',
'route_liste' => 'espace_affilie_reservations_package',
'route_details' => 'espace_affilie_reservation_detail_package'
];
return $routes;
}
public function usortPrices($sailings)
{
$sort_prices = $sailings['prices'];
usort($sort_prices, function ($a, $b) {
return $a['TicketTotal'] > $b['TicketTotal'];
});
return $sort_prices;
}
public function getPrix($sailings, $type = 'TicketTotal')
{
$prix = 0;
$array = array();
$sort_array = array();
foreach ($sailings as $k => $sailing) {
foreach ($sailing["prices"] as $price) {
$array[$k][$price["Index"]]['TicketTotal'] = $price["TicketTotal"];
$array[$k][$price["Index"]]['GrossTotal'] = $price["GrossTotal"];
}
}
foreach ($array as $value) {
usort($value, function ($a, $b) {
//return $a['TicketTotal'] > $b['TicketTotal'];
});
$sort_array[] = $value;
}
foreach ($sort_array as $value) {
$prix += $value[0][$type];
}
return $prix;
}
public function getRouteById($id, $provider = null)
{
$param = [
'id' => $id,
'provider' => $provider
];
$route = $this->maritime->getRoute($param);
return $route['Route'];
}
public function getRouteByCode($code, $provider = null)
{
$param = [
'code' => $code,
'provider' => $provider
];
$route = $this->maritime->getRoute($param);
return $route['Route'];
}
public function getPort($code, $provider = null)
{
$param = [
'code' => $code,
'provider' => $provider
];
$port = $this->maritime->getPort($param);
return $port['Port'];
}
public function getPrixCabine($sailings, $cabines)
{
$prix = 0;
$currency = null;
$array = array();
$arrayCabine = explode(',', $cabines);
foreach ($sailings as $k => $sailing) {
$prix += $sailing["prices"][$arrayCabine[$k]]["TicketTotal"];
}
foreach ($array as $value) {
$prix += min($value);
}
return $prix;
}
public function getListPays()
{
return $this->cms->Pays()['Pays'];
}
public function removeSizeStyles($html)
{
// Supprime tous les attributs class
$html = preg_replace('/\s*class\s*=\s*["\'][^"\']*["\']/i', '', $html);
// Supprime les propriétés de taille dans les attributs style
$html = preg_replace_callback(
'/style\s*=\s*["\'][^"\']*?(width|height|min-width|min-height|max-width|max-height)\s*:\s*[^;"\']+;?\s*[^"\']*?["\']/i',
function ($match) {
// Supprime les propriétés de taille tout en préservant les autres styles
$cleaned = preg_replace(
'/(width|height|min-width|min-height|max-width|max-height)\s*:\s*[^;"\']+;?\s*/i',
'',
$match[0]
);
// Supprime les attributs style vides
return preg_replace('/\s*style\s*=\s*["\']\s*["\']/i', '', $cleaned);
},
$html
);
// Convertit <, >, &, etc. en leurs caractères réels
return html_entity_decode($html, ENT_QUOTES | ENT_HTML5, 'UTF-8');
}
/**
* Regroupe les périodes par mois/année et ville de départ
* Ajoute le minPrix pour chaque pack
*
* @param array $periodes
* @return array Tableau des périodes regroupées
*/
public function groupPeriodes(array $periodes): array
{
$months = [
1 => 'Janvier', 2 => 'Février', 3 => 'Mars', 4 => 'Avril',
5 => 'Mai', 6 => 'Juin', 7 => 'Juillet', 8 => 'Août',
9 => 'Septembre', 10 => 'Octobre', 11 => 'Novembre', 12 => 'Décembre'
];
$grouped = [];
foreach ($periodes as $periode) {
// Créer la clé de regroupement
$dateDebut = new \DateTime($periode['du']);
$monthNumber = (int)$dateDebut->format('n');
$mois = $months[$monthNumber] ?? '';
$annee = $dateDebut->format('Y');
$ville = isset($periode['plans'][0]['ville']) ? $periode['plans'][0]['ville'] : 'Non défini';
$groupKey = $mois . ' ' . $annee . ' au départ de ' . $ville;
// Initialiser le groupe s'il n'existe pas
if (!isset($grouped[$groupKey])) {
$grouped[$groupKey] = [];
}
// Traiter les packs de la période pour ajouter minPrix
if (isset($periode['PACKS']) && is_array($periode['PACKS'])) {
foreach ($periode['PACKS'] as $index => $pack) {
$prices = [];
$tarifs = $pack['tarifs'] ?? [];
// Collecter les prix des chambres adultes
foreach (['single', 'double', 'triple', 'quadruple'] as $type) {
if (isset($tarifs[$type])) {
$prices[] = (float)$tarifs[$type]['vente'];
}
}
// Calculer le prix minimum
$periode['PACKS'][$index]['minPrix'] = !empty($prices) ? min($prices) : null;
}
}
// Ajouter la période au groupe
$grouped[$groupKey][] = $periode;
}
// Transformer en tableau avec structure claire
$result = [];
foreach ($grouped as $libelle => $periodes) {
$result[] = [
'libelle' => $libelle,
'periodes' => $periodes
];
}
return $result;
}
}