public function setUpMediaEntities()
 {
     $mediaType = new MediaType();
     $mediaType->setName('document');
     $mediaType->setDescription('This is a document');
     $imageType = new MediaType();
     $imageType->setName('image');
     $imageType->setDescription('This is an image');
     $videoType = new MediaType();
     $videoType->setName('video');
     $videoType->setDescription('This is a video');
     $audioType = new MediaType();
     $audioType->setName('audio');
     $audioType->setDescription('This is an audio');
     $media = new Media();
     $media->setType($imageType);
     $this->media = $media;
     $media2 = new Media();
     $media2->setType($imageType);
     $this->media2 = $media2;
     $this->account->addMedia($media2);
     // create file
     $file = new File();
     $file->setVersion(1);
     $file->setMedia($media);
     $file2 = new File();
     $file2->setVersion(1);
     $file2->setMedia($media2);
     // create file version
     $fileVersion = new FileVersion();
     $fileVersion->setVersion(1);
     $fileVersion->setName('photo.jpeg');
     $fileVersion->setMimeType('image/jpg');
     $fileVersion->setFile($file);
     $fileVersion->setSize(1124214);
     $fileVersion->setDownloadCounter(2);
     $fileVersion->setStorageOptions('{"segment":"1","fileName":"photo.jpeg"}');
     $file->addFileVersion($fileVersion);
     // create file version
     $fileVersion = new FileVersion();
     $fileVersion->setVersion(1);
     $fileVersion->setName('photo.jpeg');
     $fileVersion->setMimeType('image/jpg');
     $fileVersion->setFile($file2);
     $fileVersion->setSize(1124214);
     $fileVersion->setDownloadCounter(2);
     $fileVersion->setStorageOptions('{"segment":"1","fileName":"photo.jpeg"}');
     $file2->addFileVersion($fileVersion);
     $collection = new Collection();
     $this->setUpCollection($collection);
     $media->setCollection($collection);
     $media2->setCollection($collection);
     $this->em->persist($media);
     $this->em->persist($media2);
     $this->em->persist($collection);
     $this->em->persist($file);
     $this->em->persist($file2);
     $this->em->persist($videoType);
     $this->em->persist($imageType);
     $this->em->persist($audioType);
     $this->em->persist($mediaType);
 }
Example #2
0
 /**
  * Sets the medias of the given account to the given medias.
  * Currently associated medias are replaced.
  *
  * @param Account $account
  * @param $medias
  *
  * @throws EntityNotFoundException
  */
 public function setMedias(Account $account, $medias)
 {
     $mediaIds = array_map(function ($media) {
         return $media['id'];
     }, $medias);
     $foundMedias = $this->mediaRepository->findById($mediaIds);
     $foundMediaIds = array_map(function ($mediaEntity) {
         return $mediaEntity->getId();
     }, $foundMedias);
     if ($missingMediaIds = array_diff($mediaIds, $foundMediaIds)) {
         throw new EntityNotFoundException($this->mediaRepository->getClassName(), reset($missingMediaIds));
     }
     $account->getMedias()->clear();
     foreach ($foundMedias as $media) {
         $account->addMedia($media);
     }
 }