getFormats() public méthode

public getFormats ( integer $id, string $fileName, array $storageOptions, integer $version, integer $subVersion, string $mimeType ) : array
$id integer
$fileName string
$storageOptions array
$version integer
$subVersion integer
$mimeType string
Résultat array
Exemple #1
0
 /**
  * @param Media $media
  *
  * @return Media
  */
 public function addFormatsAndUrl(Media $media)
 {
     // Set Formats
     $media->setFormats($this->formatManager->getFormats($media->getId(), $media->getName(), $media->getStorageOptions(), $media->getVersion(), $media->getMimeType()));
     // Set Version Urls
     $versionData = [];
     foreach ($media->getFile()->getFileVersions() as $fileVersion) {
         $versionData[$fileVersion->getVersion()] = [];
         $versionData[$fileVersion->getVersion()]['url'] = $this->getUrl($media->getId(), $fileVersion->getName(), $fileVersion->getVersion());
     }
     $media->setAdditionalVersionData($versionData);
     // Set Current Url
     if (isset($versionData[$media->getVersion()]) && isset($versionData[$media->getVersion()]['url'])) {
         $media->setUrl($versionData[$media->getVersion()]['url']);
     }
     return $media;
 }
Exemple #2
0
 /**
  * @param Media $media
  *
  * @return Media
  */
 public function addFormatsAndUrl(Media $media)
 {
     // Get preview image and set either preview thumbnails if set, else rendered images
     /** @var \Sulu\Bundle\MediaBundle\Entity\Media $previewImage */
     $previewImage = $media->getEntity()->getPreviewImage();
     if ($previewImage !== null) {
         /** @var FileVersion $latestVersion */
         $latestVersion = null;
         /** @var File $file */
         foreach ($previewImage->getFiles() as $file) {
             $latestVersion = $file->getLatestFileVersion();
             // currently only one file per media exists
             break;
         }
         if ($latestVersion !== null) {
             $media->setFormats($this->formatManager->getFormats($previewImage->getId(), $latestVersion->getName(), $latestVersion->getStorageOptions(), $latestVersion->getVersion(), $latestVersion->getMimeType()));
         }
     } else {
         $media->setFormats($this->formatManager->getFormats($media->getId(), $media->getName(), $media->getStorageOptions(), $media->getVersion(), $media->getMimeType()));
     }
     // Set Version Urls
     $versionData = [];
     foreach ($media->getFile()->getFileVersions() as $fileVersion) {
         $versionData[$fileVersion->getVersion()] = [];
         $versionData[$fileVersion->getVersion()]['url'] = $this->getUrl($media->getId(), $fileVersion->getName(), $fileVersion->getVersion());
     }
     $media->setAdditionalVersionData($versionData);
     // set properties
     $properties = $media->getFileVersion()->getProperties();
     if ($properties !== null) {
         $media->setProperties($properties);
     }
     // Set Current Url
     if (isset($versionData[$media->getVersion()]) && isset($versionData[$media->getVersion()]['url'])) {
         $media->setUrl($versionData[$media->getVersion()]['url']);
     }
     return $media;
 }
 /**
  * @param int         $mediaId
  * @param FileVersion $fileVersion
  * @param string      $locale
  *
  * @return array
  */
 protected function getPreviewsFromFileVersion($mediaId, $fileVersion, $locale)
 {
     $title = '';
     /*
      * @var FileVersionMeta
      */
     foreach ($fileVersion->getMeta() as $key => $meta) {
         if ($meta->getLocale() == $locale) {
             $title = $meta->getTitle();
             break;
         } elseif ($key == 0) {
             // fallback title
             $title = $meta->getTitle();
         }
     }
     $mediaFormats = $this->formatManager->getFormats($mediaId, $fileVersion->getName(), $fileVersion->getStorageOptions(), $fileVersion->getVersion(), $fileVersion->getMimeType());
     foreach ($mediaFormats as $formatName => $formatUrl) {
         if ($formatName == $this->collectionPreviewFormat) {
             return ['url' => $formatUrl, 'title' => $title];
             break;
         }
     }
     return [];
 }