src/Aviatur/MultiBundle/Controller/FlightHotelController.php line 52

Open in your IDE?
  1. <?php
  2. namespace Aviatur\MultiBundle\Controller;
  3. use Knp\Snappy\Pdf;
  4. use Aviatur\AgencyBundle\Entity\Agency;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. use Aviatur\TwigBundle\Services\TwigFolder;
  7. use Aviatur\FlightBundle\Models\FlightModel;
  8. use Symfony\Component\HttpFoundation\Cookie;
  9. use Aviatur\HotelBundle\Services\UrlService;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\RouterInterface;
  13. use Aviatur\GeneralBundle\Services\ExceptionLog;
  14. use Aviatur\GeneralBundle\Services\AviaturMailer;
  15. use Symfony\Bundle\FrameworkBundle\Routing\Router;
  16. use Symfony\Component\HttpFoundation\JsonResponse;
  17. use Aviatur\MultiBundle\Services\MultiCustomUtils;
  18. use Aviatur\GeneralBundle\Services\AviaturPixeles;
  19. use Aviatur\GeneralBundle\Services\AviaturLogSave;
  20. use Aviatur\MultiBundle\Services\MultiHotelDiscount;
  21. use Aviatur\FlightBundle\Services\SearchFlightCookie;
  22. use Aviatur\GeneralBundle\Services\AviaturWebService;
  23. use Symfony\Component\HttpFoundation\RedirectResponse;
  24. use Aviatur\GeneralBundle\Services\PayoutExtraService;
  25. use Aviatur\GeneralBundle\Services\AviaturErrorHandler;
  26. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  27. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  28. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  29. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  30.         
  31. class FlightHotelController extends AbstractController
  32. {
  33.     /**
  34.      * @var Agency|object|null
  35.      */
  36.     protected $agency;
  37.     /**
  38.      * @var bool
  39.      */
  40.     protected $isAval;
  41.     public function __construct(ManagerRegistry $managerRegistrySessionInterface $session) {
  42.         $this->session $session;
  43.         $this->em $managerRegistry->getManager();
  44.         $this->agency $this->em->getRepository(Agency::class)->find($session->get('agencyId'));
  45.         $this->isAval $this->agency && strpos($this->agency->getName(), 'Aval') !== false;
  46.     }
  47.     public function resultsAction(Request $requestSessionInterface $sessionAviaturPixeles $aviaturPixelesManagerRegistry $registryAviaturErrorHandler $aviaturErrorHandlerSearchFlightCookie $searchFlightCookieAviaturWebService $aviaturWebServiceTwigFolder $twigFolderUrlService $urlService$origin1$destination1$date1$date2 null$rooms$adult1 null$child1 null$adult2 null,$child2 null$adult3 null$child3 null) {
  48.         $AvailabilityArray = [];
  49.         $urlDescription = [];
  50.         $pixel = [];
  51.         $em $registry->getManager();
  52.         $fullRequest $request;
  53.         // generate request url with safe optional query string
  54.         $safeQuery = [];
  55.         $safeParams = ['class''stop''airline''carryOn''baggage''tourCode''airlineTourCode''isActiveTourCode'];
  56.         foreach ($safeParams as $param) {
  57.             if ($fullRequest->query->has($param)) {
  58.                 $safeQuery[$param] = \urlencode($fullRequest->query->get($param));
  59.             }
  60.         }
  61.         $requestUrl $this->generateUrl($fullRequest->attributes->get('_route'), array_merge($fullRequest->attributes->get('_route_params'), $safeQuery));
  62.         $agency $em->getRepository(\Aviatur\AgencyBundle\Entity\Agency::class)->find($session->get('agencyId'));
  63.         if ($session->has('notEnableMultiHVSearch')) {
  64.             return $this->redirect($aviaturErrorHandler->errorRedirectNoEmail('/''Busqueda de resultados''No podemos realizar la consulta ya que no existe un proveedor configurado para este servicio'));
  65.         }
  66.         $safeUrl 'https://'.$agency->getDomainsecure();
  67.         // CREATE FLIGHT/HOTEL URL FOR AJAX
  68.         $adults 0;
  69.         $children 0;
  70.         $infants 0;
  71.         $hotelPassenger null;
  72.         $services = [];
  73.         $countAdults 0;
  74.         $countChildren 0;
  75.         $childAgesCookie 0;
  76.         $flights 2;
  77.         $dateError = [];
  78.         for ($i 1$i <= $flights; ++$i) {
  79.             $AvailabilityArray['date'.$i] = false !== strpos(${'date'.$i}, 'T') ? date('Y-m-d\TH:i:s'strtotime(substr(${'date'.$i}, 010).sprintf('+%d hours'substr(${'date'.$i}, -2)))) : date('Y-m-d\TH:i:s'strtotime(substr(${'date'.$i}, 010)));
  80.             if ($i 1) {
  81.                 if (($AvailabilityArray['date'.$i] < $AvailabilityArray['date'.($i 1)]) || ((date('Y-m-d\TH:i:s'strtotime($AvailabilityArray['date'.$i])) < date('Y-m-d\TH:i:s'strtotime('today +6 hour'))) && ((date('H'strtotime('now')) >= 18) || (date('Y-m-d'strtotime('today')) > date('Y-m-d'strtotime($AvailabilityArray['date1']))))) || ($AvailabilityArray['date'.$i] > date('Y-m-d\TH:i:s'strtotime('+12 month')))) {
  82.                     $dateError[$i] = $AvailabilityArray['date'.$i];
  83.                 }
  84.             } else {
  85.                 if (((date('Y-m-d\TH:i:s'strtotime($AvailabilityArray['date'.$i])) < date('Y-m-d\TH:i:s'strtotime('today +6 hour'))) && ((date('H'strtotime('now')) >= 18) || (date('Y-m-d'strtotime('today')) > date('Y-m-d'strtotime($AvailabilityArray['date'.$i]))))) || ($AvailabilityArray['date'.$i] > date('Y-m-d\TH:i:s'strtotime('+11 month')))) {
  86.                     $dateError[$i] = $AvailabilityArray['date'.$i];
  87.                 }
  88.             }
  89.         }
  90.         if (!= sizeof($dateError)) {
  91.             //test: /vuelos/BAQ-BOG/2014-12-18+2014-12-15/1-0-0
  92.             foreach ($dateError as $key => $date) {
  93.                 if ($date date('Y-m-d\TH:i:s'strtotime('today +12 hour'))) {
  94.                     ${'date'.$key} = date('Y-m-d'strtotime('+1 day'));
  95.                 } elseif ($date date('Y-m-d\TH:i:s'strtotime('+28 day'))) {
  96.                     if (isset($AvailabilityArray['date'.($key 1)])) {
  97.                         ${'date'.$key} = date('Y-m-d'strtotime($AvailabilityArray['date'.($key 1)].'+1 week'));
  98.                         if (${'date'.$key} > date('Y-m-d\TH:i:s'strtotime('+28 day'))) {
  99.                             ${'date'.$key} = date('Y-m-d'strtotime('+27 day'));
  100.                         }
  101.                     } else {
  102.                         ${'date'.$key} = date('Y-m-d'strtotime(${'date'.$key}.'-12 month'));
  103.                     }
  104.                 } else {
  105.                     ${'date'.$key} = date('Y-m-d'strtotime($AvailabilityArray['date'.($key 1)].'+1 week'));
  106.                 }
  107.             }
  108.             $url $this->generateUrl(
  109.                 $request->get('_route'),
  110.                 [
  111.                 'date1' => $date1,
  112.                 'date2' => $date2,
  113.                 'origin1' => $origin1,
  114.                 'destination1' => $destination1,
  115.                 'rooms' => $rooms,
  116.                 'adult1' => $adult1,
  117.                 'child1' => $child1,
  118.                 'adult2' => $adult2,
  119.                 'child2' => $child2,
  120.                 'adult3' => $adult3,
  121.                 'child3' => $child3,
  122.                 'multi' => 'vuelo-y-hotel',
  123.                     ]
  124.             );
  125.             return $this->redirect($aviaturErrorHandler->errorRedirectNoEmail($url'Recomendación Automática''La consulta que realizaste no era válida, hemos analizado tu búsqueda y esta es nuestra recomendación'));
  126.         }
  127.         for ($i 1$i <= $rooms; ++$i) {
  128.             $adults $adults + ${'adult'.$i};
  129.             $hotelPassenger .= '/'.${'adult'.$i}.'+'.${'child'.$i};
  130.             if ('n' != ${'child'.$i}) {
  131.                 $childs explode('-', ${'child'.$i});
  132.                 foreach ($childs as $child) {
  133.                     if ($child >= 2) {
  134.                         ++$children;
  135.                     } else {
  136.                         ++$infants;
  137.                     }
  138.                 }
  139.             }
  140.         }
  141.         $searchParam = ['class''stop''airline''carryOn''baggage''isActiveTourCode''airlineTourCode''tourCode'];
  142.         $optionalArray $this->getParamsInRequest($fullRequest$searchParam);
  143.         $optionals sizeof($optionalArray) > '?'.implode('&'$optionalArray) : '';
  144.         // CITY INFORMATION
  145.         $originLabel $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneByIata($origin1);
  146.         if (null == $originLabel) {
  147.             $originLabel $em->getRepository(\Aviatur\SearchBundle\Entity\SearchAirports::class)->findOneByIata($origin1)->getSearchCities();
  148.         }
  149.         $destinationLabel $em->getRepository(\Aviatur\SearchBundle\Entity\SearchCities::class)->findOneByIata($destination1);
  150.         if (null == $destinationLabel) {
  151.             $destinationLabel $em->getRepository(\Aviatur\SearchBundle\Entity\SearchAirports::class)->findOneByIata($destination1)->getSearchCities();
  152.         }
  153.         $ajaxMultiFlightUrl '/vuelos/'.$originLabel->getIata().'-'.$destinationLabel->getIata().'/'.$date1.'+'.$date2.'/'.$adults.'-'.$children.'-'.$infants.$optionals;
  154.         $hotelDate1 false !== strpos($date1'T') ? substr($date1010) : $date1;
  155.         $hotelDate2 false !== strpos($date2'T') ? substr($date2010) : $date2;
  156.         $ajaxMultiHotelUrl '/hoteles/'.$destinationLabel->getIata().'/'.$hotelDate1.'+'.$hotelDate2.''.$hotelPassenger;
  157.         $AvailabilityArray = [
  158.             'originLabel1' => $originLabel->getCity().', '.$originLabel->getCountry().' ('.$originLabel->getIata().')',
  159.             'destinationLabel1' => $destinationLabel->getCity().', '.$destinationLabel->getCountry().' ('.$destinationLabel->getIata().')',
  160.             'originCity1' => $originLabel->getCity(),
  161.             'destinationCity1' => $destinationLabel->getCity(),
  162.             'date1' => $AvailabilityArray['date1'],
  163.             'date2' => $AvailabilityArray['date2'],
  164.             'origin1' => $origin1,
  165.             'destination1' => $destination1,
  166.             'adults' => $adults,
  167.             'children' => $children,
  168.             'infants' => $infants,
  169.             'rooms' => $rooms,
  170.             'countryCode' => $destinationLabel->getCountrycode(),
  171.         ];
  172.         $AvailabilityArray = [
  173.             'cityName' => $destinationLabel->getCity(),
  174.             'countryCode' => $originLabel->getCity(),
  175.             'StartDate' =>  $date1,
  176.             'EndDate' =>  $date2,
  177.             'Rooms' => $rooms,
  178.             'Destination' => $destinationLabel->getCity(),
  179.             'Nights' => (strtotime($date1) - strtotime($date2)) / 86400,
  180.         ];
  181.         for ($i 1$i <= $rooms; ++$i) {
  182.             ${'countAdults'.$i} = 0;
  183.             ${'countChildren'.$i} = 0;
  184.             $childrens = [];
  185.             if ('n' != ${'child'.$i}) {
  186.                 ${'child'.$i.'Ages'} = array_filter(explode('-', ${'child'.$i}));
  187.                 if (== $i) {
  188.                     $childAgesCookie = [
  189.                         'age'.$i => ${'child'.$i.'Ages'},
  190.                     ];
  191.                 }
  192.                 ${'child'.$i.'Size'} = is_countable(${'child'.$i.'Ages'}) ? count(${'child'.$i.'Ages'}) : 0;
  193.                 foreach (${'child'.$i.'Ages'} as $age) {
  194.                     $childrens[] = $age;
  195.                     ++${'countChildren'.$i};
  196.                     ++$countChildren;
  197.                 }
  198.             }
  199.             $countAdults $countAdults + ${'adult'.$i};
  200.             $services[] = ['adults' => ${'adult'.$i}, 'childrens' => $childrens];
  201.             $AvailabilityArray[$i] = [];
  202.             $AvailabilityArray[$i]['Children'] = ${'countChildren'.$i};
  203.             $AvailabilityArray[$i]['Adults'] = ${'adult'.$i};
  204.         }
  205.         $cookieLastSearch $searchFlightCookie->searchFlightCookie(['flight' => base64_encode(json_encode($AvailabilityArray))]);
  206.         $AvailabilityArray['Children'] = $countChildren;
  207.         $AvailabilityArray['Adults'] = $countAdults;
  208.         $AvailabilityArray['Rooms'] = 1;
  209.         $ages explode('-'$child1);
  210.         for ($j 0$j sizeof($ages); ++$j) {
  211.             $cookieLastSearch['childAge'][$j] = $ages[$j];
  212.         }
  213.         $transactionIdResponse $aviaturWebService->loginService('SERVICIO_MPT''dummy|http://www.aviatur.com.co/dummy/', []);
  214.         if ('error' == $transactionIdResponse || is_array($transactionIdResponse)) {
  215.             $aviaturErrorHandler->errorRedirect('''Error MPA''No se creó Login!');
  216.             return new Response('Estamos experimentando dificultades técnicas en este momento.');
  217.         }
  218.         $ajaxMultiFlightUrl .= (sizeof($optionalArray) > '&' '?').'transactionMulti='.base64_encode($transactionIdResponse);
  219.         $ajaxMultiHotelUrl .= '?transactionMulti='.base64_encode($transactionIdResponse);
  220.         // RENDER VIEW
  221.         $agencyFolder $twigFolder->twigFlux();
  222.          $view $twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Multi/Default/results.html.twig');
  223.         $seoUrl $em->getRepository(\Aviatur\GeneralBundle\Entity\SeoUrl::class)->findByUrlorMaskedUrl($ajaxMultiFlightUrl);
  224.         $urlDescription['long'] = null != $seoUrl $seoUrl[0]->getDescription() : '';
  225.         $urlDescription['short'] = null != $seoUrl $seoUrl[0]->getShortdescription() : '';
  226.         $seoMaskedUrl $em->getRepository(\Aviatur\GeneralBundle\Entity\SeoUrl::class)->findByUrlorMaskedUrl($requestUrl);
  227.         $urlDescription['url'] = null != $seoMaskedUrl '/'.$seoMaskedUrl[0]->getUrl() : $requestUrl;
  228.         $pixelInfo = [];
  229.         if (!$session->has('operatorId')) {
  230.             // PIXELES INFORMATION
  231.             $pixel['partner_datalayer']['flight'] = [
  232.                 'enabled' => true,
  233.                 'event' => 'paquete_search',
  234.                 'dimension1' => $destination1,
  235.                 'dimension2' => $origin1,
  236.                 'dimension3' => $date1,
  237.                 'dimension4' => $date2 ?? '',
  238.                 'dimension5' => 'Hotel+Vuelo',
  239.                 'dimension6' => '',
  240.                 'dimension7' => isset($destination1) ? 'RoundTrip' 'OneWay',
  241.                 'dimension8' => 'economy',
  242.                 'dimension9' => '',
  243.                 'dimension10' => ((int) $adult1 + (int) $adult2 + (int) $adult3 + (int) $child1 + (int) $child2 + (int) $child3),
  244.                 'dimension11' => '',
  245.                 'dimension12' => 'Busqueda-PaqueteVuelos',
  246.                 'ecommerce' => [
  247.                     'currencyCode' => 'COP',
  248.                 ],
  249.             ];
  250.             $pixel['partner_datalayer']['hotel'] = [
  251.                 'enabled' => true,
  252.                 'event' => 'paquete_search',
  253.                 'dimension1' => $destination1,
  254.                 'dimension2' => '',
  255.                 'dimension3' => $date1,
  256.                 'dimension4' => $date2,
  257.                 'dimension5' => 'Hotel+Vuelo',
  258.                 'dimension6' => '',
  259.                 'dimension7' => '',
  260.                 'dimension8' => '',
  261.                 'dimension9' => '',
  262.                 'dimension10' => ((int) $adult1 + (int) $child1 + (int) $adult2 + (int) $child2 + (int) $adult3 + (int) $child3),
  263.                 'dimension11' => $rooms,
  264.                 'dimension12' => 'Busqueda-PaqueteHotel',
  265.                 'ecommerce' => [
  266.                     'currencyCode' => 'COP',
  267.                 ],
  268.             ];
  269.             $pixelInfo $aviaturPixeles->verifyPixeles($pixel'multi''availability'$agency->getAssetsFolder(), false);
  270.         }
  271.         $parameters json_decode($session->get($request->getHost().'[parameters]'));
  272.         $currentDate date('Y-m-d');
  273.         $endDateCensocud $parameters->date_end_cencosud;
  274.         $activeCheckCencosud = (strtotime($endDateCensocud) >= strtotime($currentDate));
  275.         $hotelUrl $urlService->generateUrlFromIata($destination1$date1$date2, (int) $adult10);
  276.         $roomsToConsult $urlService->urlToRoomsArray($hotelUrl);
  277.         $coordinates $urlService->getCoordinatesByIata($destination1);
  278.         $jsonHotelAvail $urlService->jsonHotelAvailability($date1$date2strtoupper($destinationLabel->getIata()), 'MX'$coordinates['latitude'], $coordinates['longitude'], "10"$roomsToConsult$transactionIdResponse);
  279.         $response $this->render($view, [
  280.             'availabilityFront' => $session->has('operatorId'),
  281.             'ajaxMultiUrl' => $requestUrl,
  282.             'ajaxMultiFlightUrl' => $ajaxMultiFlightUrl,
  283.             'ajaxMultiHotelUrl' => $ajaxMultiHotelUrl,
  284.             'ajaxParameters' => base64_encode(json_encode($jsonHotelAvail)),
  285.             'countrycode' => $destinationLabel->getCountrycode(),
  286.             'checkin' => $date1,
  287.             'checkout' => $date2,
  288.             'roomsconsulturl' => 'rooms',
  289.             'availableArrayHotel' => $AvailabilityArray,
  290.             'cityName' => $destinationLabel->getCity(),
  291.             'isAval' => $this->isAval,
  292.             'safeUrl' => $safeUrl,
  293.             'urlDescription' => $urlDescription,
  294.             'AvailabilityArray' => $AvailabilityArray,
  295.             'cityOriginName' => $originLabel->getCity(),
  296.             'cityDestinationName' => $destinationLabel->getCity(),
  297.             'flights' => $flights,
  298.             'inlineEngine' => true,
  299.             // 'cookieLastSearch' => $cookieLastSearch,
  300.             'pixel_info' => $pixelInfo,
  301.             'activeCheckCencosud' => $activeCheckCencosud,
  302.             'online' => 'online'
  303.         ]);
  304.         return $response;
  305.     }
  306.     public function resultsDetailAction(Request $requestSessionInterface $sessionAviaturLogSave $aviaturLogSaveParameterBagInterface $parameterBagAviaturPixeles $aviaturPixelesAuthorizationCheckerInterface $authorizationCheckerManagerRegistry $registryRouterInterface $routerAviaturErrorHandler $aviaturErrorHandlerTwigFolder $twigFolderAviaturWebService $webService) {
  307.         
  308.         $transactionIdSessionName $parameterBag->get('transaction_id_session_name');
  309.         $responseFlightDetail = [];
  310.         $fullRequest null;
  311.         $isAgent false;
  312.         $currentRequest=$request;
  313.         $parameters json_decode($session->get($request->getHost().'[parameters]'));
  314.         $webService->setUrls($parameters);
  315.         $request $request->request;
  316.         $currentRoute$currentRequest->get('_route') ?? $request->get('_route');
  317.         $routeType explode('_'$currentRoute);
  318.         $transactionId $session->get($transactionIdSessionName);
  319.         $returnUrl $twigFolder->pathWithLocale('aviatur_general_homepage');
  320.         if ((is_countable($request->get('RPH')) ? count($request->get('RPH')) : 0) < 2) {
  321.             $message $responseFlightDetail['error'] ?? 'No se ha recibido la información completa para consultar el detalle de tus vuelos.';
  322.             if (true === $session->has($transactionId.'[availability_url]')) {
  323.                 $returnUrl $session->get($transactionId.'[availability_url]');
  324.             }
  325.             return $this->redirect($aviaturErrorHandler->errorRedirect($returnUrl''$message));
  326.         }
  327.         
  328.         if ($authorizationChecker->isGranted('ROLE_AVIATUR_ADMIN_ADMIN_AGENT_OPERATOR') || $authorizationChecker->isGranted('ROLE_AVIATUR_ADMIN_ADMIN_AGENT_WAITING')) {
  329.             $user $this->getUser();
  330.             $agent $user->getAgent();
  331.             if (!empty($agent[0]) && $agent[0]->getAgency()->getId() === $this->agency->getId()) {
  332.                 $isAgent true;
  333.             }
  334.         }
  335.         // Generate Flight Detail
  336.         $route $router->match($this->generateUrl('aviatur_flight_'.$routeType[3].'_secure'));
  337.         $responseFlightDetail $this->generateFlightDetail($route$twigFolder$request$aviaturErrorHandler);
  338.         if ($responseFlightDetail instanceof RedirectResponse) {
  339.             return $responseFlightDetail;
  340.         }
  341.         if ('error' == $responseFlightDetail || (is_object($responseFlightDetail) && method_exists($responseFlightDetail'getStatusCode') && $responseFlightDetail->getStatusCode() === 500)) {
  342.             return $this->redirect($aviaturErrorHandler->errorRedirect($twigFolder->pathWithLocale('aviatur_general_homepage'), '''No se encontró información de la transacción'));
  343.         }
  344.         // Generate Hotel Detail
  345.         $responseHotelDetail $this->generateHotelDetail(
  346.             $request->get('rooms'),
  347.             $request->get('hotelcode'),
  348.             $request->get('checkIn'),
  349.             $request->get('checkOut'),
  350.             $request->get('providerid'),
  351.             $request->get('countrycode')
  352.         );
  353.         if ($responseHotelDetail instanceof RedirectResponse) {
  354.             return $responseHotelDetail;
  355.         } 
  356.         if(empty($responseHotelDetail['info'])) {
  357.             return $this->redirect($aviaturErrorHandler->errorRedirectNoEmail($returnUrl'''Ha ocurrido un error inesperado'));
  358.         }
  359.         $detailFlightJson json_encode($responseFlightDetailJSON_PRETTY_PRINT);
  360.         $compressedDetailFlight base64_encode(gzcompress($detailFlightJson));
  361.         // Generate Multi Detail
  362.         $responseMultiDetail $responseHotelDetail;
  363.         $responseMultiDetail += [
  364.             'detailFlight' => $responseFlightDetail,
  365.             'hotelProvidersId' => $responseHotelDetail["info"]["providers"][0],
  366.             'compressedDetailFlight' => $compressedDetailFlight
  367.         ];
  368.         $agencyFolder $twigFolder->twigFlux();
  369.         //$view = $twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/FlightHotel/roomlistIndex.html.twig');
  370.         $view $twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/Hotel/Default/roomlist.html.twig');
  371.         if (isset($responseMultiDetail['resume_info']['fee_type'])) {
  372.             $responseMultiDetail['resume_info']['fee_type'] = implode(','$responseMultiDetail['resume_info']['fee_type']);
  373.         }
  374.         $iinRecordsArray $this->getIINRanges($this->em);
  375.         $responseMultiDetail["ccranges"] = $iinRecordsArray["ccranges"];
  376.         $responseMultiDetail["ccfranchises"] = $iinRecordsArray["ccfranchises"];
  377.         return $this->render($view$responseMultiDetail);
  378.     }
  379.     public function generateFlightDetail(array $routeTwigFolder $twigFolder$requestAviaturErrorHandler $aviaturErrorHandler) {
  380.         $responseFlightDetailForward $this->forward($route['_controller'], $route);
  381.         $xmlFlightDetail = new \SimpleXMLElement('<?xml version="1.0"?><info></info>');
  382.         $responseFlightDetail json_decode($responseFlightDetailForward->getContent(), true);
  383.         if (null == $responseFlightDetail) {
  384.             return $responseFlightDetailForward;
  385.         }
  386.         if (isset($responseFlightDetail['error'])) {
  387.             $message $responseFlightDetail['error'] ?? 'Ha ocurrido un error inesperado';
  388.             $returnUrl $twigFolder->pathWithLocale('aviatur_general_homepage');
  389.             if (true === $request->has('referer')) {
  390.                 $returnUrl $request->get('http_referer');
  391.             }
  392.             if (isset($responseFlightDetail['no_message']) && (true == $responseFlightDetail['no_message'])) {
  393.                 return $this->redirect($aviaturErrorHandler->errorRedirectNoEmail($returnUrl''$message));
  394.             } else {
  395.                 return $this->redirect($aviaturErrorHandler->errorRedirect($returnUrl''$message));
  396.             }
  397.         }
  398.         // Convertir los segmentos y sus itinerarios a arrays
  399.         foreach ($responseFlightDetail['segments'] as $key => $segment) {
  400.             foreach ($segment['itinerary'] as $key1 => $flight) {
  401.                 $responseFlightDetail['segments'][$key]['itinerary'][$key1] = $this->simpleXmlToArray($flight);
  402.             }
  403.         }
  404.         $documentType $this->em->getRepository(\Aviatur\CustomerBundle\Entity\DocumentType::class)->findAll();
  405.         $genderType $this->em->getRepository(\Aviatur\CustomerBundle\Entity\Gender::class)->findAll();
  406.         $repositoryDocumentType $this->em->getRepository(\Aviatur\CustomerBundle\Entity\DocumentType::class);
  407.         $queryDocumentType $repositoryDocumentType
  408.                 ->createQueryBuilder('p')
  409.                 ->where('p.paymentcode != :paymentcode')
  410.                 ->setParameter('paymentcode''')
  411.                 ->getQuery();
  412.         
  413.         $documentPaymentType $queryDocumentType->getResult();
  414.         $banks = [];
  415.         if (in_array('pse'$responseFlightDetail['paymentOptions'])) {
  416.             $banks $this->em->getRepository(\Aviatur\PaymentBundle\Entity\PseBank::class)->findAll();
  417.         }
  418.         if (array_search('safety'$responseFlightDetail['paymentOptions'])) {
  419.             unset($responseFlightDetail['paymentOptions'][array_search('safety'$responseFlightDetail['paymentOptions'])]);
  420.         }
  421.         if (array_search('baloto'$responseFlightDetail['paymentOptions'])) {
  422.             unset($responseFlightDetail['paymentOptions'][array_search('baloto'$responseFlightDetail['paymentOptions'])]);
  423.         }
  424.         $today date('Y-m-d');
  425.         $diffDays = (strtotime($responseFlightDetail['destination_array'][0]['DateTime']) - strtotime($today)) / 86400;
  426.         if ($diffDays 0) {
  427.             $responseFlightDetail['baloto'] = true;
  428.         }
  429.         $responseFlightDetail['baloto'] ?? ($responseFlightDetail['baloto'] = false);
  430.         foreach ($responseFlightDetail['providersName'] as $providerName) {
  431.             if (('Kiu' == $providerName)) {
  432.                 $responseFlightDetail['baloto'] = false;
  433.             }
  434.         }
  435.         $conditions $this->em->getRepository(\Aviatur\GeneralBundle\Entity\HistoricalInfo::class)->findMessageByAgencyOrNull($this->agency'reservation_conditions');
  436.         unset($responseFlightDetail['doc_type'], $responseFlightDetail['gender'], $responseFlightDetail['payment_doc_type'], $responseFlightDetail['cards'], $responseFlightDetail['inactiveCards'], $responseFlightDetail['banks'], $responseFlightDetail['conditions']);
  437.         $responseFlightDetail += [
  438.             'doc_type' => $documentType,
  439.             'gender' => $genderType,
  440.             'payment_doc_type' => $documentPaymentType,
  441.             'cards' => $this->em->getRepository(\Aviatur\GeneralBundle\Entity\Card::class)->findBy(['isactive' => 1]),
  442.             'inactiveCards' => $this->em->getRepository(\Aviatur\GeneralBundle\Entity\Card::class)->findBy(['isactive' => 0]),
  443.             'banks' => $banks,
  444.             'conditions' => $conditions,
  445.         ];
  446.         return $responseFlightDetail;
  447.     }
  448.     public function generateHotelDetail($rooms$hotelcode$checkIn$checkOut$providerid$countrycode) {
  449.         $response $this->forward('Aviatur\HotelBundle\Controller\HotelRestController::roomListAction',
  450.             [
  451.                 'hotelcode'   => $hotelcode,
  452.                 'providerid'  => $providerid,
  453.                 'checkIn'     => $checkIn,
  454.                 'checkOut'    => $checkOut,
  455.                 'rooms'       => $rooms,
  456.                 'countrycode' => $countrycode,
  457.                 'isFlightHotel' => true
  458.             ]
  459.         );
  460.         $data json_decode($response->getContent(), true);
  461.         
  462.         return $data;
  463.     }
  464.     public function checkoutAction(Request $request, \Swift_Mailer $mailerParameterBagInterface $parameterBagTwigFolder $twigFolderSessionInterface $sessionAviaturErrorHandler $aviaturErrorHandlerRouterInterface $routerAviaturWebService $aviaturWebService) {
  465.     
  466.         // Obtener checkout de hoteles
  467.         $responseDetailHotel $this->forward('Aviatur\HotelBundle\Controller\HotelRestController::checkoutAction', [
  468.             'request' => $request,
  469.             'parameterBag' => $parameterBag,
  470.             'twigFolder' => $twigFolder,
  471.             'session' => $session,
  472.             'aviaturErrorHandler' => $aviaturErrorHandler,
  473.             'router' => $router,
  474.             'aviaturWebService' => $aviaturWebService,
  475.             'isFlightHotel' => true
  476.         ]);
  477.         $responseCheckout json_decode($responseDetailHotel->getContent(), true);
  478.         if (isset($responseCheckout['error'])) {
  479.             $message $responseCheckout['error'] ?? 'Ha ocurrido un error inesperado';
  480.             $returnUrl $twigFolder->pathWithLocale('aviatur_general_homepage');
  481.             if (true === $request->has('referer')) {
  482.                 $returnUrl $request->get('http_referer');
  483.             }
  484.             if (isset($responseCheckout['no_message']) && (true == $responseCheckout['no_message'])) {
  485.                 return $this->redirect($aviaturErrorHandler->errorRedirectNoEmail($returnUrl''$message));
  486.             } else {
  487.                 return $this->redirect($aviaturErrorHandler->errorRedirect($returnUrl''$message));
  488.             }
  489.         }
  490.         $compressedDetailFlight  $request->request->get("flightDetail");
  491.         $detailFlightJson = \gzuncompress(base64_decode($compressedDetailFlight));
  492.         $flightDetail json_decode($detailFlightJsontrue);
  493.         $xmlData = new \SimpleXMLElement('<?xml version="1.0"?><root></root>');
  494.         // Convertir los segmentos y sus itinerarios a SimpleXMLElement
  495.         foreach ($flightDetail['segments'] as $key => $segment) {
  496.             foreach ($segment['itinerary'] as $key1 => $itinerary) {
  497.                 $xmlData = new \SimpleXMLElement('<?xml version="1.0"?><itinerary></itinerary>');
  498.                 $this->array_to_xml($itinerary$xmlData);
  499.                 $flightDetail['segments'][$key]['itinerary'][$key1] = $xmlData;
  500.             }
  501.         }
  502.         // hoteles
  503.         $cards $this->em->getRepository(\Aviatur\GeneralBundle\Entity\Card::class)->findBy(['isactive' => 1]);
  504.         $repositoryDocumentType $this->em->getRepository(\Aviatur\CustomerBundle\Entity\DocumentType::class);
  505.         $queryDocumentType $repositoryDocumentType
  506.             ->createQueryBuilder('p')
  507.             ->where('p.paymentcode != :paymentcode')
  508.             ->setParameter('paymentcode''')
  509.             ->getQuery();
  510.         $documentPaymentType $queryDocumentType->getResult();
  511.         $typeDocument $this->em->getRepository(\Aviatur\CustomerBundle\Entity\DocumentType::class)->findAll();
  512.         $typeGender $this->em->getRepository(\Aviatur\CustomerBundle\Entity\Gender::class)->findAll();
  513.         $inactiveCards $this->em->getRepository(\Aviatur\GeneralBundle\Entity\Card::class)->findBy(['isactive' => 0]);
  514.         // Hoteles
  515.         $responseCheckout['cards'] = $cards;
  516.         $responseCheckout['payment_doc_type'] = $documentPaymentType;
  517.         $responseCheckout['doc_type'] = $typeDocument;
  518.         $responseCheckout['gender'] = $typeGender;
  519.         $responseCheckout['checkoutHoteles'] = $request->request->get("HT");
  520.         //Se toma los pasajero de vuelos
  521.         $responseCheckout['services'] = $flightDetail['services'];
  522.         // Vuelos
  523.         $responseCheckout["flightDetail"] = $flightDetail;
  524.         $responseCheckout["flightDetail"]['cards'] = $cards;
  525.         $responseCheckout["flightDetail"]['payment_doc_type'] = $documentPaymentType;
  526.         $responseCheckout["flightDetail"]['doc_type'] = $typeDocument;
  527.         $responseCheckout["flightDetail"]['gender'] = $typeGender;
  528.         $responseCheckout["flightDetail"]['inactiveCards'] = $inactiveCards;
  529.         $responseCheckout["isMulti"] = true;
  530.         $agencyFolder $twigFolder->twigFlux();
  531.         $view $twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/FlightHotel/checkoutIndex.html.twig');
  532.         return $this->render($view$responseCheckout);
  533.     }
  534.     public function prePaymentStep1Action(Request $requestRouterInterface $routerSessionInterface $sessionAviaturErrorHandler $aviaturErrorHandler) {
  535.         if ($request->isXmlHttpRequest()) {
  536.             $routeHotel $router->match($this->generateUrl('aviatur_hotel_prepayment_step_1_secureN'));
  537.             $responseHotel $this->forward($routeHotel['_controller'], $routeHotel);
  538.             $responseHotelData json_decode($responseHotel->getContent(), true);
  539.             if (isset($responseHotelData['error'])) {
  540.                 return $this->json($responseHotelData);
  541.             }
  542.             return $this->json([
  543.                 'hotel' => $responseHotelData,
  544.                 'ajax_url' => $this->generateUrl('aviatur_multi_prepayment_step_2_secureN'),
  545.             ]);
  546.         }
  547.         return $this->redirect($aviaturErrorHandler->errorRedirect(
  548.             $this->generateUrl('aviatur_general_homepage'),
  549.             '',
  550.             'Acceso no autorizado'
  551.         ));
  552.     }
  553.     public function prePaymentStep2Action(Request $requestRouterInterface $router) {
  554.         if ($request->isXmlHttpRequest()) {
  555.             $routeFlight $router->match($this->generateUrl('aviatur_flight_prepayment_step_1_secure'));
  556.             $responseFlight $this->forward($routeFlight['_controller'], $routeFlight);
  557.             $responseFlightData json_decode($responseFlight->getContent(), true);
  558.             if (isset($responseFlightData['error'])) {
  559.                 return $this->json($responseFlightData);
  560.             }
  561.             $routeHotel $router->match($this->generateUrl('aviatur_hotel_prepayment_step_2_secureN'));
  562.             $responseHotel $this->forward($routeHotel['_controller'], $routeHotel);
  563.             $responseHotelData json_decode($responseHotel->getContent(), true);
  564.  
  565.             if (isset($responseHotelData['error'])) {
  566.                 return $this->json($responseHotelData);
  567.             }
  568.             return $this->json([
  569.                 'hotel' => $responseHotelData,
  570.                 'flight' => $responseFlightData,
  571.                 'ajax_url' => $this->generateUrl('aviatur_multi_prepayment_step_3_secureN'),
  572.             ]);
  573.         }
  574.     }
  575.     public function prePaymentStep3Action(Request $requestSessionInterface $sessionRouterInterface $router) {
  576.         if ($request->isXmlHttpRequest()) {
  577.             $routeFlight $router->match($this->generateUrl('aviatur_flight_prepayment_step_2_secure'));
  578.             $responseFlightPrepayment2Forward $this->forward($routeFlight['_controller'], $routeFlight);
  579.             $responseFlightPrepayment2 json_decode($responseFlightPrepayment2Forward->getContent(), true);
  580.             if (null == $responseFlightPrepayment2) {
  581.                 var_dump($responseFlightPrepayment2Forward->getContent());
  582.             }
  583.             if (isset($responseFlightPrepayment2['error'])) {
  584.                 return $this->json($responseFlightPrepayment2);
  585.             }
  586.             $url 'aviatur_multi_payment_secureN';
  587.             $responseFlightPrepayment2['url'] = $this->generateUrl($url);
  588.             return $this->json($responseFlightPrepayment2);
  589.         }
  590.     }
  591.     public function paymentAction(Request $requestParameterBagInterface $parameterBagRouterInterface $routerSessionInterface $sessionAviaturErrorHandler $aviaturErrorHandler) {
  592.         $transactionIdSessionName $parameterBag->get('transaction_id_session_name');
  593.         $transactionId $session->get($transactionIdSessionName);
  594.         $postData json_decode($session->get($transactionId.'[flight][detail_data_flight]'));
  595.         $paymentData $postData->PD;
  596.         $routeFlight $router->match($this->generateUrl('aviatur_flight_payment_secure'));
  597.         $responseFlight $this->forward($routeFlight['_controller'], $routeFlight);
  598.         $responseFlightData json_decode($responseFlight->getContent(), true);
  599.         if (isset($responseFlightData['error'])) {
  600.             return $this->json($responseFlightData);
  601.         }
  602.         $routeHotel $router->match($this->generateUrl('aviatur_hotel_payment_secureN'));
  603.         $responseHotel $this->forward($routeHotel['_controller'], $routeHotel);
  604.         $responseHotelData json_decode($responseHotel->getContent(), true);
  605.         if (isset($responseHotelData['error'])) {
  606.             return $this->json($responseHotelData);
  607.         }
  608.         if ('p2p' == $paymentData->type) {
  609.             return $this->redirect($this->generateUrl('aviatur_multi_payment_p2p_return_url_secureN', [], true));
  610.         } else {
  611.             $session->set('redirectedRetry'true);
  612.             return $this->redirect($aviaturErrorHandler->errorRedirect($this->generateUrl('aviatur_multi_results_retry_secure'), '''El tipo de pago es inválido'));
  613.         }
  614.     }
  615.     public function p2pCallbackAction(SessionInterface $sessionMultiHotelDiscount $multiHotelDiscountPayoutExtraService $aviaturPayoutExtraRouterInterface $routerManagerRegistry $registryParameterBagInterface $parameterBag) {
  616.         $transactionIdSessionName $parameterBag->get('transaction_id_session_name');
  617.         $agency $this->agency;
  618.         $transactionId $session->get($transactionIdSessionName);
  619.         $routeFlight $router->match($this->generateUrl('aviatur_flight_payment_p2p_return_url_secure'));
  620.         $responseFlightP2PCallbackForward $this->forward($routeFlight['_controller'], $routeFlight);
  621.         $responseFlightP2PCallback json_decode($responseFlightP2PCallbackForward->getContent(), true);
  622.         if (isset($responseFlightP2PCallback['error'])) {
  623.             return $this->json($responseFlightP2PCallback);
  624.         }
  625.         $routeHotel $router->match($this->generateUrl('aviatur_hotel_payment_p2p_return_url_secureN'));
  626.         $responseHotelP2PCallbackForward $this->forward($routeHotel['_controller'], $routeHotel);
  627.         $responseHotelP2PCallback json_decode($responseHotelP2PCallbackForward->getContent(), true);
  628.         if (isset($responseHotelP2PCallback['error'])) {
  629.             return $this->json($responseHotelP2PCallback);
  630.         }
  631.         $responseFlight $router->match($responseFlightP2PCallbackForward->getTargetUrl());
  632.         $responseHotel $router->match($responseHotelP2PCallbackForward->getTargetUrl());
  633.         $responseFlightArray explode('_'$responseFlight['_route']);
  634.         $responseHotelArray explode('_'$responseHotel['_route']);
  635.         $responsePreference = ['success' => 1'rejected' => 2'pending' => 3'error' => 4];
  636.         if ($responsePreference[$responseFlightArray[3]] > $responsePreference[$responseHotelArray[3]]) {
  637.             $responseTwig 'aviatur_multi_results_payment_'.$responseFlightArray[3].'_secure';
  638.         } else {
  639.             $responseTwig 'aviatur_multi_results_payment_'.$responseHotelArray[3].'_secure';
  640.         }
  641.         // $aviaturPayoutExtra->payoutExtrasCallback($responseTwig, $transactionId, 'multi_1', $agency);
  642.         // if ('success' === $responseHotelArray[3]) {
  643.         //     $roomRateDiscount = $multiHotelDiscount->updateHotelReservationDiscount();
  644.         // }
  645.         return $this->redirect($this->generateUrl($responseTwig, [], true));
  646.     }
  647.     public function paymentOutputAction(Request $requestSessionInterface $session, \Swift_Mailer $mailerAviaturPixeles $aviaturPixelesPdf $pdfTwigFolder $twigFolderManagerRegistry $registryRouterInterface $routerParameterBagInterface $parameterBagExceptionLog $exceptionLog) {
  648.         $projectDir $parameterBag->get('kernel.project_dir');
  649.         $transactionIdSessionName $parameterBag->get('transaction_id_session_name');
  650.         $emailNotification $parameterBag->get('email_notification');
  651.         $voucherFile null;
  652.         $transactionId $session->get($transactionIdSessionName);
  653.         $session->set($transactionId.'[multi]'.'[validation]'true);
  654.         $agency $this->agency;
  655.         
  656.         if ($session->has('operatorId')) {
  657.             $routeNameFlight 'aviatur_flight_reservation_success_secure';
  658.             $routeNameHotel 'aviatur_hotel_reservation_success_secure';
  659.         } else {
  660.             $routeName explode('_'$request->get('_route'));
  661.             $routeNameFlight 'aviatur_flight_payment_'.$routeName[4].'_secure';
  662.             $routeNameHotel $routeName[4] == 'success'
  663.                 'aviatur_hotel_reservation_'.$routeName[4].'_secureN' 
  664.                 'aviatur_hotel_payment_'.$routeName[4].'_secureN';
  665.         }
  666.         //Vuelos
  667.         $routeFlight $router->match($this->generateUrl($routeNameFlight));
  668.         $responseFlightPaymentOutputForward $this->forward($routeFlight['_controller'], $routeFlight);
  669.         $responseFlightPaymentOutput json_decode($responseFlightPaymentOutputForward->getContent(), true);
  670.         if (null == $responseFlightPaymentOutput) {
  671.             var_dump($responseFlightPaymentOutputForward->getContent());
  672.         }
  673.         if (isset($responseFlightPaymentOutput['error'])) {
  674.             return $this->json($responseFlightPaymentOutput);
  675.         }
  676.         //Hoteles
  677.         $routeHotel $router->match($this->generateUrl($routeNameHotel));
  678.         $responseHotelPaymentOutputForward $this->forward($routeHotel['_controller'], $routeHotel);
  679.         $responseHotelPaymentOutput json_decode($responseHotelPaymentOutputForward->getContent(), true);    
  680.         if (!isset($responseHotelPaymentOutput) || empty($responseHotelPaymentOutput)) {
  681.             var_dump($responseHotelPaymentOutputForward->getContent());
  682.         }
  683.         if (isset($responseHotelPaymentOutput['error'])) {
  684.             return $this->json($responseHotelPaymentOutput);
  685.         }
  686.         $responsePaymentOutput = [
  687.             'flightResumen' => $responseFlightPaymentOutput,
  688.             'hotelResumen' => $responseHotelPaymentOutput
  689.         ];
  690.         $this->sendEmailThankYouPageAction($routeNameFlight$routeNameHotel$responsePaymentOutput$mailer$session$twigFolder$parameterBag);
  691.         $agencyFolder $twigFolder->twigFlux();
  692.         $urlResume $twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/FlightHotel/thankYouPage.html.twig');
  693.         return $this->render($urlResume$responsePaymentOutput);
  694.     }
  695.    
  696.     public function sendEmailThankYouPageAction($routeNameFlight$routeNameHotel$responsePaymentOutput, \Swift_Mailer $mailerSessionInterface $sessionTwigFolder $twigFolderParameterBagInterface $parameterBag) {
  697.         $transactionIdSessionName $parameterBag->get('transaction_id_session_name');
  698.         $transactionId $session->get($transactionIdSessionName);
  699.         $postDataFlight json_decode($session->get($transactionId '[flight][detail_data_flight]'));
  700.         $postDataHotel json_decode($session->get($transactionId.'[hotel][detail_data_hotel]'));
  701.         $customerId $postDataFlight->BD->id ?? $postDataHotel->BD->id;
  702.         $customer $this->em->getRepository(\Aviatur\CustomerBundle\Entity\Customer::class)->find($customerId);
  703.         $bccMails = ['supervisorescallcenter@aviatur.com''notificacionessitioweb@aviatur.com'];
  704.         $setTo $customer->getEmail();
  705.         $agencyFolder $twigFolder->twigFlux();
  706.         $urlResume $twigFolder->twigExists('@AviaturTwig/'.$agencyFolder.'/FlightHotel/emailThankYou.html.twig');
  707.         $subjectPrefix $session->get('agencyShortName') . ' - ';
  708.         $emissionData $responsePaymentOutput["hotelResumen"]["emissionData"] ?? null;
  709.         $flightParts explode('_'$routeNameFlight);
  710.         $hotelParts explode('_'$routeNameHotel);
  711.         $flightStatus = isset($flightParts[3]) ? $flightParts[3] : null;
  712.         $hotelStatus = isset($hotelParts[3]) ? $hotelParts[3] : null;
  713.         $responsePreference = ['success' => 1'rejected' => 2'pending' => 3'error' => 4];
  714.         if ($flightStatus && $hotelStatus) {
  715.             $selectedStatus $responsePreference[$flightStatus] > $responsePreference[$hotelStatus] ? $hotelStatus $flightStatus;
  716.         } else {
  717.             $selectedStatus $flightStatus ?: $hotelStatus;
  718.         }
  719.         if ($emissionData === 'No Reservation') {
  720.             $selectedStatus 'rejected';
  721.         }
  722.         switch ($selectedStatus) {
  723.             case 'success':
  724.                 $setSubject 'Gracias por su compra';
  725.                 break;
  726.             case 'rejected':
  727.                 $setSubject 'Pago rechazado';
  728.                 break;
  729.             case 'pending':
  730.                 $setSubject 'Pago pendiente';
  731.                 break;
  732.             default:
  733.                 $setSubject 'Estado de la transacción';
  734.                 break;
  735.         }
  736.         $message = (new \Swift_Message())
  737.             ->setContentType('text/html')
  738.             ->setFrom($session->get('emailNoReply'))
  739.             ->setTo($setTo)
  740.             ->setBcc($bccMails)
  741.             ->setSubject($subjectPrefix $setSubject)
  742.             ->setBody($this->renderView($urlResume$responsePaymentOutput));
  743.         $mailer->send($message);
  744.         return true;
  745.     }
  746.    
  747.     public function getParamsInRequest(Request $fullRequest, array $searchParam): array {
  748.         $optionalArray = [];
  749.         foreach ($searchParam as $param) {
  750.             if ($fullRequest->query->has($param)) {
  751.                 $optionalArray[] = $param '=' $fullRequest->query->get($param);
  752.             }
  753.         }
  754.         return $optionalArray;
  755.     }
  756.     private function array_to_xml($info, &$xml_info) {
  757.         foreach ($info as $key => $value) {
  758.             if (is_array($value)) {
  759.                 if (!is_numeric($key)) {
  760.                     if ('@attributes' == $key) {
  761.                         foreach ($value as $attributeKey => $attribute) {
  762.                             $xml_info->addAttribute($attributeKey$attribute);
  763.                         }
  764.                     } else {
  765.                         foreach ($value as $key2 => $value2) {
  766.                             if (!is_numeric($key2)) {
  767.                                 $subnode $xml_info->addChild($key);
  768.                                 $this->array_to_xml($value$subnode);
  769.                                 break;
  770.                             } else {
  771.                                 if (!is_array($value2)) {
  772.                                     $subnode $xml_info->addChild($key$value2);
  773.                                 } else {
  774.                                     $subnode $xml_info->addChild($key);
  775.                                     $this->array_to_xml($value2$subnode);
  776.                                 }
  777.                             }
  778.                         }
  779.                     }
  780.                 } else {
  781.                     $subnode $xml_info->addChild('item'.$key);
  782.                     $this->array_to_xml($value$subnode);
  783.                 }
  784.             } else {
  785.                 $xml_info->addChild($keyhtmlspecialchars($value));
  786.             }
  787.         }
  788.     }
  789.     private function simpleXmlToArray($xml) {
  790.         $json json_encode($xml);
  791.         return json_decode($jsontrue);
  792.     }
  793.     public function getIINRanges($em) {
  794.         $iinRecords $em->getRepository(\Aviatur\GeneralBundle\Entity\Card::class)->findByActiveFranchises();
  795.         $iinRecordsArray = [];
  796.         $ccranges = [];
  797.         $ccfranchises = [];
  798.         foreach ($iinRecords as $key => $iinRecord) {
  799.             $paymentGatewayCode $iinRecord["paymentgatewaycode"];
  800.             $description $iinRecord["description"];
  801.             $description strtoupper(str_replace(' '''trim($description)));
  802.             $stringRanges $iinRecord["ranges"];
  803.             $ranges json_decode($stringRangestrue);
  804.             $stringLengths $iinRecord["lengths"];
  805.             $lengths json_decode($stringLengthstrue);
  806.             $luhn $iinRecord["luhn"];
  807.             $cvvDigits $iinRecord["cvvdigits"];
  808.             $tempLengths = [];
  809.             foreach ($lengths["lengths"] as $length) {
  810.                 $tempLengths[] = array(=> $length[0], => (isset($length[1]) ? $length[1] : $length[0]));
  811.             }
  812.             $tempRecordArrayFranchises = [];
  813.             $tempRecordArrayFranchises["code"] = $paymentGatewayCode;
  814.             $tempRecordArrayFranchises["codename"] = $description;
  815.             $tempRecordArrayFranchises["luhn"] = $luhn;
  816.             $tempRecordArrayFranchises["length"] = $tempLengths;
  817.             $tempRecordArrayFranchises["cvvd"] = $cvvDigits;
  818.             $ccfranchises[$paymentGatewayCode] = $tempRecordArrayFranchises;
  819.             foreach ($ranges["ranges"] as $range) {
  820.                 $tempRecordArrayRanges = [];
  821.                 $tempRecordArrayRanges["range"][0] = $range[0];
  822.                 $tempRecordArrayRanges["range"][1] = (isset($range[1]) ? $range[1] : $range[0]);
  823.                 $tempRecordArrayRanges["minimum"] = strlen($range[0]);
  824.                 $tempRecordArrayRanges["code"] = $paymentGatewayCode;
  825.                 $ccranges[] = $tempRecordArrayRanges;
  826.             }
  827.         }
  828.         $iinRecordsArray = array("ccranges" => $ccranges"ccfranchises" => $ccfranchises);
  829.         return $iinRecordsArray;
  830.     }
  831.     
  832. }