Example #1
0
 /**
  * {@inheritdoc}
  */
 public function reverseTransform($ids)
 {
     if (!$ids) {
         return;
     }
     $repo = $this->mediaManager->getRepository();
     $media = $repo->createQueryBuilder('m')->where('m.id IN(:ids)')->setParameter('ids', $ids)->getQuery()->getResult();
     if (null === $media) {
         throw new TransformationFailedException(sprintf('A media item with id "%s" does not exist!', $id));
     }
     return $media;
 }
Example #2
0
 public function postFormSubmit(FormSubmitEvent $event)
 {
     $post = $event->getPost();
     $values = $post->getValueSet()->getValues();
     $this->entityManager->refresh($post);
     foreach ($values as $value) {
         if ($value instanceof AttachmentValue) {
             $media = $this->mediaManager->createMedia();
             $media->setFile($value->getFile());
             $media->setProvider('file');
             $value->setAttachment($media);
         }
     }
     $this->entityManager->persist($post);
     $this->entityManager->flush();
 }
Example #3
0
 /**
  * @param FormSubmitEvent $event
  */
 public function postFormSubmit(FormSubmitEvent $event)
 {
     $post = $event->getPost();
     $values = $post->getValueSet()->getValues();
     $this->entityManager->refresh($post);
     foreach ($values as $value) {
         if ($value instanceof AttachmentValue) {
             // Avoid saving the attachment when it's empty and not required
             if (null === $value->getFile() && !$value->getAttribute()->getRequired()) {
                 continue;
             }
             $media = $this->mediaManager->createMedia();
             $media->setFile($value->getFile());
             $media->setProvider('file');
             $value->setAttachment($media);
         }
     }
     $this->entityManager->persist($post);
     $this->entityManager->flush();
 }
Example #4
0
 /**
  * Save the thumbnail.
  *
  * @param MediaInterface $media The Youtube Object
  * @param string         $url
  *
  * @return MediaInterface The newly created image
  */
 public function saveThumbnail(MediaInterface $media, $url)
 {
     $thumb = $this->mediaManager->createMedia();
     $thumb->setStatus(Media::STATUS_HASPARENT)->setName($media->getName() . '_thumb')->setProvider('image');
     $filename = '/tmp/' . basename($url);
     $filesystem = new Filesystem();
     $filesystem->dumpFile($filename, file_get_contents($url));
     $thumb->temp = $filename;
     $thumb->setFile(new UploadedFile($filename, basename($url)));
     $this->mediaManager->save($thumb);
     return $thumb;
 }