src/Controller/HomeController.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Actividad;
  4. use App\Entity\ActividadFoto;
  5. use App\Entity\ActividadI18n;
  6. use App\Entity\Bodega;
  7. use App\Entity\BodegaFoto;
  8. use App\Entity\BodegaI18n;
  9. use App\Entity\Dorigen;
  10. use App\Entity\DorigenFoto;
  11. use App\Entity\DorigenI18n;
  12. use App\Entity\Idioma;
  13. use App\Entity\Municipio;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\HttpFoundation\JsonResponse;
  19. use App\Entity\RelActividadTipo;
  20. use App\Entity\RelDorigenBodega;
  21. use App\Entity\TipoI18n;
  22. use App\Entity\Users;
  23. use App\Utils\RandomStringGenerator;
  24. use DateTime;
  25. class HomeController extends AbstractController
  26. {
  27.     /**
  28.      * @Route("/", name="home")
  29.      */
  30.     public function index(): Response
  31.     {
  32.         if(!$this->getUser()){
  33.             return $this->redirectToRoute('app_login');
  34.         }else{
  35.             $em $this->getDoctrine()->getManager();
  36.             
  37.             $filtros = ['estado' => 1];
  38.             $dos = [];
  39.             $bodegas = [];
  40.             if ($this->getUser()->getRolesString() == "ROLE_DO") {
  41.                 $filtros['dorigen'] = $this->getUser()->getDorigen()->getId();
  42.                 $bodegas $em->getRepository(Bodega::class)->findActivasByDorigen($this->getUser()->getDorigen()->getId());
  43.             } else if ($this->getUser()->getRolesString() == "ROLE_BODEGA") {
  44.                 $filtros['bodega'] = $this->getUser()->getBodega()->getId();
  45.                 $bodegas $em->getRepository(Bodega::class)->findActivasByBodega($this->getUser()->getBodega()->getId());
  46.             } else {
  47.                 $bodegas $em->getRepository(Bodega::class)->findBy($filtros);
  48.                 $dos $em->getRepository(Dorigen::class)->findBy($filtros);
  49.             }
  50.             $actividades $em->getRepository(Actividad::class)->findBy($filtros);
  51.             return $this->render('home/index.html.twig', [
  52.                 'controller_name' => 'HomeController',
  53.                 'user_name' => $this->getUser()->getName(),
  54.                 'user_dorigen' => $this->getUser()->getDorigen() ? $this->getUser()->getDorigen()->getId() : null,
  55.                 'user_bodega' => $this->getUser()->getBodega() ? $this->getUser()->getBodega()->getId() : null,
  56.                 'user_role' => $this->getUser()->getRolesString(),
  57.                 "total_actividades" => count($actividades),
  58.                 "total_bodegas" => count($bodegas),
  59.                 "total_dos" => count($dos)
  60.             ]);
  61.         }
  62.     }
  63.     /**
  64.      * @Route("/politica", name="politica")
  65.      */
  66.     public function politica(): Response
  67.     {
  68.         return $this->render('politicy/index.html.twig', []);
  69.     }
  70.     /**
  71.      * @Route("/termes", name="termes")
  72.      */
  73.     public function termes(): Response
  74.     {
  75.         return $this->render('terms/index.html.twig', []);
  76.     }
  77.     /**
  78.      *  @Route("/data_import/{tipo_import}", name="get_data_import", methods={"GET"})
  79.      */
  80.     public function DataImport(Request $request){
  81.        
  82.         $em $this->getDoctrine()->getManager();
  83.         $responseCode 200;
  84.         $lang 'es';
  85.         $langData $em->getRepository(Idioma::class)->findOneBy(['clave' => $lang]);
  86.         $langDataCA $em->getRepository(Idioma::class)->findOneBy(['clave' => 'ca']);
  87.         $tipo_import $request->get('tipo_import') ? $request->get('tipo_import') : 'actividad';
  88.         $customAlphabet '0123456789ABCDEF';
  89.         /** Load $inputFileName to a Spreadsheet Object  **/
  90.         $path $this->getParameter('kernel.project_dir');
  91.         $inputFileName $path.'/import/import.xlsx';
  92.         $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);
  93.         // Set initial alphabet.
  94.         $generator = new RandomStringGenerator($customAlphabet);
  95.         $tokenLength 32;
  96.         /* DO */
  97.         $dos = [];
  98.         $dosExist = [];
  99.         $dosExistCA = [];
  100.         $dosExistObject = [];
  101.         $dosData $em->getRepository(Dorigen::class)->findAllImport($langData->getId());
  102.         foreach( $dosData as $d )
  103.         {        
  104.             $dosExist[$d['url']] = ['id' => $d['id'], 'idI18n' => $d['idI18n']];
  105.         }
  106.         $dosDataCA $em->getRepository(Dorigen::class)->findAllImport($langDataCA->getId());
  107.         foreach( $dosDataCA as $dCA )
  108.         {        
  109.             $dosExistCA[$dCA['url']] = ['id' => $dCA['id'], 'idI18n' => $dCA['idI18n']];
  110.         }
  111.         $dosDataObjects $em->getRepository(Dorigen::class)->findAll();
  112.         foreach( $dosDataObjects as $do )
  113.         {        
  114.             $dosExistObject[$do->getId()] = $do;
  115.         }
  116.   
  117.         if($tipo_import == 'dorigen'){
  118.             $dosExistObjectI18n = [];
  119.             $dosExistObjectI18nCA = [];
  120.             $dosExistObjectFoto = [];
  121.             $dosDataObjectsI18n $em->getRepository(DorigenI18n::class)->findBy(['idioma' => $langData->getId()]);
  122.             foreach( $dosDataObjectsI18n as $doI18n )
  123.             {        
  124.                 $dosExistObjectI18n[$doI18n->getId()] = $doI18n;
  125.             }
  126.             $dosDataObjectsI18nCA $em->getRepository(DorigenI18n::class)->findBy(['idioma' => $langDataCA->getId()]);
  127.             foreach( $dosDataObjectsI18nCA as $doI18nCA )
  128.             {        
  129.                 $dosExistObjectI18nCA[$doI18nCA->getId()] = $doI18nCA;
  130.             }
  131.             $dosDataObjectsFoto $em->getRepository(DorigenFoto::class)->findAll();
  132.             foreach( $dosDataObjectsFoto as $doFoto )
  133.             {        
  134.                 $dosExistObjectFoto[$doFoto->getDorigen()->getId()] = isset($dosExistObjectFoto[$doFoto->getDorigen()->getId()]) ? $dosExistObjectFoto[$doFoto->getDorigen()->getId()] : [];
  135.                 $dosExistObjectFoto[$doFoto->getDorigen()->getId()][$doFoto->getFoto()] = $doFoto;
  136.             }
  137.     
  138.     
  139.     
  140.             $sheetData $spreadsheet->getSheet(1)->toArray();
  141.             $i=4;
  142.             unset($sheetData[0]);
  143.             unset($sheetData[1]);
  144.             unset($sheetData[2]);
  145.             
  146.             foreach( $sheetData as $t )
  147.             {      
  148.             if($t[0] ){
  149.                 $dorigen = new Dorigen();
  150.                 $dorigenI18n = new DorigenI18n();
  151.                 if(isset($dosExist[$t[5]])){
  152.                     $dorigen $dosExistObject[$dosExist[$t[5]]['id']];
  153.                     $dorigenI18n $dosExistObjectI18n[$dosExist[$t[5]]['idI18n']];
  154.                 } else {
  155.                     $token $generator->generate($tokenLength);
  156.                     $dorigen->setHashId($token);
  157.                 }
  158.                 $logo 'uploads/dorigen/img_do_'.$dorigen->getId().'_logo.png';
  159.                 if($t[6]){
  160.                     $url $t[6];
  161.                     //dd($this->curl_get_contents($url));
  162.                     file_put_contents($logo$this->curl_get_contents($url));
  163.                     
  164.                 } else {
  165.                     if(file_exists($logo)){
  166.                         unlink($logo);
  167.                     }
  168.                     $logo '';
  169.                 }
  170.                 $dorigen->setEstado(1);
  171.                 $dorigen->setLogo($logo);
  172.                 $dorigen->setUrlWeb($t[2] ? $t[2] : '');
  173.                 $dorigen->setUrlInstagram($t[3] ? $t[3] : '');
  174.                 $dorigen->setFechaCreacion(new DateTime());
  175.                 $em->persist($dorigen);
  176.                 $em->flush();
  177.                 /* imagenes 10,11,12,13 */
  178.                 for($x 10$x<=13;$x++){
  179.                     $img 'uploads/dorigen/img_do_'.$dorigen->getId().'_'.($x-9).'.jpg';
  180.                     if($t[$x]){
  181.                         $url $t[$x];
  182.                         file_put_contents($img$this->curl_get_contents($url));
  183.                         if(!isset($dosExistObjectFoto[$dorigen->getId()][$img])){
  184.                             $foto = new DorigenFoto();
  185.                             $foto->setDorigen($dorigen);
  186.                             $foto->setFoto($img);
  187.                             $foto->setDestacada($x-== 0);
  188.                             $foto->setFechaCreacion(new DateTime());
  189.                             $em->persist($foto);
  190.                         }
  191.                     } else {
  192.                         if(file_exists($img)){
  193.                             unlink($img);
  194.                         }
  195.                         if(isset($dosExistObjectFoto[$dorigen->getId()][$img])){
  196.                             $em->remove($dosExistObjectFoto[$dorigen->getId()][$img]);
  197.                         }
  198.                     }
  199.                 }
  200.                 $dorigenI18n->setDorigen($dorigen);
  201.                 $dorigenI18n->setIdioma($langData);
  202.                 $dorigenI18n->setNombre($t[0]);
  203.                 $dorigenI18n->setDescripcion($t[1] ? $t[1] : '');
  204.                 $dorigenI18n->setUrlSemantica($t[5] ? $t[5] : '');
  205.                 $dorigenI18n->setFechaCreacion(new DateTime());
  206.                 $em->persist($dorigenI18n);
  207.                 $dorigenI18nCA = new DorigenI18n();
  208.                 if(isset($dosExistCA[$t[5]])){
  209.                     $dorigenI18nCA $dosExistObjectI18nCA[$dosExistCA[$t[5]]['idI18n']];
  210.                 }
  211.                 $dorigenI18nCA->setDorigen($dorigen);
  212.                 $dorigenI18nCA->setIdioma($langDataCA);
  213.                 $dorigenI18nCA->setNombre($t[0]);
  214.                 $dorigenI18nCA->setDescripcion($t[1] ? $t[1] : '');
  215.                 $dorigenI18nCA->setUrlSemantica($t[5] ? $t[5] : '');
  216.                 $dorigenI18nCA->setFechaCreacion(new DateTime());
  217.                 $em->persist($dorigenI18nCA);
  218.                 $dos[] = [
  219.                 "i" => $i,
  220.                 't0'=> $dorigenI18n->getNombre(),
  221.                 ];
  222.             }
  223.             $i++;
  224.             }
  225.             // print_r($dos);
  226.             // die();
  227.         }
  228.         /* bodegas */
  229.         $bodegas = [];
  230.         $bodegasExist = [];
  231.         $bodegasExistCA = [];
  232.         $bodegasExistObject = [];
  233.         $bodegasData $em->getRepository(Bodega::class)->findAllImport($langData->getId());
  234.         foreach( $bodegasData as $b )
  235.         {        
  236.             $bodegasExist[$b['url']] = ['id' => $b['id'], 'idI18n' => $b['idI18n']];
  237.         }
  238.         $bodegasDataCA $em->getRepository(Bodega::class)->findAllImport($langDataCA->getId());
  239.         foreach( $bodegasDataCA as $bCA )
  240.         {        
  241.             $bodegasExistCA[$bCA['url']] = ['id' => $bCA['id'], 'idI18n' => $bCA['idI18n']];
  242.         }
  243.         $bodegasDataObjects $em->getRepository(Bodega::class)->findAll();
  244.         foreach( $bodegasDataObjects as $bo )
  245.         {        
  246.             $bodegasExistObject[$bo->getId()] = $bo;
  247.         }
  248.         if($tipo_import == 'bodega'){
  249.             $bodegasExistObjectI18n = [];
  250.             $bodegasExistObjectI18nCA = [];
  251.             $bodegasExistObjectFoto = [];
  252.             $bodegasDoExistObject = [];
  253.             
  254.             $bodegasDataObjectsI18n $em->getRepository(BodegaI18n::class)->findBy(['idioma' => $langData->getId()]);
  255.             foreach( $bodegasDataObjectsI18n as $boI18n )
  256.             {        
  257.                 $bodegasExistObjectI18n[$boI18n->getId()] = $boI18n;
  258.             }
  259.             $bodegasDataObjectsI18nCA $em->getRepository(BodegaI18n::class)->findBy(['idioma' => $langDataCA->getId()]);
  260.             foreach( $bodegasDataObjectsI18nCA as $boI18nCA )
  261.             {        
  262.                 $bodegasExistObjectI18nCA[$boI18nCA->getId()] = $boI18nCA;
  263.             }
  264.             $bodegasDataObjectsFoto $em->getRepository(BodegaFoto::class)->findAll();
  265.             foreach( $bodegasDataObjectsFoto as $boFoto )
  266.             {        
  267.                 $bodegasExistObjectFoto[$boFoto->getBodega()->getId()] = [];
  268.                 $bodegasExistObjectFoto[$boFoto->getBodega()->getId()][$boFoto->getFoto()] = $boFoto;
  269.             }
  270.             $bodegasDataObjectsDO $em->getRepository(RelDorigenBodega::class)->findAll();
  271.             foreach( $bodegasDataObjectsDO as $dob )
  272.             {        
  273.                 $bodegasDoExistObject[$dob->getBodega()->getId()] = isset($bodegasDoExistObject[$dob->getBodega()->getId()]) ? $bodegasDoExistObject[$dob->getBodega()->getId()] : [];
  274.                 $bodegasDoExistObject[$dob->getBodega()->getId()][$dob->getDorigen()->getId()] = $dob;
  275.             }
  276.             
  277.             $sheetData $spreadsheet->getSheet(2)->toArray();
  278.             $i=4;
  279.             unset($sheetData[0]);
  280.             unset($sheetData[1]);
  281.             unset($sheetData[2]);
  282.             foreach( $sheetData as $t )
  283.             {      
  284.             if($t[0] ){
  285.                 $bodega = new Bodega();
  286.                 $bodegaI18n = new BodegaI18n();
  287.                 $bodegaI18nCA = new BodegaI18n();
  288.                 if(isset($bodegasExist[$t[2]])){
  289.                     $bodega $bodegasExistObject[$bodegasExist[$t[2]]['id']];
  290.                     $bodegaI18n $bodegasExistObjectI18n[$bodegasExist[$t[2]]['idI18n']];
  291.                 } else {
  292.                     $token $generator->generate($tokenLength);
  293.                     $bodega->setHashId($token);
  294.                 }
  295.                 $logo 'uploads/bodega/img_bodega_'.$bodega->getId().'_logo.png';
  296.                 if($t[14]){
  297.                     $url $t[14];
  298.                     file_put_contents($logo$this->curl_get_contents($url));
  299.                     
  300.                 } else {
  301.                     if(file_exists($logo)){
  302.                         unlink($logo);
  303.                     }
  304.                     $logo '';
  305.                 }
  306.                 $bodega->setLogo($logo);
  307.                 $dorigen null;
  308.                 if(isset($dosExist[$t[0]])){
  309.                     $dorigen $dosExistObject[$dosExist[$t[0]]['id']];
  310.                 } else {
  311.                     echo "no existe la do";
  312.                     print_r($t[0]);
  313.                     die();
  314.                 }
  315.                 
  316.                 $bodega->setUrlWeb($t[3] ? $t[3] : '');
  317.                 $bodega->setEmailReserva($t[4] ? $t[4] : '');
  318.                 $bodega->setDireccion($t[7] ? $t[7] : '');
  319.                 $bodega->setCodigoPostal($t[8] ? $t[8] : '');
  320.                 $bodega->setPoblacion($t[9] ? $t[9] : '');
  321.                 $bodega->setTelefonoContacto($t[10] ? $t[10] : '');
  322.                 $bodega->setUrlInstagram($t[11] ? $t[11] : '');
  323.                 $bodega->setFechaCreacion(new DateTime());
  324.                 // mapa 13
  325.                 $googleMaps $t[13];
  326.                 $latitud=null;
  327.                 $longitud=null;
  328.                 if($googleMaps){
  329.                     $googleMaps substr($googleMapsstrpos($googleMaps'@')+1);
  330.                     $googleMaps substr($googleMaps0strpos($googleMaps'/data'));
  331.                     $arrayMaps explode(","$googleMaps);
  332.                     $latitud $arrayMaps[0];
  333.                     $longitud $arrayMaps[1];
  334.                 }
  335.                 $bodega->setLatitud($latitud);
  336.                 $bodega->setLongitud($longitud);
  337.                 $em->persist($bodega);
  338.                 $em->flush();
  339.                 //$bodega->setDorigen($dorigenI18n->getDorigen());
  340.                 $dorigenBodega = new RelDorigenBodega();
  341.                 if(isset($bodegasDoExistObject[$bodega->getId()][$dorigen->getId()])){
  342.                     $dorigenBodega $bodegasDoExistObject[$bodega->getId()][$dorigen->getId()];
  343.                 }
  344.                 $dorigenBodega->setBodega($bodega);
  345.                 $dorigenBodega->setDorigen($dorigen);
  346.                 $dorigenBodega->setFechaCreacion(new DateTime());
  347.                 $em->persist($dorigenBodega);
  348.                 
  349.                 // print_r($bodega->getId()); 
  350.                 // die();
  351.                 /* imagenes 17,18,19,20 */
  352.                 for($x 17$x<=20;$x++){
  353.                     $img 'uploads/bodega/img_bodega_'.$bodega->getId().'_'.($x-16).'.jpg';
  354.                     if($t[$x]){
  355.                         $url $t[$x];
  356.                         file_put_contents($img$this->curl_get_contents($url));
  357.                         if(!isset($bodegasExistObjectFoto[$bodega->getId()][$img])){
  358.                             $foto = new BodegaFoto();
  359.                             $foto->setBodega($bodega);
  360.                             $foto->setFoto($img);
  361.                             $foto->setDestacada($x-16 == 0);
  362.                             $foto->setFechaCreacion(new DateTime());
  363.                             $em->persist($foto);
  364.                         }
  365.                     } else {
  366.                         if(file_exists($img)){
  367.                             unlink($img);
  368.                         }
  369.                         if(isset($bodegasExistObjectFoto[$bodega->getId()][$img])){
  370.                             $em->remove($bodegasExistObjectFoto[$bodega->getId()][$img]);
  371.                         }
  372.                     }
  373.                 }
  374.                 $bodegaI18n->setBodega($bodega);
  375.                 $bodegaI18n->setIdioma($langData);
  376.                 $bodegaI18n->setNombre($t[1] ? $t[1] : '');
  377.                 $bodegaI18n->setDescripcion($t[12] ? $t[12] : '');
  378.                 $bodegaI18n->setUrlSemantica($t[2] ? $t[2] : '');
  379.                 $bodegaI18n->setFechaCreacion(new DateTime());
  380.                 $em->persist($bodegaI18n);
  381.                 if(isset($bodegasExistCA[$t[2]])){
  382.                     $bodegaI18nCA $bodegasExistObjectI18nCA[$bodegasExistCA[$t[2]]['idI18n']];
  383.                 } 
  384.                 $bodegaI18nCA->setBodega($bodega);
  385.                 $bodegaI18nCA->setIdioma($langDataCA);
  386.                 $bodegaI18nCA->setNombre($t[1] ? $t[1] : '');
  387.                 $bodegaI18nCA->setDescripcion($t[12] ? $t[12] : '');
  388.                 $bodegaI18nCA->setUrlSemantica($t[2] ? $t[2] : '');
  389.                 $bodegaI18nCA->setFechaCreacion(new DateTime());
  390.                 $em->persist($bodegaI18nCA);
  391.                     $bodegas[] = [
  392.                     "i" => $i,
  393.                     't0'=> $bodegaI18n->getNombre(),
  394.                     ];
  395.             }
  396.             $i++;
  397.             }
  398.             // print_r($bodegas);
  399.             // die();
  400.         }
  401.         
  402.         /* actividades */
  403.         $actividades = [];
  404.         if($tipo_import == 'actividad'){
  405.             $actividadesExist = [];
  406.             $actividadesExistObject = [];
  407.             $actividadesExistObjectI18n = [];
  408.             $actividadesExistObjectFoto = [];
  409.             $actividadesData $em->getRepository(Actividad::class)->findAllImport($langData->getId());
  410.             foreach( $actividadesData as $a )
  411.             {        
  412.                 $actividadesExist[$a['importRow']] = ['id' => $a['id'], 'idI18n' => $a['idI18n']];
  413.             }
  414.             $actividadesDataObjects $em->getRepository(Actividad::class)->findAll();
  415.             foreach( $actividadesDataObjects as $ao )
  416.             {        
  417.                 $actividadesExistObject[$ao->getId()] = $ao;
  418.             }
  419.             $actividadesDataObjectsI18n $em->getRepository(ActividadI18n::class)->findBy(['idioma' => $langData->getId()]);
  420.             foreach( $actividadesDataObjectsI18n as $aoI18n )
  421.             {        
  422.                 $actividadesExistObjectI18n[$aoI18n->getId()] = $aoI18n;
  423.             }
  424.             $actividadesDataObjectsFoto $em->getRepository(ActividadFoto::class)->findAll();
  425.             foreach( $actividadesDataObjectsFoto as $aoFoto )
  426.             {        
  427.                 $actividadesExistObjectFoto[$aoFoto->getActividad()->getId()] = isset($actividadesExistObjectFoto[$aoFoto->getActividad()->getId()]) ? $actividadesExistObjectFoto[$aoFoto->getActividad()->getId()] : [];
  428.                 $actividadesExistObjectFoto[$aoFoto->getActividad()->getId()][$aoFoto->getFoto()] = $aoFoto;
  429.             }
  430.             $tiposI18nData $em->getRepository(TipoI18n::class)->findAll();
  431.             $tipos = [];
  432.             foreach($tiposI18nData as $t){
  433.                 $tipos[$t->getUrlSemantica()] = $t->getTipo();
  434.             }
  435.             $relATData $em->getRepository(RelActividadTipo::class)->findAll();
  436.             $relAT = [];
  437.             foreach($relATData as $rat){
  438.                 $relAT[$rat->getActividad()->getId()] = [];
  439.                 $relAT[$rat->getActividad()->getId()][$rat->getTipo()->getId()] = $rat;
  440.             }
  441.             
  442.             $sheetData $spreadsheet->getSheet(3)->toArray();
  443.             $i=4;
  444.             unset($sheetData[0]);
  445.             unset($sheetData[1]);
  446.             unset($sheetData[2]);
  447.             foreach( $sheetData as $t )
  448.             {      
  449.             if($t[0] ){
  450.                 $actividad = new Actividad();
  451.                 $actividadI18n = new ActividadI18n();
  452.                 if(isset($actividadesExist[$i])){
  453.                     $actividad $actividadesExistObject[$actividadesExist[$i]['id']];
  454.                     $actividadI18n $actividadesExistObjectI18n[$actividadesExist[$i]['idI18n']];
  455.                 } else {
  456.                     $token $generator->generate($tokenLength);
  457.                     $actividad->setHashId($token);
  458.                 }
  459.                 $bodega null;
  460.                 if(isset($bodegasExist[$t[0]])){
  461.                     $bodega $bodegasExistObject[$bodegasExist[$t[0]]['id']];
  462.                 } else {
  463.                     echo "no existe la bodega";
  464.                     print_r($t[0]);
  465.                     die();
  466.                 }
  467.                 $actividad->setBodega($bodega);
  468.                 $actividad->setDireccion($bodega->getDireccion());
  469.                 $actividad->setLatitud($bodega->getLatitud());
  470.                 $actividad->setLongitud($bodega->getLongitud());
  471.                 $m $em->getRepository(Municipio::class)->findOneByNombre($bodega->getPoblacion());
  472.                 if($m){
  473.                     $actividad->setMunicipio($m);
  474.                 }
  475.                 $dorigen null;
  476.                 if(isset($dosExist[$t[1]])){
  477.                     $dorigen $dosExistObject[$dosExist[$t[1]]['id']];
  478.                 } else {
  479.                     echo "no existe la do";
  480.                     print_r($t[1]);
  481.                     die();
  482.                 }
  483.                 $actividad->setDorigen($dorigen);
  484.                 $actividad->setImportRow($i);
  485.                 $actividad->setDuracion($t[4] ? $t[4] : '');
  486.                 $actividad->setFechaCreacion(new DateTime());
  487.                 $em->persist($actividad);
  488.                 $em->flush();
  489.                 // TODO: PRECIOS INCORRECTOS
  490.                 // $precio = $em->getRepository(Precio::class)->findOneBy(['actividad' => $actividad->getId()]);
  491.                 // if(!$precio){
  492.                 //     $precio = new Precio();
  493.                 //     $precio->setActividad($actividad);
  494.                 //     $precio->setFechaCreacion(new DateTime());
  495.                 // }
  496.                 // $precio->setPrecio($t[5] ? $t[5] : 0);
  497.                 // $em->persist($precio);
  498.                 /* imagenes 17,18,19,20 */
  499.                 for($x 17$x<=20;$x++){
  500.                     $img 'uploads/actividad/img_actividad_'.$actividad->getId().'_'.($x-16).'.jpg';
  501.                     if($t[$x]){
  502.                         $url $t[$x];
  503.                         file_put_contents($img$this->curl_get_contents($url));
  504.                         if(!isset($actividadesExistObjectFoto[$actividad->getId()][$img])){
  505.                             $foto = new ActividadFoto();
  506.                             $foto->setActividad($actividad);
  507.                             $foto->setFoto($img);
  508.                             $foto->setDestacada($x-16 == 0);
  509.                             $foto->setFechaCreacion(new DateTime());
  510.                             $em->persist($foto);
  511.                         }
  512.                     } else {
  513.                         if(file_exists($img)){
  514.                             unlink($img);
  515.                         }
  516.                         if(isset($actividadesExistObjectFoto[$actividad->getId()][$img])){
  517.                             $em->remove($actividadesExistObjectFoto[$actividad->getId()][$img]);
  518.                         }
  519.                     }
  520.                 }
  521.                 $actividadI18n->setActividad($actividad);
  522.                 $actividadI18n->setIdioma($langData);
  523.                 $actividadI18n->setNombre($t[2] ? $t[2] : '');
  524.                 $actividadI18n->setDescripcion($t[3] ? $t[3] : '');
  525.                 $actividadI18n->setIncluye($t[7] ? $t[7] : '');
  526.                 $actividadI18n->setNoIncluye($t[8] ? $t[8] : '');
  527.                 $actividadI18n->setInfoAdicional($t[9] ? $t[9] : '');
  528.                 //$actividadI18n->setUrlSemantica(''); // crear
  529.                 if($t[2]){
  530.                     $actividadI18n->setUrlSemantica($this->semanticUrl($t[2]));
  531.                     // echo $t[2];
  532.                     // dd($this->semanticUrl($t[2]));
  533.                 
  534.                 $actividadI18n->setFechaCreacion(new DateTime());
  535.                 $em->persist($actividadI18n);
  536.                 if($t[13] && isset($tipos[$t[13]])){
  537.                     if(!isset($relAT[$actividad->getId()][$t[13]])){
  538.                         $newRAT = new RelActividadTipo();
  539.                         $newRAT->setActividad($actividad);
  540.                         $newRAT->setTipo($tipos[$t[13]]);
  541.                         $newRAT->setFechaCreacion(new DateTime());
  542.                         $em->persist($newRAT);
  543.                     }
  544.                 }
  545.                     $actividades[] = [
  546.                     "i" => $i,
  547.                     't0'=> $actividadI18n->getNombre(),
  548.                     ];
  549.                     // FALTAN DIAS
  550.                     // FALTAN HORAS
  551.                     // FALTAN IDIOMAS
  552.             }
  553.             $i++;
  554.             }
  555.             print_r($actividades);
  556.             die();
  557.         }
  558.         
  559.         $em->flush();
  560.           // Return JSON data
  561.           $response = new JsonResponse();
  562.           $response->setStatusCode($responseCode);
  563.           $response->setData([
  564.             "importadas" => $actividades,
  565.           ]);
  566.           return $response;
  567.   
  568.       }
  569.     public function curl_get_contents($url)
  570.     {
  571.       $ch curl_init();
  572.       curl_setopt($chCURLOPT_URL$url);
  573.       curl_setopt($chCURLOPT_RETURNTRANSFER1);
  574.       curl_setopt($chCURLOPT_FOLLOWLOCATION1);
  575.       $data curl_exec($ch);
  576.       curl_close($ch);
  577.       return $data;
  578.     }
  579.     public function semanticUrl($text){
  580.         $url=$text;
  581.         $url $this->stripAccents($url);
  582.         $url = (str_replace('&'""$url));
  583.         $url = (str_replace('"'"_"$url));
  584.         $url = (str_replace("'""_"$url));
  585.         $url = (str_replace(":"""$url));
  586.         $url = (str_replace("."""$url));
  587.         $url = (str_replace(","""$url));
  588.         $url = (str_replace(";"""$url));
  589.         $url = (str_replace("`""_"$url));
  590.         $url strtolower(str_replace(" ""_"$url));
  591.         $url preg_replace('/[^A-Za-z0-9\_]/'''$url);
  592.         return $url;
  593.     }
  594.     public function stripAccents($str) {
  595.         $a = array('Ñ','ñ''À''Á''Â''Ã''Ä''Å''Æ''Ç''È''É''Ê''Ë''Ì''Í''Î''Ï''Ð''Ñ''Ò''Ó''Ô''Õ''Ö''Ø''Ù''Ú''Û''Ü''Ý''ß''à''á''â''ã''ä''å''æ''ç''è''é''ê''ë''ì''í''î''ï''ñ''ò''ó''ô''õ''ö''ø''ù''ú''û''ü''ý''ÿ''Ā''ā''Ă''ă''Ą''ą''Ć''ć''Ĉ''ĉ''Ċ''ċ''Č''č''Ď''ď''Đ''đ''Ē''ē''Ĕ''ĕ''Ė''ė''Ę''ę''Ě''ě''Ĝ''ĝ''Ğ''ğ''Ġ''ġ''Ģ''ģ''Ĥ''ĥ''Ħ''ħ''Ĩ''ĩ''Ī''ī''Ĭ''ĭ''Į''į''İ''ı''IJ''ij''Ĵ''ĵ''Ķ''ķ''Ĺ''ĺ''Ļ''ļ''Ľ''ľ''Ŀ''ŀ''Ł''ł''Ń''ń''Ņ''ņ''Ň''ň''ʼn''Ō''ō''Ŏ''ŏ''Ő''ő''Œ''œ''Ŕ''ŕ''Ŗ''ŗ''Ř''ř''Ś''ś''Ŝ''ŝ''Ş''ş''Š''š''Ţ''ţ''Ť''ť''Ŧ''ŧ''Ũ''ũ''Ū''ū''Ŭ''ŭ''Ů''ů''Ű''ű''Ų''ų''Ŵ''ŵ''Ŷ''ŷ''Ÿ''Ź''ź''Ż''ż''Ž''ž''ſ''ƒ''Ơ''ơ''Ư''ư''Ǎ''ǎ''Ǐ''ǐ''Ǒ''ǒ''Ǔ''ǔ''Ǖ''ǖ''Ǘ''ǘ''Ǚ''ǚ''Ǜ''ǜ''Ǻ''ǻ''Ǽ''ǽ''Ǿ''ǿ');
  596.         $b = array('N','n','A''A''A''A''A''A''AE''C''E''E''E''E''I''I''I''I''D''N''O''O''O''O''O''O''U''U''U''U''Y''s''a''a''a''a''a''a''ae''c''e''e''e''e''i''i''i''i''n''o''o''o''o''o''o''u''u''u''u''y''y''A''a''A''a''A''a''C''c''C''c''C''c''C''c''D''d''D''d''E''e''E''e''E''e''E''e''E''e''G''g''G''g''G''g''G''g''H''h''H''h''I''i''I''i''I''i''I''i''I''i''IJ''ij''J''j''K''k''L''l''L''l''L''l''L''l''l''l''N''n''N''n''N''n''n''O''o''O''o''O''o''OE''oe''R''r''R''r''R''r''S''s''S''s''S''s''S''s''T''t''T''t''T''t''U''u''U''u''U''u''U''u''U''u''U''u''W''w''Y''y''Y''Z''z''Z''z''Z''z''s''f''O''o''U''u''A''a''I''i''O''o''U''u''U''u''U''u''U''u''U''u''A''a''AE''ae''O''o');
  597.         return str_replace($a$b$str);
  598.     }
  599. }