getFileVersion() public method

public getFileVersion ( ) : FileVersion
return Sulu\Bundle\MediaBundle\Entity\FileVersion
Beispiel #1
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;
 }