/**
  * @param MediaInterface $media
  * @param string         $format
  *
  * @return string
  */
 public function getMediaFormatUrl(MediaInterface $media, $format)
 {
     $key = $media->getFilesystemName();
     if ($format != '' && MediaInterface::MEDIA_ORIGINAL != $format) {
         $key = $media->getAlternative($format);
     }
     return $this->getFileUrl($key);
 }
 /**
  * Generate a thumbnail for $media
  *
  * @param MediaInterface $media
  */
 public function generateThumbnail(MediaInterface $media)
 {
     $fileName = $media->getFilesystemName();
     $thumbnailName = '';
     $extractedImagePath = $this->imageManager->extractImageFromPdf($this->tmpDir . DIRECTORY_SEPARATOR . $fileName);
     $thumbnailPath = $this->imageManager->generateAlternative($extractedImagePath, $this->thumbnailFormat);
     if ($thumbnailPath != '') {
         $thumbnailName = self::THUMBNAIL_PREFIX . '-' . str_replace('.pdf', '.jpg', $fileName);
         $this->mediaStorageManager->uploadFile($thumbnailName, $thumbnailPath);
     }
     if (trim($extractedImagePath, DIRECTORY_SEPARATOR) != trim($this->tmpDir, DIRECTORY_SEPARATOR)) {
         $this->fileSystem->remove(array($extractedImagePath));
     }
     $media->setThumbnail($thumbnailName);
 }
 /**
  * Generate a thumbnail for $media
  *
  * @param MediaInterface $media
  */
 public function generateThumbnail(MediaInterface $media)
 {
     $fileName = $media->getFilesystemName();
     $thumbnailName = '';
     $extractedImagePath = $this->videoManager->extractImageFromVideo($this->tmpDir . DIRECTORY_SEPARATOR . $fileName, 1);
     $thumbnailPath = $this->imageManager->generateAlternative($extractedImagePath, $this->thumbnailFormat);
     if ('' !== $thumbnailPath) {
         $thumbnailName = self::THUMBNAIL_PREFIX . '-' . pathinfo($fileName, PATHINFO_FILENAME) . '.jpg';
         $this->mediaStorageManager->uploadFile($thumbnailName, $thumbnailPath);
     }
     if (trim($extractedImagePath, DIRECTORY_SEPARATOR) !== trim($this->tmpDir, DIRECTORY_SEPARATOR)) {
         $this->fileSystem->remove(array($extractedImagePath));
     }
     $media->setThumbnail($thumbnailName);
 }
 /**
  * Invalidate cache on $mediaId
  * 
  * @param MediaInterface $media
  */
 protected function invalidate($media)
 {
     $tags = array($this->tagManager->formatMediaIdTag($media->getId()));
     $nodeUsage = $media->getUseReferences(NodeInterface::ENTITY_TYPE);
     foreach ($nodeUsage as $nodeId) {
         $tags[] = $this->tagManager->formatNodeIdTag($nodeId);
     }
     $contentUsage = $media->getUseReferences(ContentInterface::ENTITY_TYPE);
     foreach ($contentUsage as $contentId) {
         $tags[] = $this->tagManager->formatContentIdTag($contentId);
     }
     $contentTypeUsage = $media->getUseReferences(ContentTypeInterface::ENTITY_TYPE);
     foreach ($contentTypeUsage as $contentTypeId) {
         $tags[] = $this->tagManager->formatContentTypeTag($contentTypeId);
     }
     $this->cacheableManager->invalidateTags($tags);
 }
 /**
  * Save a media in database
  *
  * @param MediaInterface $media
  */
 public function saveMedia($media)
 {
     $file = $media->getFile();
     $this->mediaStorageManager->uploadFile($file->getFilename(), $file->getRealPath(), false);
     $this->objectManager->persist($media);
     $this->objectManager->flush();
     $event = new MediaEvent($media);
     $this->dispatcher->dispatch(MediaEvents::MEDIA_ADD, $event);
 }
 /**
  * @param MediaInterface $media
  *
  * @param MediaInterface $media
  * @param string         $format
  * @param string         $style
  *
  * @return string
  */
 public function displayMediaForWysiwyg(MediaInterface $media, $format = '', $style = '')
 {
     return $this->render('OpenOrchestraMediaBundle:BBcode/WysiwygDisplay:audio.html.twig', array('media_id' => $media->getId(), 'style' => $style));
 }
 /**
  * Delete all aternatives of $media
  *
  * @param MediaInterface $media
  */
 public function deleteAlternatives(MediaInterface $media)
 {
     $this->deleteFile($media->getFilesystemName());
 }
 /**
  * @param MediaInterface $media
  *
  *  @param MediaInterface $media
  *  @param string         $format
  *  
  * @return string
  */
 public function displayMediaForWysiwyg(MediaInterface $media, $format = '')
 {
     return $this->render('OpenOrchestraMediaBundle:BBcode/WysiwygDisplay:thumbnail.html.twig', array('media_url' => $this->getFileUrl($media->getThumbnail()), 'media_alt' => $media->getAlt($this->request->getLocale()), 'media_id' => $media->getId()));
 }
 /**
  * @param MediaInterface $mixed
  *
  * @return FacadeInterface
  */
 public function transform($mixed)
 {
     $facade = $this->newFacade();
     $facade->id = $mixed->getId();
     $facade->name = $mixed->getName();
     $facade->mimeType = $mixed->getMimeType();
     $mediaFolder = $mixed->getMediaFolder();
     $facade->isDeletable = !$mixed->isUsed() && $this->authorizationChecker->isGranted(TreeFolderPanelStrategy::ROLE_ACCESS_DELETE_MEDIA, $mediaFolder);
     $facade->alt = $this->multiLanguageChoiceManager->choose($mixed->getAlts());
     $facade->title = $this->multiLanguageChoiceManager->choose($mixed->getTitles());
     $facade->original = $this->generateMediaUrl($mixed->getFilesystemName());
     $facade->thumbnail = $this->generateMediaUrl($mixed->getThumbnail());
     if ($this->hasGroup(MediaAdminGroupContext::MEDIA_ALTERNATIVES)) {
         $alternatives = $mixed->getAlternatives();
         foreach ($alternatives as $format => $alternativeName) {
             $facade->addAlternative($format, $this->generateMediaUrl($alternativeName));
             $facade->addLink('_self_format_' . $format, $this->generateRoute('open_orchestra_media_admin_media_override', array('format' => $format, 'mediaId' => $mixed->getId())));
         }
     }
     $facade->isEditable = false;
     if ($this->authorizationChecker->isGranted(TreeFolderPanelStrategy::ROLE_ACCESS_UPDATE_MEDIA, $mediaFolder)) {
         $facade->isEditable = true;
     }
     $facade->addLink('_self_select', $mixed->getId());
     $facade->addLink('_api_full', $this->generateRoute('open_orchestra_api_media_show', array('mediaId' => $mixed->getId())));
     if ($this->hasGroup(MediaAdminGroupContext::MEDIA_ADVANCED_LINKS)) {
         $facade->addLink('_self_select_format', $this->generateRoute('open_orchestra_media_admin_media_select_format', array('mediaId' => $mixed->getId())));
         if ($facade->isEditable) {
             $facade->addLink('_self_crop', $this->generateRoute('open_orchestra_media_admin_media_crop', array('mediaId' => $mixed->getId())));
             $facade->addLink('_self_meta', $this->generateRoute('open_orchestra_media_admin_media_meta', array('mediaId' => $mixed->getId())));
         }
     }
     if ($facade->isDeletable) {
         $facade->addLink('_self_delete', $this->generateRoute('open_orchestra_api_media_delete', array('mediaId' => $mixed->getId())));
     }
     return $facade;
 }
 /**
  * Crop $media original file with ($x, $y, $h, $w) and resize it to the $formatName
  *
  * @param MediaInterface $media
  * @param int            $x
  * @param Int            $y
  * @param Int            $h
  * @param Int            $w
  * @param string         $formatName
  */
 public function cropAlternative(MediaInterface $media, $x, $y, $h, $w, $formatName)
 {
     $originalFilePath = $this->mediaStorageManager->downloadFile($media->getFilesystemName(), $this->tmpDir);
     $croppedFilePath = $this->imageManager->cropAndResize($originalFilePath, $x, $y, $h, $w, $this->alternativeFormats[$formatName]);
     $this->overrideAlternative($media, $croppedFilePath, $formatName);
     $this->fileSystem->remove(array($originalFilePath));
 }
 /**
  * @param MediaInterface $media
  */
 public function generateThumbnail(MediaInterface $media)
 {
     $media->setThumbnail($this->thumbnail);
 }
 /**
  * @param MediaInterface $media
  * @param array          $expectedReference
  */
 protected function checkMediaReference($media, $expectedReference)
 {
     $references = $media->getUseReferences();
     $this->assertEquals($references, $expectedReference);
 }
 /**
  * @param MediaInterface $media
  * @param string         $format
  *
  * @return String
  */
 public function displayMedia(MediaInterface $media, $format = '')
 {
     return $this->render('OpenOrchestraMediaBundle:BBcode/FullDisplay:video.html.twig', array('media_url' => $this->getFileUrl($media->getFilesystemName()), 'media_type' => $media->getMimeType()));
 }
 /**
  * @param MediaInterface $media
  * @param array          $options
  *
  * @return String
  */
 public function renderMedia(MediaInterface $media, array $options)
 {
     $options = $this->validateOptions($options, __METHOD__);
     return $this->render('OpenOrchestraMediaBundle:RenderMedia:default.html.twig', array('media_url' => $this->getFileUrl($media->getFilesystemName()), 'media_name' => $media->getName(), 'id' => $options['id'], 'class' => $options['class'], 'style' => $options['style']));
 }
 /**
  * @param string         $message
  * @param MediaInterface $media
  */
 protected function mediaInfo($message, MediaInterface $media)
 {
     $this->logger->info($message, array('media_name' => $media->getName()));
 }