Пример #1
0
 /**
  * Load data fixtures with the passed EntityManager
  *
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $countries = $manager->getRepository('SehBundle:Country')->findAll();
     foreach ($countries as $country) {
         $countryBrand = new Country();
         $countryBrand->setCountry($country);
         $manager->persist($countryBrand);
     }
     $regions = $manager->getRepository('SehBundle:Region')->findAll();
     foreach ($regions as $region) {
         $regionBrand = new Region();
         $regionBrand->setRegion($region);
         $manager->persist($regionBrand);
     }
     $departments = $manager->getRepository('SehBundle:Department')->findAll();
     foreach ($departments as $department) {
         $departmentBrand = new Department();
         $departmentBrand->setDepartment($department);
         $manager->persist($departmentBrand);
     }
     $thematics = $manager->getRepository('SehBundle:Thematic')->findAll();
     foreach ($thematics as $thematic) {
         $thematicBrand = new Thematic();
         $thematicBrand->setThematic($thematic);
         $manager->persist($thematicBrand);
     }
     $cities = $manager->getRepository('SehBundle:City')->findAll();
     foreach ($cities as $city) {
         $cityBrand = new City();
         $cityBrand->setCity($city);
         $manager->persist($cityBrand);
     }
     $manager->flush();
 }
Пример #2
0
 /**
  * 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>');
     }
 }