setCollection() публичный Метод

Set collection.
public setCollection ( Sulu\Bundle\MediaBundle\Entity\CollectionInterface $collection ) : Media
$collection Sulu\Bundle\MediaBundle\Entity\CollectionInterface
Результат Media
Пример #1
0
 public function initLogo()
 {
     $collectionType = new CollectionType();
     $collectionType->setName('My collection type');
     $this->em->persist($collectionType);
     $collection = new Collection();
     $collection->setType($collectionType);
     $this->em->persist($collection);
     $imageType = new MediaType();
     $imageType->setName('image');
     $imageType->setDescription('This is an image');
     $this->em->persist($imageType);
     $file = new File();
     $file->setVersion(1);
     $fileVersion = new FileVersion();
     $fileVersion->setVersion(1);
     $fileVersion->setName('logo.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'));
     $file->addFileVersion($fileVersion);
     $this->em->persist($fileVersion);
     $this->logo = new Media();
     $this->logo->setType($imageType);
     $this->logo->setCollection($collection);
     $this->logo->addFile($file);
     $file->setMedia($this->logo);
     $this->em->persist($this->logo);
     $this->em->persist($file);
 }
 private function createFile($oldTitle, $newTitle, $collection = null)
 {
     $media = new Media();
     $media->setType($this->mediaType);
     $media->setCollection($collection ?: $this->collection);
     $file = new File();
     $file->setVersion(2);
     $file->setMedia($media);
     $this->createFileVersion($file, $oldTitle, 1);
     $this->createFileVersion($file, $newTitle, 2);
     $this->em->persist($file);
     $this->em->persist($media);
 }