<?php
namespace App\Service;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface as Session;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
class WSCMS
{
public function __construct(Generale $generale, AuthorizationCheckerInterface $authorizationChecker, Session $session, RequestStack $requestStack)
{
$this->webService = [$generale, 'WebService'];
$this->authorizationChecker = $authorizationChecker;
$this->session = $session;
$this->requestStack = $requestStack;
}
public function Pays()
{
return call_user_func($this->webService, 'CMS', 'Pays', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public function GroupePays()
{
return call_user_func($this->webService, 'CMS', 'GroupePays', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public function Company()
{
return call_user_func($this->webService, 'CMS', 'Company', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public function FlightClass()
{
return call_user_func($this->webService, 'CMS', 'FlightClass', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public
function Ville()
{
if ($_SERVER['ENABLED_HOTEL_STAY_WORLDWIDE'] == 'true') return ['Villes' => []];
$villes = call_user_func($this->webService, 'CMS', 'Ville', [], $this->requestStack->getCurrentRequest()->getLocale());
if ($_SERVER['ACCEPT_SEARCH_ALL_CITIES'] == 'true')
$villes['Villes'] = array_merge([['id' => 'all', 'ville' => 'tous', 'name' => 'Tous les hôtels', 'destination' => 'Tunis', 'pays' => 'tn', 'type' => 'v', 'image' => '']], $villes['Villes']);
return $villes;
}
public function Hotel(bool $appartement = false, $checkFiltre = true)
{
// Sortie immédiate si le module hôtel monde est activé
if ($_SERVER['ENABLED_HOTEL_STAY_WORLDWIDE'] === 'true') {
return ['Hotels' => []];
}
// Détermination du mode B2B
$rolesB2B = ['ROLE_CLIENT_B2B', 'ROLE_CLIENT_B2B_OR_AMICALE'];
$isB2B = in_array($_SERVER['APP_ACCESS_CONTROL'] ?? '', $rolesB2B, true)
|| in_array($_SERVER['APP_SECOND_ACCESS_CONTROL'] ?? '', $rolesB2B, true);
// Récupération des hôtels
$hotels = call_user_func(
$this->webService,
'CMS',
'Hotel',
[],
$this->requestStack->getCurrentRequest()->getLocale()
);
// Filtrage des hôtels
$hotels['Hotels'] = array_values(array_filter($hotels['Hotels'] ?? [], function ($h) use ($appartement, $isB2B, $checkFiltre) {
// Filtre appartement
if (isset($h['appartement']) and $h['appartement'] != $appartement) {
return false;
}
// Filtre B2B / B2C
if ($checkFiltre) {
return $isB2B ? !empty($h['filtreB2B']) : !empty($h['filtreB2C']);
}
return true;
}));
return $hotels;
}
public
function Hotel0($appartement = false, $checkB2B = true)
{
if ($_SERVER['ENABLED_HOTEL_STAY_WORLDWIDE'] == 'true') return ['Hotels' => []];
$isB2B = (in_array($_SERVER['APP_ACCESS_CONTROL'], ['ROLE_CLIENT_B2B', 'ROLE_CLIENT_B2B_OR_AMICALE']) or
in_array($_SERVER['APP_SECOND_ACCESS_CONTROL'], ['ROLE_CLIENT_B2B', 'ROLE_CLIENT_B2B_OR_AMICALE']));
$hotels = call_user_func($this->webService, 'CMS', 'Hotel', [], $this->requestStack->getCurrentRequest()->getLocale());
$hotels['Hotels'] = array_values(array_filter($hotels['Hotels'], function ($h) use ($appartement,$checkB2B,$isB2B) {
return (!isset($h['appartement']) or $h['appartement'] == $appartement) and !$checkB2B or $h['filtreB2B'];
}));
return $hotels;
}
public
function HotelEtiquette()
{
return call_user_func($this->webService, 'CMS', 'HotelEtiquette', [], date('dmY'));
}
public
function ReferentielsDemandeDeGroupe()
{
return call_user_func($this->webService, 'CMS', 'ReferentielsDemandeDeGroupe', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public
function HotelsEquivalent()
{
return call_user_func($this->webService, 'CMS', 'HotelEquivalent', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public
function GroupeVillesHotels()
{
return call_user_func($this->webService, 'CMS', 'GroupeVillesHotels', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public
function BlocBootstrap()
{
return call_user_func($this->webService, 'CMS', 'BlocBootstrap', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public
function Article()
{
return call_user_func($this->webService, 'CMS', 'Article', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public
function BlocHtml()
{
return call_user_func($this->webService, 'CMS', 'BlocHtml', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public
function Partenaire()
{
return call_user_func($this->webService, 'CMS', 'Partenaire', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public
function LienElement()
{
return call_user_func($this->webService, 'CMS', 'LienElement', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public
function Slider()
{
$sliders = call_user_func($this->webService, 'CMS', 'Slider', [], $this->requestStack->getCurrentRequest()->getLocale());
foreach (['desktop', 'mobile'] as $device) {
$sliders['Sliders'][$device] = array_filter($sliders['Sliders'][$device], 'self::filtreSlider');
if (count($sliders['Sliders'][$device]) == 1)
$sliders['Sliders'][$device][] = current($sliders['Sliders'][$device]);
}
return $sliders;
}
function filtreSlider($item)
{
$todays = new \DateTime("now");
return $todays >= new \DateTime($item['dateDebutAffichage']) and $todays <= new \DateTime($item['dateFinAffichage']);
}
public
function Element()
{
return call_user_func($this->webService, 'CMS', 'Element', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public
function Agence()
{
$agence = call_user_func($this->webService, 'CMS', 'Agence', [], $this->requestStack->getCurrentRequest()->getLocale());
if ($amicale = $this->session->get('amicale'))
if (isset($amicale['configs']['SHOW_CONTACT_INFO_INSTEAD_OF_AGENCY']) and strtoupper($amicale['configs']['SHOW_CONTACT_INFO_INSTEAD_OF_AGENCY']) == 'TRUE')
$agence['Agence'] = array_replace($agence['Agence'], ['adresse' => $amicale['adresse'], 'tel1' => $amicale['tel'], 'tel2' => null, 'fax' => $amicale['fax'], 'contactEmail' => $amicale['email']]);
$this->session->set('agence', $agence);
return $agence;
}
public
function Amicale()
{
return call_user_func($this->webService, 'CMS', 'InfosAmicale', [], $this->requestStack->getCurrentRequest()->getHost());
}
public
function PointVente($params)
{
return call_user_func($this->webService, 'CMS', 'PointVente', $params, $this->requestStack->getCurrentRequest()->getLocale());
}
public
function NewsLetter($params)
{
return call_user_func($this->webService, 'CMS', 'NewsLetter', $params);
}
public
function ModePayement($params)
{
return call_user_func($this->webService, 'CMS', 'ModePayement', $params);
}
public
function ConfigurationPayement()
{
return call_user_func($this->webService, 'CMS', 'ConfigurationPayement', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public
function Referencement()
{
return ['Referencement' => []];
#return call_user_func($this->webService, 'CMS', 'Referencement', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public
function ReferencementRoute()
{
return call_user_func($this->webService, 'CMS', 'ReferencementRoute', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public
function ArticlesElement()
{
return call_user_func($this->webService, 'CMS', 'ArticlesElement', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public
function ConfigFrontOffice()
{
//https://domaine-back/admin/config/frontoffice/configuration-front-office/config?default-config
$defaultConfig = '{"SEO":{"ROBOTSTXT":"","SITEMAPXML":""},"VOYAGE":{"BLOCS_DETAILS":1,"BLOC_CARNET":1,"TEXT_SELECT_PERIODES":"libelle","MODELE_OMRA_PERSONNALISE":"modele-voyage-organise","ADD_SELECT_PACK":"non","TYPE_CHAMP_PERIODE":"select","JOINDER_PASSPORT":"non","TRI_RESULTAT":"prix-asc","BLOC_THEMES_VO":"afficher-theme","INTERVALLE_PAGINATION":"10-30-50-100default30","INPUT_MATRICULE_TARIFS_DISPO":"non","INPUT_REFERENCE_INTERNE_TARIFS_DISPO":"non","ADD_FORM_ROOM_PAX_DETAILS_OMRA":"non","OMRA_ALLOW_ROOM_ADDITION":"non"},"SPA":{"TRI_RESULTAT":"prix-asc","INTERVALLE_PAGINATION":"10-30-50-100default10"},"HOTEL":{"ALLOW_PRINT_PROFORMA_INVOICE":"non","ALLOW_DIRECT_RESERVATION_CANCELLATION":"non","DETAILS_BLOC_ALBUMS":1,"DETAILS_VERSION_FILTRE":1,"LOADING_LIST":"classique","BLOC_CHAMBRE_TARIFS":"pension-room","BLOC_CHAMBRE_TARIFS_MOBILE":"pension-room","TYPE_INPUT_CHAMBRE":"select","TYPE_INPUT_ARRANGEMENT":"select","MODELE_SELECT_VILLE_HOTEL":"typeahead","MODELE_SELECT_VILLE_HOTEL_MOBILE":"typeahead","SEARCH_RECOMMENDED":"Hammamet","INFO_SELECT_CHAMBRE":"sur-select-chambre","COND_ANNUL_TARIF_DISPO":"sous-occupations-chambres","COND_ANNUL_TARIF_DISPO_MOBILE":"sous-occupations-chambres","DEFAULT_OPEN_BLOC_CHAMBRE_TARIFS":"close","DESCRIPTION_BLOC_HOTEL":"icons","TRI_RESULTAT":"prix-asc","BLOC_FILTRE":1,"BLOC_AFFINER":["arrangements","etoiles","price","chambres","tags","zone","disponible","enfantGratuit","promo","rembourssable","recommander"],"INPUT_OCCUPATIONS":"popup","INTERVALLE_PAGINATION":"10-30-50-100default10","MAX_ADULTE":"10","MAX_ENFANT":"4","MIN_AGE_ENFANT":"2","MAX_AGE_ENFANT":"14","VIEW_PAY_AT_HOTEL":"non","EDIT_PAY_AT_HOTEL":"non","DETAILS_BEFORE_TARIFS_DISPO":"non","INPUT_MATRICULE_TARIFS_DISPO":"non","CACHER_FORM_CLIENT_B2B_TARIFS_DISPO":"oui","INPUT_REFERENCE_INTERNE_TARIFS_DISPO":"non","DISPLAY_ONLY_CANCELLATION_DEADLINE_OR_NON_REFUNDABLE":"non","VIEW_CALENDRA":"non","DISPLAY_PRICE_HALF_DOUBLE":"non","CHECK_IMG_RECOMMANDED":false},"VOL":{"MODELE_ELEMENT_BILLET":"modele1","SEARCH_DEPARTURE_RECOMMENDED":"A\u00e9roport Houari Boumediene","SEARCH_ARRIVAL_RECOMMENDED":"A\u00e9roport d\u0027Istanbul","INTERVALLE_PAGINATION":"10-25-50-100default10","LOADING_LIST":"classique","TRI_RESULTAT":"prix-asc","BLOC_AFFINER":["escales","avion","price","classe","compagnieAerienne","aeorportDepart","aeorportArrivee","heureDepart","heureArrivee","bagage"],"JOINDER_PASSPORT":"non","HIDE_INFOS_CLIENT":"non","HIDE_INFOS_PASSAGERS":"non","HIDE_TARIF_DISPO":"non","PAYS_DEFAULT_TARIF_DISPO":"","PASSENGER_DEFAULT_BIRTHDAY_TARIF_DISPO":"","CLIENT_DEFAULT_VILLE_TARIF_DISPO":"","CLIENT_DEFAULT_ADRESSE_TARIF_DISPO":"","CLIENT_DEFAULT_TYPE_TEL_TARIF_DISPO":"M"},"GENERALE":{"RECAPTCHA_FORM":"non","NUMEROTATION_TITLE_FORM":"non","STYLESHEETS":"","COUPON_REDUCTION":"non","CONFIG_MAQUETTE":0}}';
$configs = call_user_func($this->webService, 'CMS', 'ConfigFrontOffice', [], $this->requestStack->getCurrentRequest()->getLocale());
if (isset($configs['ConfigFrontOffice']['SEO']['ROBOTSTXT']) and $configs['ConfigFrontOffice']['SEO']['ROBOTSTXT'] != '')
file_put_contents('robots.txt', $configs['ConfigFrontOffice']['SEO']['ROBOTSTXT']);
if (isset($configs['ConfigFrontOffice']['SEO']['SITEMAPXML']) and $configs['ConfigFrontOffice']['SEO']['SITEMAPXML'] != '')
file_put_contents('sitemap.xml', $configs['ConfigFrontOffice']['SEO']['SITEMAPXML']);
/*if (!is_array($configs))
$configs['ConfigFrontOffice'] = json_decode($defaultConfig, true);
else*/
foreach (json_decode($defaultConfig, true) as $key => $config)
foreach ($config as $_key => $item)
if (!isset($configs['ConfigFrontOffice'][$key][$_key]))
$configs['ConfigFrontOffice'][$key][$_key] = $item;
return $configs;
}
public
function ReseauxSociaux()
{
return call_user_func($this->webService, 'CMS', 'ReseauxSociaux', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public
function Devise()
{
return call_user_func($this->webService, 'CMS', 'Devise', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public
function SendMailLibre($params)
{
return call_user_func($this->webService, 'CMS', 'SendMailLibre', $params);
}
public
function SendEmailConfirmationInscrire($params)
{
return call_user_func($this->webService, 'CMS', 'SendEmailConfirmationInscrire', $params);
}
public
function CouponReduction($params)
{
return call_user_func($this->webService, 'CMS', 'CouponReduction', $params);
}
public
function ConditionVente()
{
return call_user_func($this->webService, 'CMS', 'ConditionVente', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public
function Gallery()
{
return call_user_func($this->webService, 'CMS', 'Gallery', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public function TopDestinations()
{
return call_user_func($this->webService, 'CMS', 'TopDestinations', [], $this->requestStack->getCurrentRequest()->getLocale());
}
public
function ContactPerso()
{
return call_user_func($this->webService, 'OldSHT', 'getcontactPerso', [], $this->requestStack->getCurrentRequest()->getLocale());
}
}