/**
  * Execute
  *
  * @param InputInterface  $input  input
  * @param OutputInterface $output output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('<info>Import translations lot 4</info>');
     try {
         $entityManager = $this->getEntityManager();
         $translationRepository = $this->getTranslationRepository();
         $langs = $this->getContainer()->getParameter('langs');
         $translationDir = $this->getContainer()->getParameter('translation_dir') . '/lot_4/';
         $progress = $this->getHelperSet()->get('progress');
         $progress->start($output, count($langs));
         $hotelHighlights = array();
         $pages = array();
         foreach ($langs as $lang) {
             $translationfiles = scandir($translationDir . strtoupper($lang) . '/');
             foreach ($translationfiles as $translationFile) {
                 if ($translationFile == "." || $translationFile == "..") {
                     continue;
                 }
                 if ($translationFile == 'page.xlsx') {
                     $file = $translationDir . strtoupper($lang) . '/' . $translationFile;
                     $pageCsv = Converter::getCsv($file);
                     $data = Converter::getData($pageCsv);
                     foreach ($data as $page) {
                         $pages[$page[0]][$lang] = array('brand' => utf8_decode($page[1]), 'name' => '[' . utf8_decode($page[1]) . '] ' . utf8_decode($page[2]), 'title' => '<h1>' . utf8_decode($page[3]) . '</h1>', 'description' => '<p>' . utf8_decode($page[4]) . '</p><p>' . utf8_decode($page[5]) . '</p>');
                     }
                 }
             }
             $progress->advance();
         }
         $progress->finish();
         $output->writeln(' > <info>Handling pages</info>');
         $progress->start($output, count($pages));
         $template = $this->getRepository('BigfootContentBundle:Template')->findOneByRoute('SehBundle:page:default.html.twig');
         foreach ($pages as $code => $cPage) {
             if (!($nPage = $this->getRepository('BigfootContentBundle:Page')->findOneBy(array('name' => $cPage['en']['name'])))) {
                 $nPage = new Page();
             }
             $nPage->setActive(true)->setTranslatableLocale('en')->setName($cPage['en']['name'])->setTitle($cPage['en']['title'])->setDescription($cPage['en']['description'])->setTemplate($template);
             foreach ($langs as $lang) {
                 if ($lang != 'en') {
                     $translationRepository->translate($nPage, 'name', $lang, $cPage[$lang]['name']);
                     $translationRepository->translate($nPage, 'title', $lang, $cPage[$lang]['title']);
                     $translationRepository->translate($nPage, 'description', $lang, $cPage[$lang]['description']);
                 }
             }
             $entityManager->persist($nPage);
             $progress->advance();
         }
         $progress->finish();
         $output->writeln(' > <info>Flushing</info>');
         $entityManager->flush();
         $output->writeln(' > <comment>OK</comment>');
     } catch (Exception $e) {
         $output->writeln(' > <error>Erreur : ' . $e->getMessage() . '</error>');
     }
 }
 /**
  * Execute
  *
  * @param InputInterface  $input  input
  * @param OutputInterface $output output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('<info>Import translations lot 2</info>');
     try {
         $entityManager = $this->getEntityManager();
         $translationRepository = $this->getTranslationRepository();
         $langs = $this->getContainer()->getParameter('langs');
         $translationDir = $this->getContainer()->getParameter('translation_dir') . '/lot_2/';
         $progress = $this->getHelperSet()->get('progress');
         $progress->start($output, count($langs));
         $hotelHighlights = array();
         $pages = array();
         foreach ($langs as $lang) {
             $translationfiles = scandir($translationDir . strtoupper($lang) . '/');
             foreach ($translationfiles as $translationFile) {
                 if ($translationFile == "." || $translationFile == "..") {
                     continue;
                 }
                 if ($translationFile == 'hotel.xlsx') {
                     $file = $translationDir . strtoupper($lang) . '/' . $translationFile;
                     $hotelCsv = Converter::getCsv($file);
                     $data = Converter::getData($hotelCsv);
                     foreach ($data as $hotel) {
                         $code = $hotel[0];
                         $description = $hotel[2];
                         $hotelHighlights[$code]['highlight_1'][$lang] = trim($hotel[3]);
                         $hotelHighlights[$code]['highlight_2'][$lang] = trim($hotel[4]);
                         $hotelHighlights[$code]['highlight_3'][$lang] = trim($hotel[5]);
                         $hotelDb = $this->getRepository('SehBundle:Hotel')->findOneByCodeAdherent($code);
                         if ($hotelDb) {
                             $hotelDb->setTranslatableLocale('en');
                             $translationRepository->translate($hotelDb, 'shortDescription', $lang, utf8_decode($description));
                             $entityManager->persist($hotelDb);
                         }
                     }
                 } elseif ($translationFile == 'page.csv') {
                     $file = $translationDir . strtoupper($lang) . '/' . $translationFile;
                     $data = Converter::getData($file);
                     foreach ($data as $page) {
                         $pages[$page[0]][$lang] = array('brand' => $page[1], 'name' => $page[2], 'title' => '<h1>' . $page[3] . '</h1>', 'description' => '<p>' . $page[4] . '</p><h2>' . $page[5] . '</h2><p>' . $page[6] . '</p><h2>' . $page[7] . '</h2><p>' . $page[8] . '</p><h2>' . $page[9] . '</h2><p>' . $page[10] . '</p>' . $page[11] . '</p><h2>' . $page[12] . '</h2><p>' . $page[13] . '</p>');
                     }
                 }
             }
             $progress->advance();
         }
         $progress->finish();
         $output->writeln(' > <info>Handling hightlights</info>');
         $this->getRepository('SehBundle:HotelHighlight')->deleteAll();
         $progress->start($output, count($hotelHighlights));
         foreach ($hotelHighlights as $code => $hightlights) {
             $hotelDb = $this->getRepository('SehBundle:Hotel')->findOneByCodeAdherent($code);
             if ($hotelDb) {
                 foreach ($hightlights as $hightlight) {
                     $hHighlight = new HotelHighlight();
                     $hHighlight->setHotel($hotelDb)->setTranslatableLocale('en')->setName($hightlight['en']);
                     foreach ($langs as $lang) {
                         if ($lang != 'en') {
                             $translationRepository->translate($hHighlight, 'name', $lang, utf8_decode($hightlight[$lang]));
                         }
                     }
                     $entityManager->persist($hHighlight);
                 }
             }
             $progress->advance();
         }
         $progress->finish();
         $output->writeln(' > <info>Handling pages</info>');
         $progress->start($output, count($pages));
         $template = $this->getRepository('BigfootContentBundle:Template')->findOneByRoute('SehBundle:page:default.html.twig');
         foreach ($pages as $cPage) {
             $nPage = $this->getRepository('BigfootContentBundle:Page')->findOneByName($cPage['en']['name']);
             if (!$nPage) {
                 $nPage = new Page();
             }
             $nPage->setActive(true)->setTranslatableLocale('en')->setName($cPage['en']['name'])->setTitle($cPage['en']['title'])->setDescription($cPage['en']['description'])->setTemplate($template);
             foreach ($langs as $lang) {
                 if ($lang != 'en') {
                     $translationRepository->translate($nPage, 'name', $lang, $cPage[$lang]['name']);
                     $translationRepository->translate($nPage, 'title', $lang, $cPage[$lang]['title']);
                     $translationRepository->translate($nPage, 'description', $lang, $cPage[$lang]['description']);
                 }
             }
             $entityManager->persist($nPage);
             $progress->advance();
         }
         $progress->finish();
         $output->writeln(' > <info>Flushing</info>');
         $entityManager->flush();
         $output->writeln(' > <comment>OK</comment>');
     } catch (Exception $e) {
         $output->writeln(' > <error>Erreur : ' . $e->getMessage() . '</error>');
     }
 }
 /**
  * Execute
  *
  * @param InputInterface  $input  input
  * @param OutputInterface $output output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('<info>Import translations lot 3</info>');
     try {
         $entityManager = $this->getEntityManager();
         $translationRepository = $this->getTranslationRepository();
         $langs = $this->getContainer()->getParameter('langs');
         $translationDir = $this->getContainer()->getParameter('translation_dir') . '/lot_3/';
         $progress = $this->getHelperSet()->get('progress');
         $progress->start($output, count($langs));
         $zonesRDS = array();
         $zonesIH = array();
         foreach ($langs as $lang) {
             $translationfiles = scandir($translationDir . strtoupper($lang) . '/');
             foreach ($translationfiles as $translationFile) {
                 if ($translationFile == "." || $translationFile == "..") {
                     continue;
                 }
                 if ($translationFile == 'zone_desc.csv') {
                     $file = $translationDir . strtoupper($lang) . '/' . $translationFile;
                     $data = Converter::getData($file);
                     foreach ($data as $zone) {
                         $brandId = str_replace('RS', 'RDS', $zone[0]);
                         $brand = $this->getRepository('SehBundle:Brand')->findOneByArtsysID($brandId);
                         if ($brand and $brandId == 'RDS') {
                             $reservitId = $zone[1];
                             $country = $this->getRepository('SehBundle:Country')->findOneByReservitId($reservitId);
                             $region = $this->getRepository('SehBundle:Region')->findOneByReservitId($reservitId);
                             $department = $this->getRepository('SehBundle:Department')->findOneByReservitId($reservitId);
                             if ($country) {
                                 $zonesRDS['country'][$brand->getId() . $country->getId()][$lang] = array('brand' => $brand, 'country' => $country, 'description' => '<p>' . $zone[4] . '</p>');
                             } elseif ($region) {
                                 $zonesRDS['region'][$brand->getId() . $region->getId()][$lang] = array('brand' => $brand, 'region' => $region, 'description' => '<p>' . $zone[4] . '</p>');
                             } elseif ($department) {
                                 $zonesRDS['department'][$brand->getId() . $department->getId()][$lang] = array('brand' => $brand, 'department' => $department, 'description' => '<p>' . $zone[4] . '</p>');
                             }
                         } elseif ($brandId == 'IH') {
                             if (preg_match('/region/i', $zone[2])) {
                                 $zonesIH['region'][$lang] = array('brand' => $brand, 'description' => $zone[3] . '<p>' . $zone[4] . '</p>');
                             } elseif (preg_match('/partement/i', $zone[2])) {
                                 $zonesIH['department'][$lang] = array('brand' => $brand, 'description' => $zone[3] . '<p>' . $zone[4] . '</p>');
                             } elseif (preg_match('/elle/i', $zone[2])) {
                                 $zonesIH['city'][$lang] = array('brand' => $brand, 'description' => $zone[3] . '<p>' . $zone[4] . '</p>');
                             } elseif (preg_match('/rattachement/i', $zone[2])) {
                                 $zonesIH['linked-city'][$lang] = array('brand' => $brand, 'description' => $zone[3] . '<p>' . $zone[4] . '</p>');
                             }
                         }
                     }
                 }
             }
             $progress->advance();
         }
         $progress->finish();
         $this->getRepository('SehBundle:Brand\\Country')->deleteAll();
         $this->getRepository('SehBundle:Brand\\Region')->deleteAll();
         $this->getRepository('SehBundle:Brand\\Department')->deleteAll();
         $output->writeln(' > <info>Handling zones IH</info>');
         if (isset($zonesIH['region'])) {
             $brandRegion = new BrandRegion();
             $brandRegion->setTranslatableLocale('en')->setBrand($zonesIH['region']['en']['brand'])->setDescription($zonesIH['region']['en']['description']);
             foreach ($langs as $lang) {
                 if ($lang != 'en') {
                     $translationRepository->translate($brandRegion, 'description', $lang, $zonesIH['region'][$lang]['description']);
                 }
             }
             $entityManager->persist($brandRegion);
         }
         if (isset($zonesIH['department'])) {
             $brandDepartment = new BrandDepartment();
             $brandDepartment->setTranslatableLocale('en')->setBrand($zonesIH['department']['en']['brand'])->setDescription($zonesIH['department']['en']['description']);
             foreach ($langs as $lang) {
                 if ($lang != 'en') {
                     $translationRepository->translate($brandDepartment, 'description', $lang, $zonesIH['department'][$lang]['description']);
                 }
             }
             $entityManager->persist($brandDepartment);
         }
         if (isset($zonesIH['city'])) {
             $brandCity = new BrandCity();
             $brandCity->setTranslatableLocale('en')->setBrand($zonesIH['city']['en']['brand'])->setDescription($zonesIH['city']['en']['description']);
             foreach ($langs as $lang) {
                 if ($lang != 'en') {
                     $translationRepository->translate($brandCity, 'description', $lang, $zonesIH['city'][$lang]['description']);
                 }
             }
             $entityManager->persist($brandCity);
         }
         if (isset($zonesIH['linked-city'])) {
             $brandLinkedCity = new BrandLinkedCity();
             $brandLinkedCity->setTranslatableLocale('en')->setBrand($zonesIH['linked-city']['en']['brand'])->setDescription($zonesIH['linked-city']['en']['description']);
             foreach ($langs as $lang) {
                 if ($lang != 'en') {
                     if (isset($zonesIH['linked-city'][$lang])) {
                         $translationRepository->translate($brandLinkedCity, 'description', $lang, $zonesIH['linked-city'][$lang]['description']);
                     }
                 }
             }
             $entityManager->persist($brandLinkedCity);
         }
         $output->writeln(' > <info>Handling zones RDS</info>');
         if (isset($zonesRDS['country'])) {
             foreach ($zonesRDS['country'] as $zoneCountry) {
                 $brandCountry = new BrandCountry();
                 $brandCountry->setTranslatableLocale('en')->setBrand($zoneCountry['en']['brand'])->setCountry($zoneCountry['en']['country'])->setDescription($zoneCountry['en']['description']);
                 foreach ($langs as $lang) {
                     if ($lang != 'en') {
                         $translationRepository->translate($brandCountry, 'description', $lang, $zoneCountry[$lang]['description']);
                     }
                 }
                 $entityManager->persist($brandCountry);
             }
         }
         if (isset($zonesRDS['region'])) {
             foreach ($zonesRDS['region'] as $zoneRegion) {
                 $brandRegion = new BrandRegion();
                 $brandRegion->setTranslatableLocale('en')->setBrand($zoneRegion['en']['brand'])->setRegion($zoneRegion['en']['region'])->setDescription($zoneRegion['en']['description']);
                 foreach ($langs as $lang) {
                     if ($lang != 'en') {
                         $translationRepository->translate($brandRegion, 'description', $lang, $zoneRegion[$lang]['description']);
                     }
                 }
                 $entityManager->persist($brandRegion);
             }
         }
         if (isset($zonesRDS['department'])) {
             foreach ($zonesRDS['department'] as $zoneDepartment) {
                 $brandDepartment = new BrandDepartment();
                 $brandDepartment->setTranslatableLocale('en')->setBrand($zoneDepartment['en']['brand'])->setDepartment($zoneDepartment['en']['department'])->setDescription($zoneDepartment['en']['description']);
                 foreach ($langs as $lang) {
                     if ($lang != 'en') {
                         $translationRepository->translate($brandDepartment, 'description', $lang, $zoneDepartment[$lang]['description']);
                     }
                 }
                 $entityManager->persist($brandDepartment);
             }
         }
         $output->writeln(' > <info>Flushing</info>');
         $entityManager->flush();
         $output->writeln(' > <comment>OK</comment>');
     } catch (Exception $e) {
         $output->writeln(' > <error>Erreur : ' . $e->getMessage() . '</error>');
     }
 }