setFileVersion() public method

Set fileVersion.
public setFileVersion ( FileVersion $fileVersion ) : FileVersionMeta
$fileVersion FileVersion
return FileVersionMeta
コード例 #1
0
ファイル: Media.php プロジェクト: kriswillis/sulu
 /**
  * @param bool $create
  *
  * @return FileVersionMeta
  */
 private function getMeta($create = false)
 {
     $locale = $this->locale;
     $metaCollection = $this->getFileVersion()->getMeta();
     // get meta only with this locale
     $metaCollectionFiltered = $metaCollection->filter(function ($meta) use($locale) {
         /** @var FileVersionMeta $meta */
         if ($meta->getLocale() == $locale) {
             return true;
         }
         return false;
     });
     // check if meta was found
     if ($metaCollectionFiltered->isEmpty()) {
         if ($create) {
             // create when not found
             $meta = new FileVersionMeta();
             $meta->setLocale($this->locale);
             $meta->setFileVersion($this->getFileVersion());
             $this->getFileVersion()->addMeta($meta);
             return $meta;
         }
         // return first when create false
         return $this->getFileVersion()->getDefaultMeta();
     }
     // return exists
     return $metaCollectionFiltered->first();
 }
コード例 #2
0
 private function createMediaWithTags($title, $collection, $mimeType, $type, $tags = [])
 {
     $media = new Media();
     $file = new File();
     $fileVersion = new FileVersion();
     $fileVersionMeta = new FileVersionMeta();
     $fileVersionMeta->setTitle($title);
     $fileVersionMeta->setLocale('de');
     $fileVersionMeta->setFileVersion($fileVersion);
     $fileVersion->addMeta($fileVersionMeta);
     $fileVersion->setVersion(1);
     $fileVersion->setName($title);
     $fileVersion->setSize(0);
     $fileVersion->setMimeType($mimeType);
     $fileVersion->setFile($file);
     $file->setVersion(1);
     $file->addFileVersion($fileVersion);
     $file->setMedia($media);
     $media->addFile($file);
     $media->setType($this->mediaTypes[$type]);
     $media->setCollection($this->collections[$collection]);
     foreach ($tags as $tag) {
         $fileVersion->addTag($this->tags[$tag]);
     }
     $this->em->persist($media);
     return $media;
 }
コード例 #3
0
 protected function createMedia($name)
 {
     $media = new Media();
     $media->setType($this->imageType);
     // create file
     $file = new File();
     $file->setVersion(1);
     $file->setMedia($media);
     // create file version
     $fileVersion = new FileVersion();
     $fileVersion->setVersion(1);
     $fileVersion->setName($name . '.jpeg');
     $fileVersion->setMimeType('image/jpg');
     $fileVersion->setFile($file);
     $fileVersion->setSize(1124214);
     $fileVersion->setDownloadCounter(2);
     $fileVersion->setChanged(new \DateTime('1937-04-20'));
     $fileVersion->setCreated(new \DateTime('1937-04-20'));
     $fileVersion->setStorageOptions('{"segment":"1","fileName":"' . $name . '.jpeg"}');
     if (!file_exists(__DIR__ . '/../../uploads/media/1')) {
         mkdir(__DIR__ . '/../../uploads/media/1', 0777, true);
     }
     copy($this->getImagePath(), __DIR__ . '/../../uploads/media/1/' . $name . '.jpeg');
     // create meta
     $fileVersionMeta = new FileVersionMeta();
     $fileVersionMeta->setLocale('en-gb');
     $fileVersionMeta->setTitle($name);
     $fileVersionMeta->setDescription($this->mediaDefaultDescription);
     $fileVersionMeta->setFileVersion($fileVersion);
     $fileVersion->addMeta($fileVersionMeta);
     $fileVersion->setDefaultMeta($fileVersionMeta);
     $file->addFileVersion($fileVersion);
     $media->addFile($file);
     $media->setCollection($this->collection);
     $this->em->persist($media);
     $this->em->persist($file);
     $this->em->persist($fileVersionMeta);
     $this->em->persist($fileVersion);
     $this->em->flush();
     return $media;
 }
コード例 #4
0
 private function createFileVersion(File $file, $title, $version)
 {
     $fileVersion = new FileVersion();
     $fileVersion->setName($title . '.png');
     $fileVersion->setVersion($version);
     $fileVersion->setSize(0);
     $fileVersion->setFile($file);
     $fileVersionMeta = new FileVersionMeta();
     $fileVersionMeta->setTitle($title);
     $fileVersionMeta->setLocale('en');
     $fileVersionMeta->setFileVersion($fileVersion);
     $this->em->persist($fileVersion);
     $this->em->persist($fileVersionMeta);
 }