Esempio n. 1
0
 protected function updateSlugsForEntity($output, $entityName)
 {
     $em = $this->getEntityManager();
     /** @var TranslationRepository $translationRepository */
     $translationRepository = $this->getTranslationRepository();
     $entities = $em->getRepository($entityName)->findAll();
     $output->writeln(sprintf(' > Updating slugs for <info>%s</info>', $entityName));
     /** @var ProgressHelper $progress */
     $progress = $this->getHelperSet()->get('progress');
     $progress->start($output, count($entities));
     foreach ($entities as $entity) {
         $entity->setSlug(null);
         $translations = $translationRepository->findTranslations($entity);
         foreach ($translations as $locale => $values) {
             if (isset($values['name'])) {
                 $slug = Urlizer::transliterate($values['name']);
                 $slug = Urlizer::urlize($slug);
                 if (function_exists('mb_strtolower')) {
                     $slug = mb_strtolower($slug);
                 } else {
                     $slug = strtolower($slug);
                 }
                 $translationRepository->translate($entity, 'slug', $locale, $slug);
             }
         }
         $em->persist($entity);
         $progress->advance();
     }
     $em->flush();
     $em->clear();
     $progress->finish();
 }
Esempio n. 2
0
 protected function setSlug($estate)
 {
     $originalAddress = $estate->getAddress();
     $estate->setTranslatableLocale('en');
     $_manager = $this->getConfigurationPool()->getContainer()->get('Doctrine')->getManager();
     $_manager->refresh($estate);
     $slug = $estate->getAddress() ? $estate->getAddress() : $originalAddress;
     $slug = Sluggable\Urlizer::transliterate($slug, '_');
     $estate->setSlug(Sluggable\Urlizer::urlize($slug, '_'));
     $_manager->persist($estate);
     $_manager->flush();
 }
Esempio n. 3
0
 /**
  * Execute
  *
  * @param InputInterface  $input  input
  * @param OutputInterface $output output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('<info>Update department slug</info>');
     try {
         $em = $this->getEntityManager();
         /** @var ProgressHelper $progress */
         $progress = $this->getHelperSet()->get('progress');
         /** @var DepartmentRepository $departmentRepo */
         $departmentRepo = $this->getRepository('SehBundle:Department');
         $entities = $departmentRepo->findAll();
         $langs = array('en', 'de', 'es', 'it', 'nl');
         $progress->start($output, count($entities));
         /** @var Department $entity */
         foreach ($entities as $entity) {
             foreach ($langs as $lang) {
                 $entity->setTranslatableLocale($lang);
                 $em->refresh($entity);
                 $slug = $entity->getName();
                 $entity->setSlug(null);
                 $slug = Urlizer::transliterate($slug);
                 $slug = Urlizer::urlize($slug);
                 if (function_exists('mb_strtolower')) {
                     $slug = mb_strtolower($slug);
                 } else {
                     $slug = strtolower($slug);
                 }
                 $entity->setSlug($slug);
                 $em->persist($entity);
                 $em->flush();
             }
             $progress->advance();
         }
         $progress->finish();
         $output->writeln(' > <info>Flushing</info>');
         $em->flush();
         $em->clear();
         $output->writeln(' > <comment>OK</comment>');
     } catch (Exception $e) {
         $output->writeln(' > <error>Erreur : ' . $e->getMessage() . '</error>');
     }
 }
Esempio n. 4
0
 /**
  * Execute
  *
  * @param InputInterface  $input  input
  * @param OutputInterface $output output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('<info>Update hotels slug</info>');
     try {
         $entityManager = $this->getEntityManager();
         $progress = $this->getHelperSet()->get('progress');
         $hotelRepo = $this->getRepository('SehBundle:Hotel');
         $entities = $hotelRepo->findAll();
         $progress->start($output, count($entities));
         foreach ($entities as $entity) {
             $exists = $hotelRepo->findBy(array("name" => $entity->getName()));
             if (count($exists) > 1) {
                 echo "\n" . $entity->getName();
                 $slug = $entity->getName() . "-" . $entity->getZipCode();
             } else {
                 $slug = $entity->getName();
             }
             $entity->setSlug(null);
             $slug = Urlizer::transliterate($slug);
             $slug = Urlizer::urlize($slug);
             if (function_exists('mb_strtolower')) {
                 $slug = mb_strtolower($slug);
             } else {
                 $slug = strtolower($slug);
             }
             $entity->setSlug($slug);
             $entityManager->persist($entity);
             $progress->advance();
         }
         $progress->finish();
         $output->writeln(' > <info>Flushing</info>');
         $entityManager->flush();
         $entityManager->clear();
         $output->writeln(' > <comment>OK</comment>');
     } catch (Exception $e) {
         $output->writeln(' > <error>Erreur : ' . $e->getMessage() . '</error>');
     }
 }
Esempio n. 5
0
 /**
  * Manages the copying of the file to the relevant place on the server
  * @throws EmptyFileException when no file has been uploaded
  * @return $this
  */
 public function upload()
 {
     // the file property cannot be empty
     if (null === $this->getFile()) {
         throw new EmptyFileException("File is empty");
     }
     // Sanitize the filename
     $this->filename = Urlizer::transliterate($this->getFile()->getClientOriginalName());
     // check upload dir
     $this->checkUploadDir();
     // change filename if a file with the same name exists
     if (file_exists($this->getPath())) {
         $i = 1;
         $originalFilename = $this->filename;
         do {
             $this->filename = $i++ . '_' . $originalFilename;
             if ($i > 3) {
                 $this->filename = uniqid();
             }
         } while (file_exists($this->getPath()));
     }
     // move the file to the upload dir
     $this->getFile()->move($this->getDirectoryPath(), $this->filename);
     // file property cleaned, not needed anymore
     $this->setFile(null);
     return $this;
 }
Esempio n. 6
0
 protected function importLang($brand, $lang)
 {
     $translationRepository = $this->getTranslationRepository();
     $translationDir = $this->getContainer()->getParameter('translation_dir') . '/lot_5/';
     $defaultLang = 'en';
     $em = $this->getEntityManager();
     $translationfiles = scandir($translationDir . strtoupper($lang) . '/');
     $exclude = array('.', '..');
     $translationfiles = array_diff($translationfiles, $exclude);
     foreach (array_values($translationfiles) as $translationFile) {
         $file = $translationDir . strtoupper($lang) . '/' . $translationFile;
         $handle = fopen($file, "r");
         while (($line = fgetcsv($handle)) !== false) {
             if ($line) {
                 list($brandId, $regionId, $pageName, $pageTitle, $pageDescription, $block1Title, $block1Description, $block2Title, $block2Description, $block3Title, $block3Description, $block4Title, $block4Description, $block5Title, $block5Description, $imageTitle1, $imageTitle2, $imageTitle3) = $line;
                 $name = sprintf('[%s] Region hotelier - %s [%s]', $brandId, $pageName, $regionId);
                 $page = $em->getRepository('BigfootContentBundle:Page\\Template\\TitleDescMediaBlockSidebar')->createQueryBuilder('p')->where('p.name LIKE :name')->setParameter(':name', sprintf('%%[%s]%%', $regionId))->getQuery()->setHint(\Gedmo\Translatable\TranslatableListener::HINT_TRANSLATABLE_LOCALE, 'en')->getOneOrNullResult();
                 if (!$page) {
                     $page = new Page\Template\TitleDescMediaBlockSidebar();
                     $page->setTemplate('title_desc_media_block_sidebar_edito');
                     $page->setActive(true);
                 }
                 if ($lang != $defaultLang) {
                     $translationRepository->translate($page, 'name', $lang, $name);
                     $translationRepository->translate($page, 'title', $lang, $pageTitle);
                     $translationRepository->translate($page, 'description', $lang, $pageDescription);
                     $slug = Urlizer::transliterate(sprintf('%s Region hotelier %s', $brandId, $pageName));
                     $slug = Urlizer::urlize($slug);
                     if (function_exists('mb_strtolower')) {
                         $slug = mb_strtolower($slug);
                     } else {
                         $slug = strtolower($slug);
                     }
                     $translationRepository->translate($page, 'slug', $lang, $slug);
                 } else {
                     $page->setName($name);
                     $page->setTitle($pageTitle);
                     $page->setDescription($pageDescription);
                     $slug = Urlizer::transliterate(sprintf('%s Region hotelier %s', $brandId, $pageName));
                     $slug = Urlizer::urlize($slug);
                     if (function_exists('mb_strtolower')) {
                         $slug = mb_strtolower($slug);
                     } else {
                         $slug = strtolower($slug);
                     }
                     $page->setSlug($slug);
                 }
                 $em->persist($page);
                 for ($i = 1; $i < 6; $i++) {
                     $title = sprintf('block%sTitle', $i);
                     $desc = sprintf('block%sDescription', $i);
                     if (${$title} or ${$desc}) {
                         $blockName = sprintf('[%s] Region hotelier - %s - Bloc %s [%s]', $brandId, $pageName, $i, $regionId);
                         $block = $em->getRepository('BigfootContentBundle:Block\\Template\\TitleDescMedia')->createQueryBuilder('b')->where('b.name LIKE :name')->setParameter(':name', sprintf('%%%s [%s]%%', $i, $regionId))->getQuery()->setHint(\Gedmo\Translatable\TranslatableListener::HINT_TRANSLATABLE_LOCALE, 'en')->getOneOrNullResult();
                         if (!$block) {
                             $block = new TitleDescMedia();
                             $block->setTemplate('title_desc_media_editorialLeft');
                             $block->setActive(true);
                         }
                         if ($lang != $defaultLang) {
                             $translationRepository->translate($block, 'name', $lang, $blockName);
                             $translationRepository->translate($block, 'title', $lang, ${$title});
                             $translationRepository->translate($block, 'description', $lang, ${$desc});
                             $slug = Urlizer::transliterate($blockName);
                             $slug = Urlizer::urlize($slug);
                             if (function_exists('mb_strtolower')) {
                                 $slug = mb_strtolower($slug);
                             } else {
                                 $slug = strtolower($slug);
                             }
                             $translationRepository->translate($block, 'slug', $lang, $slug);
                         } else {
                             $block->setName($blockName);
                             $block->setTitle(${$title});
                             $block->setDescription(${$desc});
                             $pageBlock = new Page\Block();
                             $pageBlock->setBlock($block);
                             $pageBlock->setPage($page);
                             $pageBlock->setPosition($i);
                             $pageBlock->setTemplate('title_desc_media_editorialLeft');
                             $page->addBlock($pageBlock);
                             $em->persist($pageBlock);
                         }
                         $em->persist($block);
                     }
                 }
                 $em->flush();
             }
         }
     }
 }
 public function oldAndSuckingFunction($type)
 {
     $term = strtolower(trim($this->getRequest()->get('term', null)));
     // TODO: this dependency needs to go away or made explicit
     $term = \Gedmo\Sluggable\Util\Urlizer::transliterate($term);
     $currentLocaleResults = $this->searchBaseLocale($term);
     $otherLocalesResults = $this->searchOtherLocales($term);
     $results = array_merge($currentLocaleResults, $otherLocalesResults);
     $data = array();
     $ids = array();
     foreach ($results as $result) {
         $data[] = array('id' => $result['id'], 'label' => $result['name']);
     }
     $res = new Response(json_encode($data));
     $res->headers->set('Content-Type', 'application/json');
     return $res;
 }
 protected function importLang($lang)
 {
     $translationRepository = $this->getTranslationRepository();
     $translationDir = $this->getContainer()->getParameter('translation_dir') . '/cities2Hours/';
     $defaultLang = 'en';
     $em = $this->getEntityManager();
     $translationfiles = scandir($translationDir . '/');
     $exclude = array('.', '..');
     $translationfiles = array_diff($translationfiles, $exclude);
     foreach (array_values($translationfiles) as $translationFile) {
         $xml = new \SimpleXMLElement(file_get_contents($translationDir . '/' . $translationFile));
         $destinations = $xml->xpath('/homepage/' . $lang . '/destination');
         foreach ($destinations as $destination) {
             $destinationId = $destination->id;
             $destinationName = $destination->ville;
             $result = $destination->xpath('descriptif');
             $description = $result[0]->__toString();
             $country = $destination->pays;
             if ($country == "Allemagne") {
                 $country = "Germany";
             } elseif ($country == "Italie") {
                 $country = "Italy";
             } elseif ($country == "Belgique") {
                 $country = "Belgium";
             } elseif ($country == "Suisse") {
                 $country = "Switzerland";
             } elseif ($country == "Espagne") {
                 $country = "Spain";
             } elseif ($country == "Autriche") {
                 $country = "Austria";
             }
             $destinationDb = $this->getRepository('SehBundle:ListingCity')->findOneByIdXml($destinationId);
             $entityCountry = $em->getRepository('SehBundle:Country')->createQueryBuilder('c')->where('c.name = :name')->setParameter(':name', $country)->getQuery()->setHint(\Gedmo\Translatable\TranslatableListener::HINT_TRANSLATABLE_LOCALE, 'fr')->getOneOrNullResult();
             if (!$destinationDb) {
                 $destinationDb = new ListingCity();
             }
             if ($lang != $defaultLang) {
                 $translationRepository->translate($destinationDb, 'description', $lang, $description);
                 $translationRepository->translate($destinationDb, 'city', $lang, $destinationName);
                 $slug = Urlizer::transliterate($destinationName);
                 $slug = Urlizer::urlize($slug);
                 if (function_exists('mb_strtolower')) {
                     $slug = mb_strtolower($slug);
                 } else {
                     $slug = strtolower($slug);
                 }
                 $translationRepository->translate($destinationDb, 'slug', $lang, $slug);
             } else {
                 $destinationDb->setDescription($description);
                 $destinationDb->setCity($destinationName);
                 $destinationDb->setIdXml($destinationId);
                 $destinationDb->setCountry($entityCountry);
             }
             $em->persist($destinationDb);
         }
         $em->flush();
     }
 }
Esempio n. 9
0
 /**
  * Uses transliteration tables to convert any kind of utf8 character
  *
  * @param string $text
  * @param string $separator
  * @return string $text
  */
 public static function transliterate($text, $separator = '-')
 {
     $text = strip_tags($text);
     $text = GedmoUrlizer::transliterate($text, $separator);
     return $text;
 }
Esempio n. 10
0
 /**
  * since transliterate will convert "ä" to an "a", i added this hack to call urlize first so it is converted to "ae" first
  *
  * @param string $text
  * @param string $separator
  * @return string $text
  */
 public static function transliterate($text, $separator = '-')
 {
     $text = \Gedmo\Sluggable\Util\Urlizer::urlize($text, $separator);
     return \Gedmo\Sluggable\Util\Urlizer::transliterate($text, $separator);
 }