/**
  * @Route("/ck/upload", name="bigfoot_media_upload", options={"expose"=true})
  */
 public function ckUploadAction()
 {
     $content = '';
     /** @var UploadedFile $file */
     if ($file = $this->getRequestStack()->files->get('upload', false)) {
         try {
             $fileName = $file->getClientOriginalName();
             $mimeType = $file->getMimeType();
             $size = $file->getSize();
             $absPath = sprintf('%s/%s', rtrim($this->getUploadDir(), '/'), $this->getRequestStack()->get('CKEditor'));
             $relPath = sprintf('%s/%s', rtrim($this->getUploadDir(false), '/'), $this->getRequestStack()->get('CKEditor'));
             $file->move($absPath, $fileName);
             $content = sprintf("window.parent.CKEDITOR.tools.callFunction(%s, '%s', '%s')", $this->getRequestStack()->get('CKEditorFuncNum'), sprintf('%s/%s', $relPath, $fileName), '');
             $media = new Media();
             $media->setFile(sprintf('%s/%s', $relPath, $fileName));
             $media->setType($mimeType);
             $em = $this->getDoctrine()->getManager();
             $em->persist($media);
             $em->flush();
             /** @var MediaRepository $mediaRepository */
             $mediaRepository = $em->getRepository('BigfootMediaBundle:Media');
             list($width, $height) = getimagesize(sprintf('%s/%s', rtrim($absPath, '/'), $fileName));
             $mediaRepository->setMetadata($media, 'title', $fileName);
             $mediaRepository->setMetadata($media, 'width', $width);
             $mediaRepository->setMetadata($media, 'height', $height);
             $mediaRepository->setMetadata($media, 'size', $media->convertFileSize($size));
             $em->flush();
         } catch (\Exception $e) {
             $content = sprintf('alert(\'%s\')', $e->getMessage());
         }
     }
     return new Response(sprintf('<script>%s</script>', $content));
 }
Example #2
0
 /**
  * Execute
  *
  * @param InputInterface  $input  input
  * @param OutputInterface $output output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('<info>Import services images</info>');
     try {
         $entityManager = $this->getEntityManager();
         $portfolioPath = $this->getContainer()->getParameter('bigfoot.core.upload_dir') . $this->getContainer()->getParameter('bigfoot.media.portfolio_dir');
         $servicesPath = $portfolioPath . 'services/';
         $webDir = $this->getContainer()->get('kernel')->getRootDir() . '/../web/';
         $imagesDir = $webDir . $servicesPath;
         $mediaRepo = $entityManager->getRepository('BigfootMediaBundle:Media');
         $mediaUsageRepo = $entityManager->getRepository('BigfootMediaBundle:MediaUsage');
         $serviceRepo = $entityManager->getRepository('SehBundle:HotelService');
         /**
          * @var Filesystem $fs
          */
         $fs = $this->getContainer()->get('filesystem');
         if (!$fs->exists($imagesDir)) {
             throw new FileNotFoundException($imagesDir);
         }
         $images = scandir($imagesDir);
         $exclude = array('.', '..');
         $images = array_diff($images, $exclude);
         $progress = $this->getHelperSet()->get('progress');
         $progress->start($output, count($images));
         foreach ($images as $image) {
             $slug = basename($image, sprintf('.%s', $extension = pathinfo($image, PATHINFO_EXTENSION)));
             $fileName = $servicesPath . $image;
             $newMedia = false;
             if (!($media = $mediaRepo->findOneByFile($fileName))) {
                 $media = new Media();
                 $media->setFile($fileName);
                 $media->setType($extension);
                 $entityManager->persist($media);
                 $newMedia = true;
             }
             if ($service = $serviceRepo->findOneBySlug($slug)) {
                 if ($newMedia or !($usage = $mediaUsageRepo->findOneBy(array('mediaId' => $media, 'tableRef' => 'SehBundle:HotelService', 'columnRef' => 'media', 'elementId' => $service->getId())))) {
                     $mediaUsage = new MediaUsage();
                     $mediaUsage->setMediaId($media);
                     $mediaUsage->setTableRef('SehBundle:Hotel');
                     $mediaUsage->setColumnRef('gallery');
                     $mediaUsage->setElementId($service->getId());
                     $entityManager->persist($mediaUsage);
                 }
                 $service->setMedia($media->getId());
                 $entityManager->persist($service);
             } else {
                 $output->writeln(sprintf(' > <error>Service "%s" not found - the image was saved but not associated to the service</error>', $slug));
             }
             $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>');
     }
 }
 /**
  * Initializes metadatas for the given media.
  * Checkouts the current list of possible metadatas and sets them to empty for the media if the association between media and metadata doesn't exist yet
  *
  * @param Media $media
  */
 public function initMetadata(Media $media)
 {
     $em = $this->getEntityManager();
     $metadataRepo = $em->getRepository('BigfootMediaBundle:Metadata');
     $allMetadatas = $metadataRepo->findAll();
     foreach ($allMetadatas as $metadata) {
         if (!$media->getMetadata($metadata->getSlug())) {
             $this->setMetadata($media, $metadata->getSlug(), '');
         }
     }
 }
Example #4
0
 /**
  * Load data fixtures with the passed EntityManager
  *
  * @param Doctrine\Common\Persistence\ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $media1 = new Media();
     $media1->setFile('fixtures/1.gif');
     $media1->setType('gif');
     $manager->persist($media1);
     $manager->flush();
     $tabMedia = array();
     $tabMedia[] = $media1->getId();
     $tabMedia[] = $media1->getId();
     $stringMedia = implode(';', $tabMedia);
     // Room With thumbnail
     $room1 = new RoomType();
     $room1->setReservitId('127826-334940')->setThumbnail($stringMedia);
     // Room with no thumbnail
     $room2 = new RoomType();
     $room2->setReservitId('127826-334941')->setThumbnail('');
     $manager->persist($room1);
     $manager->persist($room2);
     $manager->flush();
 }
 /**
  * Handles upload
  *
  * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
  *
  * @return \Symfony\Component\HttpFoundation\Response
  * @throws \Exception
  *
  * @Route("/upload", name="portfolio_upload")
  */
 public function uploadAction()
 {
     // retrieves the posted data, for reference
     $requestStack = $this->getRequestStack();
     $file = $requestStack->get('value');
     $name = $requestStack->get('name');
     $json = array('name' => $name, 'success' => false, 'html' => null);
     // separate out the data
     $data = explode(',', $file);
     // encode it correctly
     $encodedData = str_replace(' ', '+', $data[1]);
     $decodedData = base64_decode($encodedData);
     $media = new Media();
     // generate new name, relative and absolute path
     $fileManager = $this->get('bigfoot_core.manager.file_manager');
     $name = $fileManager->sanitizeName($name);
     $image = uniqid() . '_' . $name;
     $directory = $this->getUploadDir();
     $absolutePath = $directory . '/' . $image;
     if (!file_exists($directory)) {
         $filesystem = $this->get('filesystem');
         $filesystem->mkdir($directory, 0777);
     }
     if (file_put_contents($absolutePath, $decodedData)) {
         $relativePath = $this->getParameter('bigfoot.core.upload_dir') . $this->getParameter('bigfoot.media.portfolio_dir') . $image;
         $imageInfos = getimagesize($absolutePath);
         $media->setType($imageInfos['mime'])->setFile($relativePath);
         $em = $this->getEntityManager();
         $em->persist($media);
         $em->flush();
         /** @var MediaRepository $mediaRepository */
         $mediaRepository = $em->getRepository('BigfootMediaBundle:Media');
         $mediaRepository->setMetadata($media, 'title', $name);
         $mediaRepository->setMetadata($media, 'width', $imageInfos[0]);
         $mediaRepository->setMetadata($media, 'height', $imageInfos[1]);
         $mediaRepository->setMetadata($media, 'size', $media->convertFileSize(filesize($absolutePath)));
         $em->flush();
         $json['success'] = true;
         $json['html'] = $this->container->get('twig')->render('BigfootMediaBundle:snippets:table_line.html.twig', array('line' => $media, 'used' => false));
     }
     return new Response(json_encode($json), 200, array('Content-Type', 'application/json'));
 }
Example #6
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getContainer()->get("doctrine")->getManager();
     $repository = $em->getRepository('Gedmo\\Translatable\\Entity\\Translation');
     $medias = array();
     // Media creation
     $media300x500 = new Media();
     $media300x500->setFile('fixtures/300x500.gif');
     $media300x500->setType('gif');
     $medias[] = $media300x500;
     $media400x300 = new Media();
     $media400x300->setFile('fixtures/400x300.gif');
     $media400x300->setType('gif');
     $medias[] = $media400x300;
     $media500x200 = new Media();
     $media500x200->setFile('fixtures/500x200.gif');
     $media500x200->setType('gif');
     $medias[] = $media500x200;
     $media800x600 = new Media();
     $media800x600->setFile('fixtures/800x600.gif');
     $media800x600->setType('gif');
     $medias[] = $media800x600;
     $em->persist($media300x500);
     $em->persist($media400x300);
     $em->persist($media500x200);
     $em->persist($media800x600);
     $media300x500 = new Media();
     $media300x500->setFile('fixtures/300x500.gif');
     $media300x500->setType('gif');
     $medias[] = $media300x500;
     $media400x300 = new Media();
     $media400x300->setFile('fixtures/400x300.gif');
     $media400x300->setType('gif');
     $medias[] = $media400x300;
     $media500x200 = new Media();
     $media500x200->setFile('fixtures/500x200.gif');
     $media500x200->setType('gif');
     $medias[] = $media500x200;
     $media800x600 = new Media();
     $media800x600->setFile('fixtures/800x600.gif');
     $media800x600->setType('gif');
     $medias[] = $media800x600;
     $em->persist($media300x500);
     $em->persist($media400x300);
     $em->persist($media500x200);
     $em->persist($media800x600);
     $media300x500 = new Media();
     $media300x500->setFile('fixtures/300x500.gif');
     $media300x500->setType('gif');
     $medias[] = $media300x500;
     $media400x300 = new Media();
     $media400x300->setFile('fixtures/400x300.gif');
     $media400x300->setType('gif');
     $medias[] = $media400x300;
     $media500x200 = new Media();
     $media500x200->setFile('fixtures/500x200.gif');
     $media500x200->setType('gif');
     $medias[] = $media500x200;
     $media800x600 = new Media();
     $media800x600->setFile('fixtures/800x600.gif');
     $media800x600->setType('gif');
     $medias[] = $media800x600;
     $em->persist($media300x500);
     $em->persist($media400x300);
     $em->persist($media500x200);
     $em->persist($media800x600);
     $media300x500 = new Media();
     $media300x500->setFile('fixtures/300x500.gif');
     $media300x500->setType('gif');
     $medias[] = $media300x500;
     $media400x300 = new Media();
     $media400x300->setFile('fixtures/400x300.gif');
     $media400x300->setType('gif');
     $medias[] = $media400x300;
     $media500x200 = new Media();
     $media500x200->setFile('fixtures/500x200.gif');
     $media500x200->setType('gif');
     $medias[] = $media500x200;
     $media800x600 = new Media();
     $media800x600->setFile('fixtures/800x600.gif');
     $media800x600->setType('gif');
     $medias[] = $media800x600;
     $em->persist($media300x500);
     $em->persist($media400x300);
     $em->persist($media500x200);
     $em->persist($media800x600);
     $media300x500 = new Media();
     $media300x500->setFile('fixtures/300x500.gif');
     $media300x500->setType('gif');
     $medias[] = $media300x500;
     $media400x300 = new Media();
     $media400x300->setFile('fixtures/400x300.gif');
     $media400x300->setType('gif');
     $medias[] = $media400x300;
     $media500x200 = new Media();
     $media500x200->setFile('fixtures/500x200.gif');
     $media500x200->setType('gif');
     $medias[] = $media500x200;
     $media800x600 = new Media();
     $media800x600->setFile('fixtures/800x600.gif');
     $media800x600->setType('gif');
     $medias[] = $media800x600;
     $em->persist($media300x500);
     $em->persist($media400x300);
     $em->persist($media500x200);
     $em->persist($media800x600);
     $em->flush();
     $hotels = $em->getRepository('SehBundle:Hotel')->findAll();
     foreach ($hotels as $hotel) {
         $hotel->setTranslatableLocale('en');
         $em->refresh($hotel);
         if ($hotel->getThumbnail() == null) {
             $nbRandom = rand(1, 4);
             if ($nbRandom == 1) {
                 $hotel->setThumbnail($media300x500->getId());
             } else {
                 if ($nbRandom == 2) {
                     $hotel->setThumbnail($media400x300->getId());
                 } else {
                     if ($nbRandom == 3) {
                         $hotel->setThumbnail($media500x200->getId());
                     } else {
                         $hotel->setThumbnail($media800x600->getId());
                     }
                 }
             }
         }
         if ($hotel->getMark() == null) {
             $randomMark = rand(10, 50) / 10;
             //                $hotel->setMark($randomMark);
         }
         if ($hotel->getGallery() == null) {
             $nbRandom = rand(1, 3);
             $tabGallery = array();
             if ($nbRandom == 1) {
                 for ($i = 0; $i < 5; $i++) {
                     $tabGallery[] = $medias[$i]->getId();
                 }
             } else {
                 if ($nbRandom == 2) {
                     for ($i = 0; $i < 10; $i++) {
                         $tabGallery[] = $medias[$i]->getId();
                     }
                 } else {
                     for ($i = 0; $i < 20; $i++) {
                         $tabGallery[] = $medias[$i]->getId();
                     }
                 }
             }
             $stringGallery = implode(';', $tabGallery);
             $hotel->setGallery($stringGallery);
         }
         if (!$hotel->getShortDescription()) {
             $hotel->setShortDescription('<p><strong>Lucc varius orci eget placerat auctor.</strong> Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse potenti. Sed sed consequat nibh, a molestie dolor. Nunc ultricies semper augue at auctor. Nulla fringilla lacus et laoreet posuere.</p>');
         }
         $repository->translate($hotel, 'shortDescription', 'fr', $hotel->getShortDescription());
         if (!$hotel->getLongDescription()) {
             $hotel->setLongDescription('<p><strong>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</strong> Quisque scelerisque ipsum sit amet ipsum tempor, nec ultricies mauris molestie. Vivamus vestibulum est et odio egestas, sit amet faucibus arcu elementum. Nulla auctor dapibus leo nec sodales. Suspendisse sit amet aliquet magna. Pellentesque nunc nibh, aliquet sodales egestas vitae, fermentum vitae arcu. Nullam sit amet nunc elit. Integer in ipsum augue. Nunc scelerisque commodo nisi. Nulla convallis, enim et suscipit hendrerit, metus tortor dignissim risus, quis interdum purus neque sed dolor. Sed eget imperdiet leo, id suscipit lectus. Quisque interdum purus non pretium vehicula. Quisque quis nisl vel velit pharetra porttitor. Vestibulum ut turpis adipiscing felis semper consectetur sit amet eget sem.<br />
         Sed euismod massa eget velit lacinia malesuada. Nulla egestas urna ac tellus rutrum, quis sodales tortor malesuada. Quisque ut pellentesque lacus. Sed ultricies ante quis porttitor suscipit. Maecenas rutrum neque nec dui fermentum hendrerit. Morbi non lacus mollis quam vestibulum pretium. Fusce mauris nisi, elementum in purus in, elementum posuere turpis. Vivamus tincidunt nisi nec tellus mattis, at eleifend nisl rhoncus. Donec blandit et dui in semper. Nulla volutpat id odio nec commodo. Quisque laoreet non magna vel luctus.</p>');
         }
         $repository->translate($hotel, 'longDescription', 'fr', $hotel->getLongDescription());
         if (!$hotel->getConvenience()) {
             $hotel->setConvenience('<h3 class="title3">Venir en voiture ?</h3><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Recusandae, hic, mollitia, vero quia at repellat architecto numquam obcaecati vel libero officia perspiciatis illo accusamus earum magni voluptatem fugiat ea alias.</p><h3 class="title3">Où se garer ?</h3><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Architecto, voluptas dicta alias veniam facere voluptatum doloremque cum natus consequatur maxime.</p>');
         }
         $repository->translate($hotel, 'convenience', 'fr', $hotel->getConvenience());
         if (!$hotel->getStars()) {
             //                $hotel->setStars('****');
         }
         $highlight = new HotelHighlight();
         $highlight->setTranslatableLocale('en')->setName('Lorem ipsum');
         $repository->translate($highlight, 'name', 'fr', $highlight->getName());
         $hotel->addHighlight($highlight);
         $em->persist($highlight);
         $em->persist($hotel);
     }
     $em->flush();
     $regions = $em->getRepository('SehBundle:Region')->findAll();
     foreach ($regions as $region) {
         $region->setTranslatableLocale('fr');
         $em->refresh($region);
         if (!$region->getName()) {
             $region->setTranslatableLocale('en');
             $em->refresh($region);
             if ($region->getName()) {
                 $repository->translate($region, 'name', 'fr', $region->getName());
             }
             $em->persist($region);
         }
     }
     $departments = $em->getRepository('SehBundle:Department')->findAll();
     foreach ($departments as $department) {
         $department->setTranslatableLocale('fr');
         $em->refresh($department);
         if (!$department->getName()) {
             $department->setTranslatableLocale('en');
             $em->refresh($department);
             if ($department->getName()) {
                 $repository->translate($department, 'name', 'fr', $department->getName());
             }
             $em->persist($department);
         }
     }
     $services = $em->getRepository('SehBundle:HotelService')->findAll();
     foreach ($services as $service) {
         $service->setTranslatableLocale('fr');
         $em->refresh($service);
         if (in_array($service->getSlug(), array('swimming-pool', 'restaurant'))) {
             $service->setUseInSearch(true);
         }
         if (!$service->getName()) {
             $service->setTranslatableLocale('en');
             $em->refresh($service);
             if ($service->getName()) {
                 $repository->translate($service, 'name', 'fr', $service->getName());
             }
         }
         $em->persist($service);
     }
     $em->flush();
 }
Example #7
0
 /**
  * Execute
  *
  * @param InputInterface  $input  input
  * @param OutputInterface $output output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('<info>Import hotel images</info>');
     try {
         $entityManager = $this->getEntityManager();
         $descriptorFilesDir = $this->getContainer()->getParameter('images_dir') . '/hotels/';
         $portfolioPath = $this->getContainer()->getParameter('bigfoot.core.upload_dir') . $this->getContainer()->getParameter('bigfoot.media.portfolio_dir');
         $webDir = $this->getContainer()->get('kernel')->getRootDir() . '/../web/';
         $mediaRepo = $entityManager->getRepository('BigfootMediaBundle:Media');
         $mediaUsageRepo = $entityManager->getRepository('BigfootMediaBundle:MediaUsage');
         $brands = $entityManager->getRepository('SehBundle:Brand')->findAll();
         /** @var ProgressHelper $progress */
         $progress = $this->getHelperSet()->get('progress');
         $progress->start($output, count($brands));
         /** @var Brand $brand */
         foreach ($brands as $brand) {
             $brandSlug = strtolower($brand->getArtsysID());
             $descriptorFile = sprintf('%s%s.csv', $descriptorFilesDir, $brandSlug);
             if (file_exists($descriptorFile)) {
                 $fp = fopen($descriptorFile, 'r');
                 while (($line = fgetcsv($fp, null, ';', '"')) !== false) {
                     list($reservitId, $fileName, $thumbnail) = $line;
                     $fileName = sprintf('%s%s/%s', $portfolioPath, $brandSlug, $fileName);
                     $fullFileName = $webDir . $fileName;
                     if (file_exists($fullFileName)) {
                         $newMedia = false;
                         if (!($media = $mediaRepo->findOneBy(array('file' => $fileName)))) {
                             $media = new Media();
                             $media->setFile($fileName);
                             $media->setType(pathinfo($fullFileName, PATHINFO_EXTENSION));
                             $entityManager->persist($media);
                             $entityManager->flush();
                             $newMedia = true;
                         }
                         if ($hotel = $entityManager->getRepository('SehBundle:Hotel')->findOneBy(array('reservitId' => $reservitId))) {
                             if ($newMedia or !($usageGallery = $mediaUsageRepo->findOneBy(array('mediaId' => $media, 'tableRef' => 'SehBundle:Hotel', 'columnRef' => 'gallery', 'elementId' => $hotel->getId())))) {
                                 $mediaUsage = new MediaUsage();
                                 $mediaUsage->setMediaId($media);
                                 $mediaUsage->setTableRef('SehBundle:Hotel');
                                 $mediaUsage->setColumnRef('gallery');
                                 $mediaUsage->setElementId($hotel->getId());
                                 $entityManager->persist($mediaUsage);
                             }
                             $existingGallery = $hotel->getGallery();
                             if (strpos($existingGallery, (string) $media->getId()) === false) {
                                 $hotel->setGallery($existingGallery ? $existingGallery . ';' . $media->getId() : $media->getId());
                                 $entityManager->persist($hotel);
                             }
                             if ($thumbnail and (!$hotel->getThumbnail() and ($newMedia or !($usageGallery = $mediaUsageRepo->findOneBy(array('mediaId' => $media, 'tableRef' => 'SehBundle:Hotel', 'columnRef' => 'thumbnail', 'elementId' => $hotel->getId())))))) {
                                 $mediaUsage = new MediaUsage();
                                 $mediaUsage->setMediaId($media);
                                 $mediaUsage->setTableRef('SehBundle:Hotel');
                                 $mediaUsage->setColumnRef('thumbnail');
                                 $mediaUsage->setElementId($hotel->getId());
                                 $entityManager->persist($mediaUsage);
                             }
                             if (!$hotel->getThumbnail()) {
                                 $hotel->setThumbnail($media->getId());
                                 $entityManager->persist($hotel);
                             }
                         }
                     }
                 }
             }
             $progress->advance();
         }
         $progress->finish();
         $output->writeln(' > <info>Cleaning</info>');
         $hotelRepo = $entityManager->getRepository('SehBundle:Hotel');
         /** @var Hotel $hotel */
         foreach ($hotelRepo->findAll() as $hotel) {
             $currentMediaIds = explode(';', $hotel->getGallery());
             $newMediaIds = array();
             foreach ($currentMediaIds as $mediaId) {
                 if ($mediaRepo->find($mediaId)) {
                     $newMediaIds[] = $mediaId;
                 }
             }
             if (array_diff($currentMediaIds, $newMediaIds)) {
                 $ids = null;
                 if ($newMediaIds) {
                     $ids = implode(';', $newMediaIds);
                 }
                 $hotel->setGallery($ids);
                 $entityManager->persist($hotel);
             }
         }
         $output->writeln(' > <info>Flushing</info>');
         $entityManager->flush();
         $output->writeln(' > <comment>OK</comment>');
     } catch (\Exception $e) {
         $output->writeln(' > <error>Erreur : ' . $e->getMessage() . '</error>');
     }
 }