src/Controller/VoyagesOrganise/IndexController.php line 73

Open in your IDE?
  1. <?php
  2. namespace App\Controller\VoyagesOrganise;
  3. use App\Service\Generale;
  4. use App\Service\WSCMS;
  5. use App\Service\WSVoyagesOrganise;
  6. use APY\BreadcrumbTrailBundle\BreadcrumbTrail\Trail;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\HttpFoundation\Session\SessionInterface as Session;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. class IndexController extends AbstractController
  14. {
  15.     public function __construct(Generale $service)
  16.     {
  17.         $this->service $service;
  18.     }
  19.     public function listvoyages($type$themes$destinations$paysSession $sessionWSVoyagesOrganise $voyagesOrganiseRequest $request): Response
  20.     {
  21.         if (!$this->service->hasModule('voyages-organise')) {
  22.             $this->addFlash('danger''Produit sans licence');
  23.             return $this->render('bundles/TwigBundle/Exception/error404.html.twig');
  24.         }
  25.         $session->set('nameType'$request->get('nameType'));
  26.         $session->set('routeDetails'$request->get('routeDetails'));
  27.         $key "title_{$request->get('_route')}_" implode('-'$request->get('_route_params'));
  28.         if (isset($_GET['title'])) {
  29.             $session->set($key$_GET['title']);
  30.             return $this->redirectToRoute($request->get('_route'), $request->get('_route_params'));
  31.         }
  32.         return $this->render($this->service->checkCustomTemplate('VoyagesOrganise/listvoyages.html.twig'), [
  33.             'title' => $session->get($key$request->get('nameType')),
  34.             /*'detailsVoyages'=>$detailsVoyages,*/
  35.             'themes' => $themes,
  36.             'destinations' => $destinations,
  37.             'pays' => $pays,
  38.             'type' => $type,
  39.         ]);
  40.     }
  41.     public function jsonVoyages($typeWSVoyagesOrganise $voyagesOrganiseSession $session)
  42.     {
  43.         $listeVoyages $voyagesOrganise->getListe($_GET);
  44.         if (isset($listeVoyages['Error']))
  45.             return new JsonResponse(['Error' => $listeVoyages['Error']]);
  46.         $voyages = array();
  47.         foreach ($listeVoyages['Resultat'] as $voyage) {
  48.             $_voyages $voyage;
  49.             $_voyages['route'] = $this->get('router')->generate($session->get('routeDetails'), array('slug' => $voyage['slug']));
  50.             $voyages['Voyage'][] = $_voyages;
  51.         }
  52.         $voyages['filtre'] = $listeVoyages['filtre'];
  53.         $voyages['referentielle'] = $listeVoyages['referentielle'];
  54.         return new JsonResponse($voyages);
  55.     }
  56.     public function detailsVoyages($slugWSVoyagesOrganise $voyagesOrganiseWSCMS $WSCMSTrail $trailSession $sessionRequest $request): Response
  57.     {
  58.         $detailsVoyages $voyagesOrganise->getDetails(['slug' => $slug]);
  59.         $type $detailsVoyages['Resultat']['type'];
  60.         $session->set('routeConfirm'$request->get('routeConfirm'));
  61.         $trail->add($request->get('nameType'), $request->get('routeList'));
  62.         $session->set('nameType'$request->get('nameType'));
  63.         $session->set('routeList'$request->get('routeList'));
  64.         $configAffichage = array();
  65.         if (!is_null($WSCMS->ConfigFrontOffice()))
  66.             $configAffichage $WSCMS->ConfigFrontOffice()['ConfigFrontOffice'];
  67.         $facebook $WSCMS->ReseauxSociaux()['ReseauxSociaux']['facebook'];
  68.         if (isset($detailsVoyages['Resultat'])) {
  69.             $detailsVoyages $detailsVoyages['Resultat'];
  70.             return $this->render($this->service->checkCustomTemplate('VoyagesOrganise/details/details.html.twig'),
  71.                 [
  72.                     'details' => $detailsVoyages,
  73.                     'configAffichage' => $configAffichage,
  74.                     'facebook' => $facebook,
  75.                     'type' => $type
  76.                 ]);
  77.         } else {
  78.             return $this->render('bundles/TwigBundle/Exception/error500.html.twig');
  79.         }
  80.     }
  81.     /**
  82.      * @Route("/reservation/{slug}/{pack}/{periode}",  name="reservation")
  83.      */
  84.     public function reservationVoyages($slug$pack$periodeWSVoyagesOrganise $voyagesOrganiseWSCMS $WSCMSTrail $trailSession $sessionRequest $request): Response
  85.     {
  86.         if ($request->isMethod('POST') and !isset($_POST['reservation'])) {
  87.             if ($request->files->get('fichier') != null) {
  88.                 $uniqid sha1(uniqid(mt_rand(), TRUE));
  89.                 foreach ($request->files->get('fichier') as $i => $file)
  90.                     $_POST['data']['file-passeport'][] = [
  91.                         'nom' => "$i-$uniqid.{$file->guessExtension()}",
  92.                         'ordre' => 0,
  93.                         'base64' => [
  94.                             'contents' => base64_encode(file_get_contents($file->getPathName())),
  95.                             'originalName' => $file->getClientOriginalName(),
  96.                             'size' => $file->getSize(),
  97.                             'mimeType' => $file->getMimeType()
  98.                         ],
  99.                         'nomOrigine' => $file->getClientOriginalName(),
  100.                         'taille' => '',
  101.                         'width' => getimagesize($file)[0],
  102.                         'height' => getimagesize($file)[1]
  103.                     ];
  104.             }
  105.             foreach ($_POST['data'] as $key => &$value)
  106.                 if (strpos($key'_nom_') !== false && $value == "")
  107.                     $value "*";
  108.             $res $voyagesOrganise->saveReservation($_POST);
  109.             if ($request->isXmlHttpRequest())
  110.                 return new JsonResponse($res);
  111.             if (isset($res["Resultat"]["err"]["message"]) and $res["Resultat"]["err"]["message"])
  112.                 throw new \ErrorException($res["Resultat"]["err"]["message"]);
  113.             else {
  114.                 // if (!isset($res["Resultat"]["err"]["message"]) and !$res["Resultat"]["err"]["message"]){
  115.                 $paymentOnline $res["Resultat"]['PaymentOnline'];
  116.                 $idbook $res["Resultat"]["id"];
  117.                 $route_confir $this->generateUrl($_POST['routeConfirm'], ['Paiement' => $paymentOnline 'EnLigne' 'Agence''id' => $idbook,], 0);
  118.                 $url_echec $this->generateUrl('front_voyageorganise_echec', [], 0);
  119.                 if ($paymentOnline)
  120.                     return $this->redirect("{$this->service->domaineBack()}/payment-electronique/2/{$res["Resultat"]["id"]}/VO?url_succes=" urlencode($route_confir) . "&url_echec=" urlencode($url_echec) );
  121.                 return $this->redirect($route_confir);
  122.             }
  123.             //return $this->redirectToRoute($_POST['routeConfirm'], ['Paiement' => 'Agence', 'id' => $res["Resultat"]["id"],]);
  124.         }
  125.         $detailsVoyages $voyagesOrganise->getDetails(['slug' => $slug])['Resultat'];
  126.         $type $detailsVoyages['type'];
  127.         $libelle $detailsVoyages['libelle'];
  128.         $trail->add($session->get('nameType'), $session->get('routeList'));
  129.         $trail->add($libelle"front_voyagecarte_details", ['slug' => $slug]);
  130.         $_pack = array();
  131.         $_periode = array();
  132.         $periodes $detailsVoyages['PERIODES'];
  133.         foreach ($periodes as $periode) {
  134.             foreach ($periode['PACKS'] as $pck) {
  135.                 if ($pck['id'] == $pack) {
  136.                     $_pack $pck;
  137.                     $_periode $periode;
  138.                 }
  139.             }
  140.         }
  141.         $pointsventes array_map(function ($item) {
  142.             $tel = [];
  143.             if ($item['tel1'])
  144.                 $tel[] = $item['tel1'];
  145.             if ($item['tel2'])
  146.                 $tel[] = $item['tel2'];
  147.             if ($item['fax'])
  148.                 $tel[] = $item['fax'];
  149.             return [
  150.                 'id' => $item['id'],
  151.                 'libelle' => $item['libelle'],
  152.                 'tel' => implode(' / '$tel),
  153.                 'adresse' => $item['adresse'],
  154.                 'franchise' => $item['franchise'],
  155.             ];
  156.         }, $WSCMS->PointVente(['franchis' => true])['PointsVente']);
  157.         $ModePayement $WSCMS->ModePayement([
  158.             'produit' => 'VO',
  159.             'montant' => $detailsVoyages['prix']
  160.         ]);
  161.         $configAffichage = array();
  162.         if (!is_null($WSCMS->ConfigFrontOffice()))
  163.             $configAffichage $WSCMS->ConfigFrontOffice()['ConfigFrontOffice'];
  164.         $facebook $WSCMS->ReseauxSociaux()['ReseauxSociaux']['facebook'];
  165.         return $this->render($this->service->checkCustomTemplate('VoyagesOrganise/reservation.html.twig'),
  166.             [
  167.                 'details' => $detailsVoyages,
  168.                 'packs' => $_pack,
  169.                 'periode' => $_periode,
  170.                 'rib' => $ModePayement['ModePayement']['CoordonnnesBancarie'],
  171.                 'rip' => $ModePayement['ModePayement']['CoordonnnesPostales'],
  172.                 'methodPayment' => $ModePayement['ModePayement']['MethodPayment'],
  173.                 'typePayment' => $ModePayement['ModePayement']['TypePayment'],
  174.                 'pointsventes' => $pointsventes,
  175.                 'configAffichage' => $configAffichage,
  176.                 'facebook' => $facebook,
  177.                 'type' => $type
  178.             ]);
  179.     }
  180.     public function echec($detailsPayement): Response
  181.     {
  182.         if ($detailsPayement) {
  183.             $detailsPayement json_decode(base64_decode($detailsPayement), true);
  184.             $this->addFlash('danger'$detailsPayement['Echec']);
  185.             unset($detailsPayement['Echec']);
  186.         } else
  187.             $detailsPayement = [];
  188.         return $this->render($this->service->checkCustomTemplate('VoyagesOrganise/echec.html.twig'), [
  189.             'detailsPayement' => $detailsPayement
  190.         ]);
  191.     }
  192.     public function saveReservation($idWSVoyagesOrganise $voyagesOrganiseTrail $trailSession $sessionRequest $request): Response
  193.     {
  194.         if (isset($_GET['id']))
  195.             $id $_GET['id'];
  196.         $detailsReservation $voyagesOrganise->detailsReservation(['id' => $id]);
  197.         $type $detailsReservation['type'];
  198.         $libelle $detailsReservation['voyage'];
  199.         $slug $detailsReservation['slug'];
  200.         $trail->add($session->get('nameType'), $session->get('routeList'));
  201.         $trail->add($libelle"front_voyagecarte_details", ['slug' => $slug]);
  202.         return $this->render($this->service->checkCustomTemplate('VoyagesOrganise/succes.html.twig'),
  203.             [
  204.                 'succes' => ['Resultat' => $detailsReservation],
  205.                 'detailreservation' => ['payment_type' => $detailsReservation['payment_type']],
  206.                 'detailsPayement' => $detailsReservation['DetailsPayement'],
  207.                 'type' => $type
  208.             ]
  209.         );
  210.     }
  211. }