/**
  * @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);
 }
 /**
  * @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;
 }
 /**
  * @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:audio.html.twig', array('media_url' => $this->getFileUrl($media->getFilesystemName()), 'media_type' => $media->getMimeType(), 'id' => $options['id'], 'class' => $options['class'], 'style' => $options['style']));
 }
 /**
  * Delete all aternatives of $media
  *
  * @param MediaInterface $media
  */
 public function deleteAlternatives(MediaInterface $media)
 {
     $this->deleteFile($media->getFilesystemName());
 }
 /**
  * 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
  * @param string         $format
  *
  * @return String
  */
 public function displayMedia(MediaInterface $media, $format = '')
 {
     return $this->render('OpenOrchestraMediaBundle:BBcode/FullDisplay:audio.html.twig', array('media_url' => $this->getFileUrl($media->getFilesystemName()), 'media_type' => $media->getMimeType()));
 }