Transforms an object (media) to a string (id).

@param Media|null $media

@return string
542811
public function transform($medias)
    {
        if (null === $medias) {
            return array();
        }

        $ids = array();
        foreach ($medias as $media) {
            $ids[] = $media->getId();
        }

        return implode(';', $ids);
    }
1310635
public function path($media, $format)
    {
        if (!$media) {
            return '';
        }

        $provider = $this->getProvider($media);

        $format = $provider->getFormatName($media, $format);

        return $provider->generatePublicUrl($media, $format);
    }
600142
public function setMedia($media)
    {
        if (is_string($media)) {
            $this->media = $media;
        } else {
            $msg = "Media must be a string, '" . gettype($media) . "' given.";
            throw new InvalidArgumentException($msg);
        }
    }
643349
public function getHtml(MediaInterface $media, $alias = null)
    {
        if ($media->getType() == $media::IMAGE) {
            $template = 'ApoutchikaMediaBundle:Render:image.html.twig';
        } elseif ($media->getType() == $media::VIDEO) {
            $template = 'ApoutchikaMediaBundle:Render:video.html.twig';
        } elseif ($media->getType() == $media::AUDIO) {
            $template = 'ApoutchikaMediaBundle:Render:audio.html.twig';
        } else {
            $template = 'ApoutchikaMediaBundle:Render:other.html.twig';
        }

        return $this->container->get('templating')->render($template, array(
            'media' => $media,
            'alias' => $alias,
            'url' => $this->getAbsoluteUrl($media, $alias),
        ));
    }
437330
protected function _encode($body) {
		$media = $this->_classes['media'];

		if ($media::type($this->_type)) {
			$encoded = $media::encode($this->_type, $body);
			$body = $encoded !== null ? $encoded : $body;
		}
		return $body;
	}
1021889
public function prepareMedia(Media $media)
    {
        if (null == $media->getUuid()) {
            $uuid = uniqid();
            $media->setUuid($uuid);
        }
        $video = new RemoteVideoHelper($media);
        $url = $video->getCode();
        //update thumbnail
        switch ($video->getType()) {
            case 'youtube':
                $code = $this->isolateYoutubeVideoCode($url);
                $video->setThumbnailUrl('http://img.youtube.com/vi/'.$code.'/0.jpg');
                break;
            case 'vimeo':
                $code = $this->isolateVimeoVideoCode($url);
                $xml = simplexml_load_file('http://vimeo.com/api/v2/video/'.$code.'.xml');
                $video->setThumbnailUrl((string) $xml->video->thumbnail_large);
                break;
            case 'dailymotion':
                $code = $this->isolateDailymotionVideoCode($url);
                $json = json_decode(file_get_contents('https://api.dailymotion.com/video/'.$code.'?fields=thumbnail_large_url'));
                $thumbnailUrl = $json->{'thumbnail_large_url'};
                /* dirty hack to fix urls for imagine */
                if (!$this->endsWith($thumbnailUrl, '.jpg') && !$this->endsWith($thumbnailUrl, '.png')) {
                    $thumbnailUrl = $thumbnailUrl.'&ext=.jpg';
                }
                $video->setThumbnailUrl($thumbnailUrl);
                break;
        }
    }
569595
protected function getExtension(MediaInterface $media)
    {
        $ext = $media->getExtension();
        if (!\is_string($ext) || \strlen($ext) < 3) {
            $ext = $this->defaultFormat;
        }

        return $ext;
    }
73652
public function getMedia($mediaId)
    {
        $em = $this->getEntityManager();

        $media = $em->getRepository('VictoireMediaBundle:Media')->find($mediaId);
        if (!$media) {
            throw new EntityNotFoundException('The id given for the media is not valid.');
        }

        return $media;
    }
422283
public function generateThumbUrl(MediaInterface $media)
    {
        $path = null;

        if ($media->getType() === MediaTypes::IMAGE) {
            $path = $this->cacheManager->getBrowserPath($media->getPath(), 'media_thumb');
        } else {
            $path = $this->generateFileThumb($media);
        }

        if (null === $path) {
            $path = '/bundles/ekynamedia/img/file.jpg';
        }

        return $path;
    }
45860
public function setData(Media $media)
    {
        $this->id = $media->getId();
        $this->title = $media->getTitle();
        $this->setFormats($media->getFormats());
        $this->url = $media->getUrl();
        $this->copyright = $media->getCopyright();

        return $this;
    }
262411
public function setMedia(\Amulen\MediaBundle\Entity\Media $media = null)
    {
        $this->media = $media;

        return $this;
    }
1022166
public function transform($object)
    {
        if (null === $object) {
            return '';
        }

        return current(array_values($this->om->getClassMetadata($this->entityName)->getIdentifierValues($object)));
    }
309322
public function getMedia()
    {
        if ($this->media === null) {
            $cache = $this->getMediaCache();

            // Use cached media if possible.
            $cacheKey = md5('media' . $this->getCacheKey());
            if (!$media = $cache->get($cacheKey)) {
                $media = new Media($this->getMediaFolder(), $this->getMediaOrder());
                $cache->set($cacheKey, $media);
            }
            $this->media = $media;
        }

        return $this->media;
    }
334814
public function getMediaFormatUrl(MediaInterface $media, $format)
    {
        $key = $media->getFilesystemName();

        if ($format != '' && MediaInterface::MEDIA_ORIGINAL != $format) {
            $key = $media->getAlternative($format);
        }

        return $this->getFileUrl($key);
    }
1160536
public function prepareMedia(Media $media)
    {
        if (null === $media->getUuid()) {
            $uuid = uniqid();
            $media->setUuid($uuid);
        }
        $video = new RemoteVideoHelper($media);
        $code = $video->getCode();
        //update thumbnail
        switch ($video->getType()) {
            case 'youtube':
                try {
                    if (@fopen('https://img.youtube.com/vi/'.$code.'/maxresdefault.jpg', 'r') === false) {
                        $video->setThumbnailUrl('https://img.youtube.com/vi/'.$code.'/0.jpg');
                    } else {
                        $video->setThumbnailUrl('https://img.youtube.com/vi/'.$code.'/maxresdefault.jpg');
                    }
                } catch (\Exception $e) {
                }

                break;
            case 'vimeo':
                try {
                    $xml = simplexml_load_file('https://vimeo.com/api/v2/video/' . $code . '.xml');
                    $video->setThumbnailUrl((string) $xml->video->thumbnail_large);
                } catch (\Exception $e) {
                }

                break;
            case 'dailymotion':
                try {
                    $json = json_decode(
                        file_get_contents('https://api.dailymotion.com/video/' . $code . '?fields=thumbnail_large_url')
                    );
                    $thumbnailUrl = $json->{'thumbnail_large_url'};
                    /* dirty hack to fix urls for imagine */
                    if (!$this->endsWith($thumbnailUrl, '.jpg') && !$this->endsWith($thumbnailUrl, '.png')) {
                        $thumbnailUrl = $thumbnailUrl . '&ext=.jpg';
                    }
                    $video->setThumbnailUrl($thumbnailUrl);
                } catch (\Exception $e) {
                }

                break;
        }
    }
816066
public function getMediaId(): \Psr\Http\Message\UriInterface
    {
        if (!$this->mediaId) {
            return new Uri();
        }

        return $this->mediaId;
    }
1185862
public function determineImageGenerator(Media $media)
    {
        return $media->getImageGenerators()
            ->map(function (string $imageGeneratorClassName) {
                return app($imageGeneratorClassName);
            })
            ->first(function (ImageGenerator $imageGenerator) use ($media) {
                return $imageGenerator->canConvert($media);
            });
    }