src/Controller/TourController.php line 269

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Api\Helper\SeoHelper;
  4. use App\Api\Helper\ThemeHelper;
  5. use App\Api\Helper\ContactHelper;
  6. use App\Helper\NavigationHelper;
  7. use App\Api\Helper\DemandHelper;
  8. use App\Api\Helper\VoyageHelper;
  9. use App\Api\Helper\ContentHelper;
  10. use App\Api\Helper\PaysHelper;
  11. use App\Api\Helper\TemoignageHelper;
  12. use App\Api\ApiClient;
  13. use App\Api\DolApiClient;
  14. use App\Api\Helper\VoyageTypeHelper;
  15. use App\Form\TourFormType;
  16. use App\Form\CustomTourFormType;
  17. use App\Form\InfoTourType;
  18. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  19. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  20. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. use Symfony\Contracts\Translation\TranslatorInterface;
  23. use Symfony\Component\HttpFoundation\Request;
  24. use Symfony\Component\HttpFoundation\Session\Session;
  25. class TourController extends AbstractController {
  26.     private $voyageHelper;
  27.     private $contentHelper;
  28.     private $demandHelper;
  29.     public function __construct(VoyageHelper $voyageHelper,
  30.      ContentHelper $contentHelper,
  31.      DemandHelper $demandHelper)
  32.     {
  33.         $this->voyageHelper  $voyageHelper;
  34.         $this->contentHelper $contentHelper;
  35.         $this->demandHelper  $demandHelper;
  36.     }
  37.     /**
  38.      * @Route("tourcat/voyages-sur-mesure", name="tour_planner")
  39.      */
  40.     public function planner(Request $request,
  41.      ApiClient $apiClient,
  42.      DolApiClient $dolApiClient,
  43.      \Swift_Mailer $mailer,
  44.      TranslatorInterface $translator,
  45.      contactHelper $contactHelper) {
  46.         $debug $this->getParameter('kernel.debug');
  47.         $locale $request->getLocale();
  48.         $seo['meta_title'] = 'Voyage sur mesure';
  49.         $form $this->createForm(TourFormType::class);
  50.         $form->handleRequest($request);
  51.         if ($form->isSubmitted() && $form->isValid()) {
  52.             $data $form->getData();
  53.             $contact = [];
  54.             $contact["name"] = $data['name'];
  55.             $contact["address"] = $data['address'];
  56.             $contact["zip"] = $data['zip'];
  57.             $contact["town"] = $data['city'];
  58.             $contact["pays"] = $data['country'];
  59.             $contact["phone"] = $data['phone'];
  60.             $contact["email"] = $data['email'];
  61.             $contact["client"] = 2;
  62.             $contact["code_client"] = -1;
  63.             $contact["array_options"] = ["source" => 1];
  64.             try {
  65.                 $contactExists $contactHelper->getByEmail($contact["email"]);
  66.             } catch (ClientException $e) {
  67.                 if ($debug) {
  68.                     $viewPath "api/error/notfound.html.twig";
  69.                     return $this->render($viewPath, array("message" => sprintf("Erreur API : %s"$this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  70.                 }
  71.             }
  72.             if (is_null($contactExists)) {
  73.                 try {
  74.                     $response $contactHelper->create($contact);
  75.                 } catch (ClientException $e) {
  76.                     if ($debug) {
  77.                         $viewPath "api/error/notfound.html.twig";
  78.                         return $this->render($viewPath, array("message" => sprintf("Erreur API : %s"$this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  79.                     }
  80.                 }
  81.                 $customerId $response;
  82.             } else {
  83.                 try {
  84.                     $response $contactHelper->update($contactExists['rowid'], $contact);
  85.                 } catch (ClientException $e) {
  86.                     if ($debug) {
  87.                         $viewPath "api/error/notfound.html.twig";
  88.                         return $this->render($viewPath, array("message" => sprintf("Erreur API : %s"$this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  89.                     }
  90.                 }
  91.                 $customerId $response['id'];
  92.             }
  93.             
  94.             $demand = [];
  95.             $demand["customer"] = $customerId;
  96.             $demand['destination'] = $request->request->get('destination'null);
  97.             $demand['destination2'] = $request->request->get('destination2'null);
  98.             $demand["date"] = $data['date'];
  99.             $demand["duration"] = $data['duration'];
  100.             $demand["budget"] = $data['budget'];
  101.             $demand["type"] = $data['type'];
  102.             $demand["language"] = $data['language'];
  103.             $demand["wishes"] = $data['wishes'];
  104.             $demand["group"] = $data['group'];
  105.             $demand["persons"] = $data['budget'];
  106.             $demand["adults"] = $data['adults'];
  107.             $demand["children"] = $data['children'];
  108.             $demand["divers"] = $data['divers'];
  109.             $demand["no_divers"] = $data['no_divers'];
  110.             $demand["message"] = $data['message'];
  111.             try {
  112.                 $demandHelper $this->demandHelper;
  113.                 $demandResponse $demandHelper->create($demand);
  114.             } catch (ClientException $e) {
  115.                 if ($debug) {
  116.                     $viewPath "api/error/notfound.html.twig";
  117.                     return $this->render($viewPath, array("message" => sprintf("Erreur API : %s"$this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  118.                 }
  119.             }
  120.             $message = (new \Swift_Message($translator->trans('Nous vous remercions pour votre demande')))
  121.                     ->setFrom('voyage@odasie.fr')
  122.                     ->setTo($data['email'])
  123.                     ->setBody(
  124.                     $this->renderView(
  125.                             'emails/registration.html.twig', [
  126.                         'name' => $data['name'],
  127.                         'subject' => 'Voyage sur mesure',
  128.                         'message' => $data['message'],
  129.                             ]
  130.                     ), 'text/html'
  131.                     )
  132.             ;
  133.             $mailer->send($message);
  134.             //dd('test');
  135.             $this->addFlash(
  136.                     'success'$translator->trans('Votre demande a bien été transmise')
  137.             );
  138.             
  139.             return $this->redirectToRoute('tour_planner');
  140.         }
  141.         return $this->render('tour/planner.html.twig', [
  142.                     'seo' => $seo,
  143.                     'form' => $form->createView()
  144.         ]);
  145.     }
  146.     
  147.     public function showByType($slugRequest $requestApiClient $apiClient,
  148.      TranslatorInterface $translator,
  149.       VoyageTypeHelper $voyageTypeHelper,
  150.       NavigationHelper $navigationHelper,
  151.       SeoHelper $seoHelper,
  152.       TemoignageHelper $temoignageHelper,
  153.       ThemeHelper $themeHelper,
  154.       PaysHelper $paysHelper)
  155.     {
  156.         $page $request->query->get('page'1);
  157.         $locale $request->getLocale();
  158.         $debug $this->getParameter('kernel.debug');
  159.         //$entity = 'content';
  160.         $entity 'thematic';
  161.       
  162.         /*  
  163.             Récuperation du slug FR pour nourrir SeoHelper 
  164.             Le slug sert aussi d'url aux différentes pages de catégories de tour
  165.             ainsi, le slug est traduit en anglais.
  166.             il faut retrouver le slug d'origine (en FR) et nourrir
  167.             $seoHelper avec celui-ci.
  168.         */
  169.         $voyageTypes $voyageTypeHelper->getAllTranslated($locale);
  170.         
  171.         foreach($voyageTypes as $voyageType){
  172.             if($slug == $voyageType['slug']){
  173.                 $slug $voyageType['original_slug'];
  174.             }
  175.         }
  176.      
  177.         /* Fin récuperation du slug FR pour nourrir SeoHelper */
  178.         try {
  179.             $seo $seoHelper->getSeoBySlug($entity$slug,$request->getLocale());
  180.         } catch (ClientException $e) {
  181.             if ($debug) {
  182.                 $viewPath "api/error/notfound.html.twig";
  183.                 return $this->render($viewPath, array("message" => sprintf("Erreur API : %s"$this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  184.             }
  185.         }
  186.       
  187.         
  188.         $theme $themeHelper->getOneBySlug($slug);
  189.         /* Pays */
  190.         //$paysHelper = $this->container->get('app.api.helper.paysHelper');
  191.         $countries =  $paysHelper->getAllTranslated($locale);
  192.         //formulaire
  193.         $duration_range $request->get("duration_range") ?? null;
  194.         $arrival $request->get("arrival") ?? null;
  195.         $category $request->get("category") ?? null;
  196.         $arrTemoignages = [];
  197.         $arrTemoignages $temoignageHelper->getByTourType($slug);
  198.         try {
  199.             $navigation $navigationHelper->getNavigation();
  200.         }
  201.         catch(\Exception $e) {
  202.         }  
  203.         /**
  204.          * sélection et formatage des tour_types
  205.          * pour affichage dans twig
  206.          */
  207.         $typeLibelle '';
  208.         foreach($navigation['themes']['children'] as $tourTypeKey => $tourType) {
  209.             $slugBis str_replace('-''_'$slug);
  210.             if(str_contains($slugBis$tourTypeKey)) {
  211.                 $typeLibelle str_replace('Voyage '''$tourType['label']);
  212.                 if($typeLibelle === 'entre amis') {
  213.                     $typeLibelle 'entre potes';
  214.                 }
  215.             }
  216.             if($slug === 'solitaire') {
  217.                 $typeLibelle 'en solo';
  218.             }
  219.         }
  220.         return $this->render('tour/index_by_category.html.twig', [
  221.             'seo' => $seo,
  222.             'slug' => $slug,
  223.             //'content' => $content,
  224.             'page' => $page,
  225.             'countries' => $countries,
  226.             'temoignages' => $arrTemoignages,
  227.             //Champs du formulaire
  228.             'duration_range' => $duration_range,
  229.             'arrival' => $arrival,
  230.             'category' => $category,
  231.             'navigation' => $navigation,
  232.             'typeLibelle' => $typeLibelle
  233.         ]);
  234.     }
  235.     /**
  236.      * @Route("tourcat/{slug}", name="tour_index_by_theme")
  237.      */
  238.     public function indexByTheme($slug,
  239.      Request $request,
  240.      ApiClient $apiClient,
  241.      TranslatorInterface $translator,
  242.      SeoHelper $seoHelper) {
  243.         $page $request->query->get('page'1);
  244.         $debug $this->getParameter('kernel.debug');
  245.         $entity 'thematic';
  246.         try {
  247.             $seo $seoHelper->getSeoBySlug($entity$slug);
  248.         } catch (ClientException $e) {
  249.             if ($debug) {
  250.                 $viewPath "api/error/notfound.html.twig";
  251.                 return $this->render($viewPath, array("message" => sprintf("Erreur API : %s"$this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  252.             }
  253.         }
  254.         return $this->render('tour/index_by_category.html.twig', [
  255.                     'seo' => $seo,
  256.                     'slug' => $slug,
  257.                     'page' => $page
  258.         ]);
  259.     }
  260. /**
  261.      *  
  262.      * @Route({
  263.      *     "fr": "/{_locale}/voyages",
  264.      *     "en": "/{_locale}/trips"
  265.      * }, name="tour_index")
  266.      * 
  267.      */
  268.     public function index(Request $requestApiClient $apiClient,
  269.      TranslatorInterface $translator,
  270.      PaysHelper $paysHelper) {
  271.         
  272.         $page $request->query->get('page'1);
  273.         $debug $this->getParameter('kernel.debug');
  274.         $locale $request->getLocale();
  275.         $params['pays'] = $request->query->get('country'"");
  276.         if($params['pays'] == ""){
  277.             $params['pays'] = $request->query->get('pays'"");
  278.         }
  279.         
  280.         $params['arrivee'] = $request->query->get('arrival'"");
  281.         $params['duree'] = $request->query->get('duration_range'"");
  282.         $params['categorie'] = $request->query->get('category'"");
  283.    
  284.         if ($params['pays'] != "") {
  285.             return $this->redirect('/'.$locale.'/' $params['pays'] . "?arrival=" .  $params['arrivee'] . "&duration_range=" $params['duree'] . "&duree=" $params['duree'] . "&categorie=" $params['categorie']);
  286.         }
  287.         if ($params['pays'] == "") {
  288.             return $this->redirect('/'.$locale.'/' $params['categorie'] . "?arrival=" .  $params['arrivee'] . "&duration_range=" $params['duree'] . "&duree=" $params['duree']);
  289.         }
  290.         if ($params['arrivee']  ) {
  291.             $request->getSession()->set('date'$params['arrivee']);
  292.         }
  293.         try {
  294.             //$paysHelper = $this->container->get('app.api.helper.paysHelper');
  295.             $pays $paysHelper->getOneBySlug($params['pays']);
  296.         } catch (ClientException $e) {
  297.             if ($debug) {
  298.                 $viewPath "api/error/notfound.html.twig";
  299.                 return $this->render($viewPath, array("message" => sprintf("Erreur API : %s"$this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  300.             }
  301.         }
  302.    
  303.         return $this->render('tour/index.html.twig', [
  304.                     // 'seo' => $seo,
  305.                     'page' => $page,
  306.                     'pays' => $pays,
  307.                     'params' => $params,
  308.         ]);
  309.     }
  310.     
  311.     /**
  312.      * @Route("/{_locale}/promotions", name="tour_promos")
  313.      */
  314.     public function promos(Request $request,
  315.      ApiClient $apiClient,
  316.      TranslatorInterface $translator,
  317.      SeoHelper $seoHelper) {
  318.         
  319.         $debug      $this->getParameter('kernel.debug');
  320.         $locale     $request->getLocale();
  321.         $entity     'content';
  322.         
  323.         try {
  324.             $seo $seoHelper->getSeoBySlug($entity"promotions",$request->getLocale());
  325.         } catch (ClientException $e) {
  326.             if ($debug) {
  327.                 $viewPath "api/error/notfound.html.twig";
  328.                 return $this->render($viewPath, array("message" => sprintf("Erreur API : %s"$this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  329.             }
  330.         }
  331.         try {
  332.             $voyageHelper $this->voyageHelper;
  333.             $voyages $voyageHelper->getAll(nullnullnullnullnull'promotion');
  334.         } catch (ClientException $e) {
  335.             if ($debug) {
  336.                 $viewPath "api/error/notfound.html.twig";
  337.                 return $this->render($viewPath, array("message" => sprintf("Erreur API : %s"$this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  338.             }
  339.         }
  340.        
  341.         $contentHelper $this->contentHelper;
  342.         $content $contentHelper->getOneBySlug("promotions");
  343.         return $this->render('tour/promotions.html.twig', [
  344.             'seo' => $seo,
  345.             'content' => $content,
  346.             'voyages' => $voyages
  347.         ]);
  348.         
  349.     }
  350.     /*
  351.     public function show($pays, $slug, Request $request,ApiClient $apiClient, TranslatorInterface $translator) {
  352.         $debug      = $this->getParameter('kernel.debug');
  353.         $entity     = 'tour';
  354.         $locale     = $request->getLocale();
  355.         $basePath   = $this->getParameter('api.base_uri').'/uploads/';
  356.         
  357.         try {
  358.             $seoHelper = new SeoHelper($apiClient);
  359.             $seo = $seoHelper->getSeoBySlug($entity, $slug);
  360.         } catch (ClientException $e) {
  361.             if ($debug) {
  362.                 $viewPath = "api/error/notfound.html.twig";
  363.                 return $this->render($viewPath, array("message" => sprintf("Erreur API : %s", $this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  364.             }
  365.         }
  366.         $voyageHelper = new VoyageHelper($apiClient,$locale);
  367.         $voyages = $voyageHelper->getAll();
  368.         $contentHelper = new ContentHelper($apiClient, $locale);
  369.         //$voyages =  $contentHelper->getTraductionCustomTour($voyages,$locale);
  370.         //Si la langue n'est pas FR, le slug est très probablement une version traduite
  371.         //il faut retrouver sa version originale.
  372.         $realSlug = $slug;
  373.       
  374.         $trip = $voyageHelper->getOneBySlug($realSlug);
  375.        
  376.         //Traductions du customtour 
  377.         if($locale != "fr"){
  378.           
  379.             $traductionContent =  $contentHelper->getTraductionCustomTour([$trip['tour']],$locale);
  380.             $trip['tour'] = $traductionContent[0] ?? $trip['tour'];
  381.        
  382.      
  383.        
  384.             //traduction des commodités
  385.             foreach($trip['commodities'] as &$commodite){
  386.                 $tradCommodity = $contentHelper->getTraductionContenu($commodite['commodity_id'],"ext_commodite",$locale);
  387.                 $commodite['commodity_libelle'] = $tradCommodity['libelle'];
  388.             }
  389.             //traduction des jours
  390.             foreach($trip['days'] as &$day){
  391.                 $trad = $contentHelper->getTraductionContenu($day['day_id'],"ext_customtour_day",$locale);
  392.                 $day['day_description'] = $trad['description'];
  393.                 //traduction des supports
  394.                 foreach($day['supports'] as &$support){
  395.                     $trad = $contentHelper->getTraductionContenu($support['id'],"ext_customtour_day_support",$locale);
  396.                     $support['libelle'] = $trad['libelle'];
  397.                 }
  398.             }
  399.      
  400.         }
  401.        
  402.         if(!$trip){
  403.              $this->addFlash(
  404.                     'danger', $translator->trans('ce voyage n\'existe pas')
  405.             );
  406.             return $this->redirectToRoute('tour_index');
  407.         }
  408.         
  409.         //on organise les hotels et croisieres par destination car en twig c'est chiant
  410.         $arrHotels = array();
  411.         
  412.         $arrayHEtC = array_merge($trip['hotels'],$trip['cruises']);
  413.         
  414.         foreach($arrayHEtC as $keyH => $hotelOuCroisiere){
  415.             if(!array_key_exists($hotelOuCroisiere['destination_libelle'], $arrHotels)){
  416.                 $arrHotels[$hotelOuCroisiere['destination_libelle']] = array();
  417.             }
  418.             array_push($arrHotels[$hotelOuCroisiere['destination_libelle']],$hotelOuCroisiere);
  419.         }
  420.         // Recherche de voyages sur la même destination
  421.         $voyagesDestination = [];
  422.         $voyagesAutresDestinations = [];
  423.         $voyageHelper = $this->voyageHelper;
  424.         $voyagesDestination = $voyageHelper->getAll($trip['tour']['pays_slug'], null, 1, null, null, null, 'ct.ordre', 'ASC', 12, null);
  425.     
  426.         if (empty($voyagesDestination)) {
  427.             $voyagesAutresDestinations = $voyageHelper->getAll(null, null, 1, null, null, null, 'ct.ordre', 'ASC', 12, null);
  428.         }
  429.         
  430.         //dd($arrHotels);
  431.         return $this->render('tour/show2.html.twig', [
  432.             'seo'       => $seo,
  433.             'trip'      => $trip,
  434.             'slug'      => $realSlug,
  435.             'locale'    => $locale,
  436.             'basePath'  => $basePath,
  437.             'arrHotels' => $arrHotels,
  438.             'voyagesDestination' => $voyagesDestination,
  439.             'voyagesAutresDestinations' => $voyagesAutresDestinations
  440.         ]);
  441.     }
  442.     */
  443.    
  444.    
  445. //    /**
  446. //     * @Route("voyage/{slug}/devis", name="tour_quotation")
  447. //     */
  448. //    public function quotation($slug, Request $request, ApiClient $apiClient, DolApiClient $dolApiClient, \Swift_Mailer $mailer, TranslatorInterface $translator) {
  449. //        $debug = $this->getParameter('kernel.debug');
  450. //        $locale = $request->getLocale();
  451. //        $entity = 'tour';
  452. //
  453. //        try {
  454. //            $seoHelper = new SeoHelper($apiClient);
  455. //            $seo = $seoHelper->getSeoBySlug($entity, $slug);
  456. //        } catch (ClientException $e) {
  457. //            if ($debug) {
  458. //                $viewPath = "api/error/notfound.html.twig";
  459. //                return $this->render($viewPath, array("message" => sprintf("Erreur API : %s", $this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  460. //            }
  461. //        }
  462. //
  463. //        $form = $this->createForm(CustomTourFormType::class);
  464. //        $form->handleRequest($request);
  465. //
  466. //        if ($form->isSubmitted() && $form->isValid()) {
  467. //
  468. //            $data = $form->getData();
  469. //
  470. //            $contact = [];
  471. //            $contact["name"] = $data['lastname'] . ' ' . $data['firstname'];
  472. //            $contact["address"] = $data['address'];
  473. //            $contact["zip"] = $data['zip'];
  474. //            $contact["town"] = $data['city'];
  475. //            $contact["pays"] = $data['country'];
  476. //            $contact["phone"] = $data['phone'];
  477. //            $contact["email"] = $data['email'];
  478. //            $contact["client"] = 2;
  479. //            $contact["code_client"] = -1;
  480. //            $contact["array_options"] = ["source" => 1];
  481. //
  482. //            try {
  483. //                $contactHelper = new contactHelper($apiClient, $locale);
  484. //                $contactExists = $contactHelper->getByEmail($contact["email"]);
  485. //            } catch (ClientException $e) {
  486. //                if ($debug) {
  487. //                    $viewPath = "api/error/notfound.html.twig";
  488. //                    return $this->render($viewPath, array("message" => sprintf("Erreur API : %s", $this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  489. //                }
  490. //            }
  491. //
  492. //            $contactHelper = new contactHelper($dolApiClient, $locale);
  493. //
  494. //            if (is_null($contactExists)) {
  495. //
  496. //                try {
  497. //                    $response = $contactHelper->create($contact);
  498. //                } catch (ClientException $e) {
  499. //                    if ($debug) {
  500. //                        $viewPath = "api/error/notfound.html.twig";
  501. //                        return $this->render($viewPath, array("message" => sprintf("Erreur API : %s", $this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  502. //                    }
  503. //                }
  504. //
  505. //                $customerId = $response;
  506. //            } else {
  507. //
  508. //                try {
  509. //                    $response = $contactHelper->update($contactExists['rowid'], $contact);
  510. //                } catch (ClientException $e) {
  511. //                    if ($debug) {
  512. //                        $viewPath = "api/error/notfound.html.twig";
  513. //                        return $this->render($viewPath, array("message" => sprintf("Erreur API : %s", $this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  514. //                    }
  515. //                }
  516. //
  517. //                $customerId = $response['id'];
  518. //            }
  519. //
  520. //            $demand = [];
  521. //            $demand["customer"] = $customerId;
  522. //            $demand['tour'] = $slug;
  523. //            $demand["message"] = $data['message'];
  524. //            $demand["availabilities"] = $data['availability'];
  525. //
  526. //            try {
  527. //                $demandHelper = new DemandHelper($apiClient, $locale);
  528. //                $demandResponse = $demandHelper->create($demand);
  529. //            } catch (ClientException $e) {
  530. //                if ($debug) {
  531. //                    $viewPath = "api/error/notfound.html.twig";
  532. //                    return $this->render($viewPath, array("message" => sprintf("Erreur API : %s", $this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  533. //                }
  534. //            }
  535. //
  536. //            $message = (new \Swift_Message($translator->trans('Nous vous remercions pour votre demande')))
  537. //                    ->setFrom('voyage@odasie.fr')
  538. //                    ->setTo($data['email'])
  539. //                    ->setBody(
  540. //                    $this->renderView(
  541. //                            'emails/registration.html.twig', [
  542. //                        'name' => $contact['name'],
  543. //                        'subject' => 'Votre demande de devis',
  544. //                        'message' => $demand["message"],
  545. //                            ]
  546. //                    ), 'text/html'
  547. //                    )
  548. //            ;
  549. //
  550. //            $mailer->send($message);
  551. //
  552. //            $this->addFlash(
  553. //                    'success', $translator->trans('Votre demande a bien été transmise')
  554. //            );
  555. //
  556. //            return $this->redirectToRoute('tour_show', ['slug' => $slug,]);
  557. //        }
  558. //
  559. //        return $this->render('tour/quotation.html.twig', [
  560. //                    'seo' => $seo,
  561. //                    'slug' => $slug,
  562. //                    'form' => $form->createView()
  563. //        ]);
  564. //    }
  565.     /**
  566.      * @Route({
  567.      *     "fr": "{_locale}/votre-voyage/{key}",
  568.      *     "en": "{_locale}/your-trip/{key}"
  569.      * }, name="tour_custom_itinary")
  570.      */
  571.     public function customItinary($keyRequest $requestApiClient $apiClientTranslatorInterface $translator) {
  572.         $debug      $this->getParameter('kernel.debug');
  573.         $locale     $request->getLocale();
  574.         $basePath   $this->getParameter('api.base_uri').'/uploads/';
  575.         if (!$key) {
  576.             throw new BadRequestHttpException($translator->trans("La clé doit être indiquée"));
  577.         }
  578.         try {
  579.             $voyageHelper $this->voyageHelper;
  580.             $voyage $voyageHelper->getOneByKey($key);
  581.         } catch (ClientException $e) {
  582.             if ($debug) {
  583.                 $viewPath "api/error/notfound.html.twig";
  584.                 return $this->render($viewPath, array("message" => sprintf("Erreur API : %s"$this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  585.             }
  586.         }
  587.         if (empty($voyage)) {
  588.             return $this->redirectToRoute('tour_index');
  589.         }
  590.         
  591.         //on organise les hotels et croisieres par destination car en twig c'est chiant
  592.         $arrHotels = array();
  593.         
  594.         $arrayHEtC array_merge($voyage['hotels'],$voyage['cruises']);
  595.         foreach($arrayHEtC as $keyH => $hotelOuCroisiere){
  596.             if(!array_key_exists($hotelOuCroisiere['destination_libelle'], $arrHotels)){
  597.                 $arrHotels[$hotelOuCroisiere['destination_libelle']] = array();
  598.             }
  599.             array_push($arrHotels[$hotelOuCroisiere['destination_libelle']],$hotelOuCroisiere);
  600.         }
  601.         $params = [];
  602.         $params['arrivee'] = $request->query->get('arrival'"");
  603.         $params['duree'] = $request->query->get('duration_range'"");
  604.         $params['categorie'] = $request->query->get('category'"");
  605.         $params['defaultTour'] = "custom";
  606.         $sum 0;
  607.         $totalBarre 0;
  608.         if (isset($voyage['tour']['voyage_price_per_person_to_apply']) && 
  609.             json_decode($voyage['tour']['voyage_price_per_person_to_apply'], true) == true) {
  610.             foreach (json_decode($voyage['tour']['voyage_price_per_person_to_apply'], true) as $pricePerPerson) {
  611.                 $sum += $pricePerPerson;
  612.             }
  613.             // caclul du prix total barré à aficher
  614.             $applyDiscountPrice json_decode($voyage['tour']['voyage_apply_discount_price_per_person'], true);
  615.             $initialPricePerPerson json_decode($voyage['tour']['voyage_initial_price_per_person'], true);
  616.             foreach ($applyDiscountPrice as $keyDiscount => $pax) {
  617.                 if($pax === true) {
  618.                     $price round($initialPricePerPerson[$keyDiscount]['totalPrice']);
  619.                     $totalBarre += $price;
  620.                 } else {
  621.                     /* $price = $voyage['tour']['voyage_prix_personne']; */
  622.                     foreach ($voyage['voyageurs'] as $keyVoyageur => $voyageur) {
  623.                         if($voyageur['rowid'] == $keyDiscount) {
  624.                             $price $voyageur['contact_price'];
  625.                         }
  626.                     }
  627.                     $totalBarre += $price;
  628.                 }
  629.             }
  630.             /* dd($voyage, json_decode($voyage['tour']['voyage_price_per_person_to_apply']), $initialPricePerPerson); */
  631.         } else {
  632.             if(isset($voyage['tour']['voyage_initial_price_per_person'])){
  633.                 foreach (json_decode($voyage['tour']['voyage_initial_price_per_person'], true) as $pricePerPerson) {
  634.                     $sum += $pricePerPerson['totalPrice'];
  635.                 }
  636.             }
  637.         }
  638.         /* dd($totalBarre); */
  639.         return $this->render('tour/show2.html.twig', [
  640.                 'params' => $params,
  641.                 'trip' => $voyage,
  642.                 'titleTagName' => 'h1',
  643.                 'key' => $key,
  644.                 'locale' => $locale,
  645.                 'basePath' => $basePath,
  646.                 'arrHotels' => $arrHotels,
  647.                 'initialPricePerPerson' => json_decode($voyage['tour']['voyage_initial_price_per_person'], true),
  648.                 'pricePerPersonToApply' => json_decode($voyage['tour']['voyage_price_per_person_to_apply'], true),
  649.                 'applyDiscountPricePerPerson' => json_decode($voyage['tour']['voyage_apply_discount_price_per_person'], true),
  650.                 'totalPrice' => $sum,
  651.                 'totalBarre' => $totalBarre
  652.         ]);
  653.     }
  654.     /**
  655.      * @Route({
  656.      *     "fr": "{_locale}/votre-voyage/{key}/contacts",
  657.      *     "en": "{_locale}/your-trip/{key}/contacts"
  658.      * }, name="tour_custom_itinary_contact")
  659.      */
  660.     public function customItinaryContacts($keyRequest $requestApiClient $apiClientTranslatorInterface $translator) {
  661.         
  662.         $debug $this->getParameter('kernel.debug');
  663.         $locale $request->getLocale();
  664.         if (!$key) {
  665.             throw new BadRequestHttpException($translator->trans("La clé doit être indiquée"));
  666.         }
  667.         //on recupère les voyageurs
  668.         try {
  669.             $voyageHelper $this->voyageHelper;
  670.             $voyageurs $voyageHelper->getVoyageurs($key);
  671.             $clientId $voyageurs['contacts'][0]['client_id'];
  672.             //sanétization : si un champs à la string "null" en valeur, on le passe à null (vrai valeur vide)
  673.             /*
  674.             foreach($voyageurs['contacts'] as &$v){
  675.                 foreach($v as $key => $field){
  676.                     if(is_string($field)){
  677.                         if($field === "null"){
  678.                             $v[$key] = null;
  679.                         }
  680.                     }
  681.                 }
  682.             }
  683.             */
  684.             // //recup de la session, si pas encore loggé redirect vers login
  685.             // $session = $request->getSession();
  686.             // $userId = $session->get('userId');
  687.             // //on teste si user est bien le contact
  688.             // if ($userId != $clientId) {
  689.             //     $userId = $session->set('userId', '-1');
  690.             //     $this->addFlash(
  691.             //         'warning', $translator->trans('Merci de vous connecter avec le bon utilisateur')
  692.             //     );
  693.             //     return $this->redirectToRoute('login', array('key' => $key));
  694.             // }
  695.         } catch (ClientException $e) {
  696.             if ($debug) {
  697.                 $viewPath "api/error/notfound.html.twig";
  698.                 return $this->render($viewPath, array("message" => sprintf("Erreur API : %s"$this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  699.             }
  700.         }
  701.         if (empty($voyageurs) && $debug) {
  702.             return $this->redirectToRoute('tour_index');
  703.         }
  704.         //TODO get info du form
  705.         $form $this->createForm(InfoTourType::class, array('key' => $key));
  706.         $form->handleRequest($request);
  707.         
  708.         if ($form->isSubmitted() && $form->isValid()) {
  709.             
  710.       
  711.             //on envoi a l'api
  712.             try {
  713.                 $voyageHelper $this->voyageHelper;
  714.                 $retour $voyageHelper->setVoyageurs($key$form->getData());
  715.             } catch (ClientException $e) {
  716.                 if ($debug) {
  717.                     $viewPath "api/error/notfound.html.twig";
  718.                     return $this->render($viewPath, array("message" => sprintf("Erreur API : %s"$this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  719.                 }
  720.             }
  721.             if ($retour) {
  722.                 //redirect sur la page du voyage
  723.                 //                $this->addFlash(
  724.                 //                        'success', $translator->trans('Votre demande a bien été transmise')
  725.                 //                );
  726.                 
  727.                 return $this->redirectToRoute('tour_custom_itinary_valide', array('key' => $key));
  728.             }
  729.         }
  730.        
  731.         //tableau des pays pour faciliter la gestion des selecteurs de pays
  732.         $pays = array(
  733.             => array('value' => 'BE''label' => 'Belgique'),
  734.             => array('value' => 'CA''label' => 'Canada'),
  735.             => array('value' => 'FR''label' => 'France'),
  736.             => array('value' => 'LU''label' => 'Luxembourg'),
  737.             => array('value' => 'CH''label' => 'Suisse'),
  738.             => array(),
  739.             => array('value' => 'AF''label' => 'Afghanistan'),
  740.             => array('value' => 'ZA''label' => 'Afrique du Sud'),
  741.             => array('value' => 'AL''label' => 'Albanie'),
  742.             => array('value' => 'DZ''label' => 'Algérie'),
  743.             10 => array('value' => 'DE''label' => 'Allemagne'),
  744.             11 => array('value' => 'AD''label' => 'Andorre'),
  745.             12 => array('value' => 'AO''label' => 'Angola'),
  746.             13 => array('value' => 'AI''label' => 'Anguilla'),
  747.             14 => array('value' => 'AQ''label' => 'Antarctique'),
  748.             15 => array('value' => 'AG''label' => 'Antigua-et-Barbuda'),
  749.             16 => array('value' => 'SA''label' => 'Arabie saoudite'),
  750.             17 => array('value' => 'AR''label' => 'Argentine'),
  751.             18 => array('value' => 'AM''label' => 'Arménie'),
  752.             19 => array('value' => 'AW''label' => 'Aruba'),
  753.             20 => array('value' => 'AU''label' => 'Australie'),
  754.             21 => array('value' => 'AT''label' => 'Autriche'),
  755.             22 => array('value' => 'AZ''label' => 'Azerbaïdjan'),
  756.             23 => array('value' => 'BS''label' => 'Bahamas'),
  757.             24 => array('value' => 'BH''label' => 'Bahreïn'),
  758.             25 => array('value' => 'BD''label' => 'Bangladesh'),
  759.             26 => array('value' => 'BB''label' => 'Barbade'),
  760.             27 => array('value' => 'BZ''label' => 'Belize'),
  761.             28 => array('value' => 'BM''label' => 'Bermudes'),
  762.             29 => array('value' => 'BT''label' => 'Bhoutan'),
  763.             30 => array('value' => 'BY''label' => 'Biélorussie'),
  764.             31 => array('value' => 'BO''label' => 'Bolivie'),
  765.             32 => array('value' => 'BA''label' => 'Bosnie-Herzégovine'),
  766.             33 => array('value' => 'BW''label' => 'Botswana'),
  767.             34 => array('value' => 'BN''label' => 'Brunei'),
  768.             35 => array('value' => 'BR''label' => 'Brésil'),
  769.             36 => array('value' => 'BG''label' => 'Bulgarie'),
  770.             37 => array('value' => 'BF''label' => 'Burkina Faso'),
  771.             38 => array('value' => 'BI''label' => 'Burundi'),
  772.             39 => array('value' => 'BJ''label' => 'Bénin'),
  773.             40 => array('value' => 'KH''label' => 'Cambodge'),
  774.             41 => array('value' => 'CM''label' => 'Cameroun'),
  775.             42 => array('value' => 'CV''label' => 'Cap Vert'),
  776.             43 => array('value' => 'CL''label' => 'Chili'),
  777.             44 => array('value' => 'CN''label' => 'Chine'),
  778.             45 => array('value' => 'CY''label' => 'Chypre'),
  779.             46 => array('value' => 'CO''label' => 'Colombie'),
  780.             47 => array('value' => 'KM''label' => 'Comores'),
  781.             48 => array('value' => 'KP''label' => 'Corée du Nord'),
  782.             49 => array('value' => 'KR''label' => 'Corée du Sud'),
  783.             50 => array('value' => 'CR''label' => 'Costa Rica'),
  784.             51 => array('value' => 'HR''label' => 'Croatie'),
  785.             52 => array('value' => 'CU''label' => 'Cuba'),
  786.             53 => array('value' => 'CI''label' => 'Côte d\'Ivoire'),
  787.             54 => array('value' => 'DK''label' => 'Danemark'),
  788.             55 => array('value' => 'DJ''label' => 'Djibouti'),
  789.             56 => array('value' => 'DM''label' => 'Dominique'),
  790.             57 => array('value' => 'SV''label' => 'El Salvador'),
  791.             58 => array('value' => 'ES''label' => 'Espagne'),
  792.             59 => array('value' => 'EE''label' => 'Estonie'),
  793.             60 => array('value' => 'FM''label' => 'Etats fédérés de Micronésie'),
  794.             61 => array('value' => 'US''label' => 'Etats-Unis d\'Amérique'),
  795.             62 => array('value' => 'FJ''label' => 'Fidji'),
  796.             63 => array('value' => 'FI''label' => 'Finlande'),
  797.             64 => array('value' => 'GA''label' => 'Gabon'),
  798.             65 => array('value' => 'GM''label' => 'Gambie'),
  799.             66 => array('value' => 'GH''label' => 'Ghana'),
  800.             67 => array('value' => 'GI''label' => 'Gibraltar'),
  801.             68 => array('value' => 'GD''label' => 'Grenade'),
  802.             69 => array('value' => 'GR''label' => 'Grèce'),
  803.             70 => array('value' => 'GU''label' => 'Guam'),
  804.             71 => array('value' => 'GT''label' => 'Guatemala'),
  805.             72 => array('value' => 'GN''label' => 'Guinée'),
  806.             73 => array('value' => 'GQ''label' => 'Guinée équatoriale'),
  807.             74 => array('value' => 'GW''label' => 'Guinée-Bissau'),
  808.             75 => array('value' => 'GE''label' => 'Géorgie'),
  809.             76 => array('value' => 'HT''label' => 'Haïti'),
  810.             77 => array('value' => 'HN''label' => 'Honduras'),
  811.             78 => array('value' => 'HK''label' => 'Hong-Kong'),
  812.             79 => array('value' => 'HU''label' => 'Hongrie'),
  813.             80 => array('value' => 'IN''label' => 'Inde'),
  814.             81 => array('value' => 'ID''label' => 'Indonésie'),
  815.             82 => array('value' => 'IR''label' => 'Iran'),
  816.             83 => array('value' => 'IQ''label' => 'Iraq'),
  817.             84 => array('value' => 'IE''label' => 'Irlande'),
  818.             85 => array('value' => 'IS''label' => 'Islande'),
  819.             86 => array('value' => 'IL''label' => 'Israël'),
  820.             87 => array('value' => 'IT''label' => 'Italie'),
  821.             88 => array('value' => 'JM''label' => 'Jamaïque'),
  822.             89 => array('value' => 'JP''label' => 'Japon'),
  823.             90 => array('value' => 'JO''label' => 'Jordanie'),
  824.             91 => array('value' => 'KZ''label' => 'Kazakhstan'),
  825.             92 => array('value' => 'KE''label' => 'Kenya'),
  826.             93 => array('value' => 'KG''label' => 'Kirghizstan'),
  827.             94 => array('value' => 'KI''label' => 'Kiribati'),
  828.             95 => array('value' => 'KW''label' => 'Koweït'),
  829.             96 => array('value' => 'LA''label' => 'Laos'),
  830.             97 => array('value' => 'LS''label' => 'Lesotho'),
  831.             98 => array('value' => 'LV''label' => 'Lettonie'),
  832.             99 => array('value' => 'LB''label' => 'Liban'),
  833.             100 => array('value' => 'LY''label' => 'Libye'),
  834.             101 => array('value' => 'LR''label' => 'Libéria'),
  835.             102 => array('value' => 'LI''label' => 'Liechtenstein'),
  836.             103 => array('value' => 'LT''label' => 'Lituanie'),
  837.             104 => array('value' => 'MO''label' => 'Macao'),
  838.             105 => array('value' => 'MK''label' => 'Macédoine'),
  839.             106 => array('value' => 'MG''label' => 'Madagascar'),
  840.             107 => array('value' => 'MY''label' => 'Malaisie'),
  841.             108 => array('value' => 'MW''label' => 'Malawi'),
  842.             109 => array('value' => 'MV''label' => 'Maldives'),
  843.             110 => array('value' => 'ML''label' => 'Mali'),
  844.             111 => array('value' => 'MT''label' => 'Malte'),
  845.             112 => array('value' => 'MA''label' => 'Maroc'),
  846.             113 => array('value' => 'MQ''label' => 'Martinique'),
  847.             114 => array('value' => 'MR''label' => 'Mauritanie'),
  848.             115 => array('value' => 'YT''label' => 'Mayotte'),
  849.             116 => array('value' => 'MX''label' => 'Mexique'),
  850.             117 => array('value' => 'MD''label' => 'Moldavie'),
  851.             118 => array('value' => 'MC''label' => 'Monaco'),
  852.             119 => array('value' => 'MN''label' => 'Mongolie'),
  853.             120 => array('value' => 'MS''label' => 'Montserrat'),
  854.             121 => array('value' => 'ME''label' => 'Monténégro'),
  855.             122 => array('value' => 'MZ''label' => 'Mozambique'),
  856.             123 => array('value' => 'MM''label' => 'Myanmar'),
  857.             124 => array('value' => 'NA''label' => 'Namibie'),
  858.             125 => array('value' => 'NR''label' => 'Nauru'),
  859.             126 => array('value' => 'NI''label' => 'Nicaragua'),
  860.             127 => array('value' => 'NE''label' => 'Niger'),
  861.             128 => array('value' => 'NG''label' => 'Nigeria'),
  862.             129 => array('value' => 'NU''label' => 'Nioué'),
  863.             130 => array('value' => 'NO''label' => 'Norvège'),
  864.             131 => array('value' => 'NZ''label' => 'Nouvelle-Zélande'),
  865.             132 => array('value' => 'NP''label' => 'Népal'),
  866.             133 => array('value' => 'OM''label' => 'Oman'),
  867.             134 => array('value' => 'UG''label' => 'Ouganda'),
  868.             135 => array('value' => 'UZ''label' => 'Ouzbékistan'),
  869.             136 => array('value' => 'PK''label' => 'Pakistan'),
  870.             137 => array('value' => 'PW''label' => 'Palau'),
  871.             138 => array('value' => 'PS''label' => 'Palestine'),
  872.             139 => array('value' => 'PA''label' => 'Panama'),
  873.             140 => array('value' => 'PG''label' => 'Papouasie-Nouvelle-Guinée'),
  874.             141 => array('value' => 'PY''label' => 'Paraguay'),
  875.             142 => array('value' => 'NL''label' => 'Pays-Bas'),
  876.             143 => array('value' => 'PH''label' => 'Philippines'),
  877.             144 => array('value' => 'PL''label' => 'Pologne'),
  878.             145 => array('value' => 'PR''label' => 'Porto Rico'),
  879.             146 => array('value' => 'PT''label' => 'Portugal'),
  880.             147 => array('value' => 'PE''label' => 'Pérou'),
  881.             148 => array('value' => 'QA''label' => 'Qatar'),
  882.             149 => array('value' => 'RO''label' => 'Roumanie'),
  883.             150 => array('value' => 'UK''label' => 'Royaume-Uni'),
  884.             151 => array('value' => 'RU''label' => 'Russie'),
  885.             152 => array('value' => 'RW''label' => 'Rwanda'),
  886.             153 => array('value' => 'CF''label' => 'République Centrafricaine'),
  887.             154 => array('value' => 'DO''label' => 'République Dominicaine'),
  888.             155 => array('value' => 'CG''label' => 'République du Congo'),
  889.             156 => array('value' => 'GY''label' => 'République du Guyana'),
  890.             157 => array('value' => 'CD''label' => 'République démocratique du Congo'),
  891.             158 => array('value' => 'CZ''label' => 'République tchèque'),
  892.             159 => array('value' => 'RE''label' => 'Réunion'),
  893.             160 => array('value' => 'SM''label' => 'Saint-Marin'),
  894.             161 => array('value' => 'WS''label' => 'Samoa'),
  895.             162 => array('value' => 'ST''label' => 'Sao Tomé-et-Principe'),
  896.             163 => array('value' => 'RS''label' => 'Serbie'),
  897.             164 => array('value' => 'SC''label' => 'Seychelles'),
  898.             165 => array('value' => 'SL''label' => 'Sierra Leone'),
  899.             166 => array('value' => 'SG''label' => 'Singapour'),
  900.             167 => array('value' => 'SK''label' => 'Slovaquie'),
  901.             168 => array('value' => 'SI''label' => 'Slovénie'),
  902.             169 => array('value' => 'SO''label' => 'Somalie'),
  903.             170 => array('value' => 'SD''label' => 'Soudan'),
  904.             171 => array('value' => 'LK''label' => 'Sri Lanka'),
  905.             172 => array('value' => 'SR''label' => 'Suriname'),
  906.             173 => array('value' => 'SE''label' => 'Suède'),
  907.             174 => array('value' => 'SZ''label' => 'Swaziland'),
  908.             175 => array('value' => 'SY''label' => 'Syrie'),
  909.             176 => array('value' => 'SN''label' => 'Sénégal'),
  910.             177 => array('value' => 'TJ''label' => 'Tadjikistan'),
  911.             178 => array('value' => 'TZ''label' => 'Tanzanie'),
  912.             179 => array('value' => 'TW''label' => 'Taïwan'),
  913.             180 => array('value' => 'TD''label' => 'Tchad'),
  914.             181 => array('value' => 'TH''label' => 'Thaïlande'),
  915.             182 => array('value' => 'TL''label' => 'Timor oriental'),
  916.             183 => array('value' => 'TG''label' => 'Togo'),
  917.             184 => array('value' => 'TO''label' => 'Tonga'),
  918.             185 => array('value' => 'TT''label' => 'Trinité-et-Tobago'),
  919.             186 => array('value' => 'TN''label' => 'Tunisie'),
  920.             187 => array('value' => 'TM''label' => 'Turkménistan'),
  921.             188 => array('value' => 'TR''label' => 'Turquie'),
  922.             189 => array('value' => 'TV''label' => 'Tuvalu'),
  923.             190 => array('value' => 'UA''label' => 'Ukraine'),
  924.             191 => array('value' => 'UY''label' => 'Uruguay'),
  925.             192 => array('value' => 'VU''label' => 'Vanuatu'),
  926.             193 => array('value' => 'VA''label' => 'Vatican'),
  927.             194 => array('value' => 'VE''label' => 'Venezuela'),
  928.             195 => array('value' => 'VN''label' => 'Vietnam'),
  929.             196 => array('value' => 'YE''label' => 'Yémen'),
  930.             197 => array('value' => 'ZM''label' => 'Zambie'),
  931.             198 => array('value' => 'ZW''label' => 'Zimbabwe'),
  932.             199 => array('value' => 'EG''label' => 'Égypte'),
  933.             200 => array('value' => 'AE''label' => 'Émirats arabes unis'),
  934.             201 => array('value' => 'EC''label' => 'Équateur'),
  935.             202 => array('value' => 'ER''label' => 'Érythrée'),
  936.             203 => array('value' => 'ET''label' => 'Éthiopie'),
  937.             204 => array('value' => 'BV''label' => 'Île Bouvet'),
  938.             205 => array('value' => 'MU''label' => 'Île Maurice'),
  939.             206 => array('value' => 'AX''label' => 'Îles Åland'),
  940.         );
  941.         //dd($voyageurs);
  942.         return $this->render('tour/form_contact.html.twig', [
  943.                     'voyageurs' => $voyageurs,
  944.                     'pays' => $pays,
  945.                     'titleTagName' => 'h1',
  946.                     'form' => $form->createView(),
  947.                     'upload_dir' => $this->getParameter('upload_dir'),
  948.                     'locale' => $locale
  949.         ]);
  950.     }
  951.     /**
  952.      * @Route({
  953.      *     "fr": "{_locale}/votre-voyage/{key}/valide",
  954.      *     "en": "{_locale}/your-trip/{key}/valide"
  955.      * }, name="tour_custom_itinary_valide")
  956.      */
  957.     public function customItinaryValide($keyRequest $requestApiClient $apiClientTranslatorInterface $translator) {
  958.         
  959.         $locale $request->getLocale();
  960.         $voyageHelper $this->voyageHelper;
  961.         $voyageur $voyageHelper->getVoyageurs($key);
  962.         $prenom '';
  963.         
  964.         if(!is_null($voyageur)){
  965.             if(array_key_exists("contacts"$voyageur)){
  966.                 $prenom $voyageur["contacts"][0]["firstname"];
  967.             }
  968.         }
  969.         
  970.         return $this->render('tour/valide.html.twig', [
  971.                     'prenom' => $prenom,
  972.                     'titleTagName' => 'h1',
  973.                     'locale' => $locale
  974.         ]);
  975.     }
  976.      /**
  977.      * @Route("/{_locale}/{pays}/{slug}", name="show_tour")
  978.      */
  979.     public function showTour($pays$slugRequest $request,
  980.      ApiClient $apiClient,
  981.      TranslatorInterface $translator,
  982.      VoyageHelper $voyageHelper,
  983.      SeoHelper $seoHelper) {
  984.         $debug      $this->getParameter('kernel.debug');
  985.         $entity     'tour';
  986.         $locale     $request->getLocale();
  987.         $basePath   $this->getParameter('api.base_uri').'/uploads/';
  988.         
  989.         //$voyageHelper = new VoyageHelper($apiClient,$locale);
  990.         //$voyages = $voyageHelper->getAll();
  991.         $contentHelper $this->contentHelper;
  992.         $locale $request->getLocale();
  993.         if(!in_array($locale,['fr','en'])){
  994.             $request->getSession()->set('_locale'"fr");
  995.             $locale $request->getSession()->get('_locale'"fr");
  996.         }
  997.         //$voyages =  $contentHelper->getTraductionCustomTour($voyages,$locale);
  998.         //Si la langue n'est pas FR, le slug est très probablement une version traduite
  999.         //il faut retrouver sa version originale.
  1000.         if($locale != "fr"){
  1001.             $realSlug $contentHelper->getVoyageByTranslatedSlug($slug,$locale);
  1002.             //Verifier si le $pays est correct
  1003.             
  1004.            
  1005.             if(!in_array($pays,
  1006.             ["thailand","indonesia""cambodia","sri-lanka""philippines","vietnam","laos""birmanie-myanmar"])){
  1007.                 return $this->redirectToRoute("homepage", ["_locale"=> $locale], 301);
  1008.             }
  1009.             if(!is_null($realSlug)){
  1010.                 $slug $realSlug;
  1011.             }
  1012.             
  1013.         }else{
  1014.             //Si on est en FR et que le pays n'est pas bon, on redirige à l'accueil.
  1015.             if(!in_array($pays,
  1016.             ["thailande","indonesie""cambodge","sri-lanka""philippines","vietnam","laos" ,"birmanie-myanmar"])){
  1017.                 return $this->redirectToRoute("homepage", ["_locale"=>$locale], 301);
  1018.             }
  1019.         }
  1020.         try {
  1021.             $seo $seoHelper->getSeoBySlug($entity$slug$request->getLocale());
  1022.         } catch (ClientException $e) {
  1023.             if ($debug) {
  1024.                 $viewPath "api/error/notfound.html.twig";
  1025.                 return $this->render($viewPath, array("message" => sprintf("Erreur API : %s"$this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  1026.             }
  1027.         }
  1028.        
  1029.         $trip $voyageHelper->getOneBySlug($slug);
  1030.         //Traductions du customtour 
  1031.         if($locale != "fr" && $trip && $slug == $realSlug){
  1032.             $traductionContent =  $contentHelper->getTraductionCustomTour([$trip['tour']],$locale);
  1033.             $trip['tour'] = $traductionContent[0] ?? $trip['tour'];
  1034.             //traduction des commodités
  1035.             foreach($trip['commodities'] as &$commodite){
  1036.                 $tradCommodity $contentHelper->getTraductionContenu($commodite['commodity_id'],"ext_commodite",$locale);
  1037.                 if(!empty($tradCommodity)){
  1038.                     $commodite['commodity_libelle'] = $tradCommodity['libelle'];
  1039.                 }else{
  1040.                     $commodite['commodity_libelle'] = $commodite['libelle'] ?? "";
  1041.                 }
  1042.               
  1043.             }
  1044.            
  1045.             //traduction des jours
  1046.          
  1047.             foreach($trip['days'] as &$day){
  1048.                 $trad $contentHelper->getTraductionContenu($day['day_id'],"ext_customtour_day",$locale);
  1049.                 if(!empty($trad)){
  1050.                     $day['day_libelle'] = $trad['libelle'] ?? $day['day_libelle'];
  1051.                     $day['day_description'] = $trad['description'];
  1052.                 }else{
  1053.                     $day['day_libelle'] = $day['day_libelle'];
  1054.                     $day['day_description'] = $day['description'];
  1055.                 }
  1056.                 //traduction des elements de l'hotel et sous-jacent
  1057.                 if (isset($day) && !empty($day['hotels'])) {
  1058.                     foreach ($day['hotels'] as &$hotel) {
  1059.                         //Hotel
  1060.                         //dd($hotel);
  1061.                         $tradHotel $contentHelper->getTraductionContenu($hotel['service_id'], "ext_service"$locale);
  1062.                         if (!is_null($tradHotel) && !empty($tradHotel)) {
  1063.                             //hotel_description
  1064.                             $hotel['hotel_description'] = (isset($tradHotel['description'])) ? $tradHotel['description'] :  $hotel['hotel_description'];
  1065.                         }
  1066.                         //commodities
  1067.                         //Si l'hotel possède un champs "rooms" qui n'est pas vide 
  1068.                         if (isset($hotel['rooms']) && !empty($hotel['rooms'])) {
  1069.                             foreach ($hotel['rooms'] as &$room) {
  1070.                                 //dump($room);
  1071.                                 $tradRoom $contentHelper->getTraductionContenu($room['room_id'], "ext_hotel_chambre"$locale);
  1072.                                 if (!is_null($tradRoom) && !empty($tradRoom)) {
  1073.                                     //description
  1074.                                     $room['description'] = (isset($tradRoom['description'])) ? $tradRoom['description'] :  $room['description'];
  1075.                                 }
  1076.                                 
  1077.                                 //Commodités de la room
  1078.                                 if (isset($room['commodities']) && !empty($room['commodities'])) {
  1079.                                     foreach ($room['commodities'] as &$commodity) {
  1080.                                         $tradCom $contentHelper->getTraductionContenu($commodity['commodity_id'], "ext_commodite"$locale);
  1081.                                         if (!is_null($tradCom) && !empty($tradCom)) {
  1082.                                             //description
  1083.                                             $commodity['commodity_libelle'] = (isset($tradCom['libelle'])) ? $tradCom['libelle'] :  $commodity['commodity_libelle'];
  1084.                                         }
  1085.                                     }
  1086.                                 }
  1087.                             }
  1088.                         }
  1089.                     }
  1090.                 }
  1091.               
  1092.                 //traduction des supports
  1093.                 foreach($day['supports'] as &$support){
  1094.                     $trad $contentHelper->getTraductionContenu($support['id'],"ext_customtour_day_support",$locale);
  1095.                     if(!empty($trad)){
  1096.                         $support['libelle'] = $trad['libelle'];
  1097.                     }
  1098.                   
  1099.                 }
  1100.             }
  1101.             //dd($trip['days']);
  1102.             
  1103.         }
  1104.         if(!$trip){
  1105.              $this->addFlash(
  1106.                     'danger'$translator->trans('ce voyage n\'existe pas')
  1107.             );
  1108.             return $this->redirectToRoute('tour_index', [], 301);
  1109.         }
  1110.   
  1111.         foreach($trip['hotels'] as &$hotel){
  1112.             //$hotel = $contentHelper->getTraductionContenu($support['id'],"ext_customtour_day_support",$locale);
  1113.         }
  1114.      
  1115.         foreach($trip['cruises'] as &$cruise){
  1116.             //$cruise = $contentHelper->getTraductionContenu($support['id'],"ext_customtour_day_support",$locale);
  1117.         }
  1118.         //on organise les hotels et croisieres par destination car en twig c'est chiant
  1119.         $arrHotels = array();
  1120.         
  1121.         $arrayHEtC array_merge($trip['hotels'],$trip['cruises']);
  1122.         //dd($arrayHEtC);
  1123.         foreach($arrayHEtC as $keyH => $hotelOuCroisiere){
  1124.             if(!array_key_exists($hotelOuCroisiere['destination_libelle'], $arrHotels)){
  1125.                 $arrHotels[$hotelOuCroisiere['destination_libelle']] = array();
  1126.             }
  1127.             array_push($arrHotels[$hotelOuCroisiere['destination_libelle']],$hotelOuCroisiere);
  1128.         }
  1129.         
  1130.         // Recherche de voyages sur la même destination
  1131.         $voyagesDestination = [];
  1132.         $voyagesAutresDestinations = [];
  1133.         $voyageHelper $this->voyageHelper;
  1134.      
  1135.         $voyagesDestination $voyageHelper->getAll($trip['tour']['pays_slug'], null1nullnullnull'ct.ordre''ASC'12null);
  1136.     
  1137.         if (empty($voyagesDestination)) {
  1138.             $voyagesAutresDestinations $voyageHelper->getAll(nullnull1nullnullnull'ct.ordre''ASC'12null);
  1139.         }
  1140.         //Voyages 'coup de coeur'
  1141.         $pays $request->query->get('pays');
  1142.         $theme $request->query->get('theme');
  1143.         $favoris $request->query->get('favoris');
  1144.         $dateDebut $request->query->get('dateDebut');
  1145.         $duree $request->query->get('duree');
  1146.         $tag $request->query->get('tag');
  1147.         $page $request->query->get('page'1);
  1148.         $perPage $request->query->get('perPage'6);
  1149.         $sort $request->query->get('sort''ct.ordre'); 
  1150.         $direction $request->query->get('direction''ASC');
  1151.         $limit $request->query->get('limit'6); 
  1152.         $offset $request->query->get('offset');
  1153.         
  1154.         try {
  1155.             $voyageHelper $this->voyageHelper;
  1156.             $voyages $voyageHelper->getAll($pays$theme$favoris$dateDebut$duree$tag$sort$direction$limit$offset);
  1157.             
  1158.         } catch (ClientException $e) {
  1159.             if ($debug) {
  1160.                 $viewPath "api/error/notfound.html.twig";
  1161.                 return $this->render($viewPath, array("message" => sprintf("Erreur API : %s"$this->getParameter('api.base_uri') . $e->getRequest()->getRequestTarget())));
  1162.             }
  1163.         }
  1164.         $params = [];
  1165.         $params['arrivee'] = $request->query->get('arrival'"");
  1166.         $params['duree'] = $request->query->get('duration_range'"");
  1167.         $params['categorie'] = $request->query->get('category'"");
  1168.         $params['defaultTour'] = "default";
  1169.         $bestSellerTableau $voyageHelper->getBestseller(""8);
  1170.         $tabBestSeller = [];
  1171.         $index 0;
  1172.         if(!empty($bestSellerTableau)){
  1173.             foreach($bestSellerTableau as $best){
  1174.                 if($index 4){
  1175.                     if($index 2){
  1176.                         $tabBestSeller['partiGauche']['carre'][] = $best;
  1177.                     }
  1178.                     if($index == 2){
  1179.                         $tabBestSeller['partiGauche']['hauteur'] = $best;
  1180.                     }
  1181.                     if($index == 3){
  1182.                         $tabBestSeller['partiGauche']['largeur'] = $best;
  1183.                     }
  1184.                 } else {
  1185.                     if($index == 4){
  1186.                         $tabBestSeller['partiDroite']['largeur'] = $best;
  1187.                     }
  1188.                     if($index && $index 7){
  1189.                         $tabBestSeller['partiDroite']['carre'][] = $best;
  1190.                     }
  1191.                     if($index == 7){
  1192.                         $tabBestSeller['partiDroite']['hauteur'] = $best;
  1193.                     }                
  1194.                 }
  1195.             $index++;
  1196.             }
  1197.         }
  1198.         /**
  1199.          * si plus d'une image, supprimer les images qui ne sont pas dans le répertoire customtour (car identiques)
  1200.          */
  1201.         if(count($trip['pictures']) > 1) {
  1202.             $offset 0;
  1203.             foreach($trip['pictures'] as $pictureKey => $picture) {
  1204.                 if($picture['document_entite'] === false) {
  1205.                     array_splice($trip['pictures'], $offset1);
  1206.                 }
  1207.                 $offset++;
  1208.             }
  1209.         }
  1210.         
  1211.         return $this->render('tour/show2.html.twig', [
  1212.             'seo'       => $seo,
  1213.             'trip'      => $trip,
  1214.             'slug'      => $slug,
  1215.             'locale'    => $locale,
  1216.             'basePath'  => $basePath,
  1217.             'arrHotels' => $arrHotels,
  1218.             'voyagesDestination' => $voyagesDestination,
  1219.             'voyages' => $voyages,
  1220.             'voyagesAutresDestinations' => $voyagesAutresDestinations,
  1221.             'params' => $params,
  1222.             'tabBestSeller' => $tabBestSeller
  1223.         ]);
  1224.     }
  1225.    
  1226. }