/** * {@inheritdoc} * * @VirtualProperty */ public function getImage() { if (!array_key_exists('50x50', $thumbnails = $this->entity->getThumbnails())) { return; } return $thumbnails['50x50']; }
public function getMediaUrl(Media $media, $dispositionType = null) { if (!$dispositionType && !($dispositionType = $this->getDispositionTypeByMimeType($media->getMimeType()))) { $dispositionType = $this->default; } $url = $media->getUrl(); if ($dispositionType === ResponseHeaderBag::DISPOSITION_INLINE) { $url .= false === strpos($url, '?') ? '?inline=1' : '&inline=1'; } return $url; }
/** * Get the contacts avatar and return the array of different formats. * * @return Media * * @VirtualProperty * @SerializedName("avatar") * @Groups({"fullContact","partialContact"}) */ public function getAvatar() { if ($this->avatar) { return ['id' => $this->avatar->getId(), 'url' => $this->avatar->getUrl(), 'thumbnails' => $this->avatar->getFormats()]; } return; }
/** * Get the accounts logo and return the array of different formats. * * @return Media * * @VirtualProperty * @SerializedName("logo") * @Groups({"fullAccount"}) */ public function getLogo() { if ($this->logo) { return ['id' => $this->logo->getId(), 'url' => $this->logo->getUrl(), 'thumbnails' => $this->logo->getFormats()]; } return; }
/** * @dataProvider provideIndex */ public function testIndex($format, $expectedException) { if ($expectedException) { $this->setExpectedException($expectedException); } $this->media->setFormats([$format => 'myimage.jpg']); $testAdapter = $this->container->get('massive_search.adapter.test'); $document = $this->documentManager->create('page'); $document->setTitle('Hallo'); $document->setResourceSegment('/hallo/fo'); $document->setStructureType('images'); $document->setParent($this->webspaceDocument); $document->getStructure()->bind(['images' => $this->mediaSelectionContainer->reveal()], false); $this->documentManager->persist($document, 'de'); $this->documentManager->flush(); $documents = $testAdapter->getDocuments(); $this->assertCount(1, $documents); $document = current($documents); $this->assertInstanceOf('Massive\\Bundle\\SearchBundle\\Search\\Document', $document); $this->assertEquals('myimage.jpg', $document->getImageUrl()); }
/** * @param Media $media * * @return Media */ public function addFormatsAndUrl(Media $media) { // Get preview image and set either preview thumbnails if set, else rendered images /** @var \Sulu\Bundle\MediaBundle\Entity\Media $previewImage */ $previewImage = $media->getEntity()->getPreviewImage(); if ($previewImage !== null) { /** @var FileVersion $latestVersion */ $latestVersion = null; /** @var File $file */ foreach ($previewImage->getFiles() as $file) { $latestVersion = $file->getLatestFileVersion(); // currently only one file per media exists break; } if ($latestVersion !== null) { $media->setFormats($this->formatManager->getFormats($previewImage->getId(), $latestVersion->getName(), $latestVersion->getStorageOptions(), $latestVersion->getVersion(), $latestVersion->getMimeType())); } } else { $media->setFormats($this->formatManager->getFormats($media->getId(), $media->getName(), $media->getStorageOptions(), $media->getVersion(), $media->getMimeType())); } // Set Version Urls $versionData = []; foreach ($media->getFile()->getFileVersions() as $fileVersion) { $versionData[$fileVersion->getVersion()] = []; $versionData[$fileVersion->getVersion()]['url'] = $this->getUrl($media->getId(), $fileVersion->getName(), $fileVersion->getVersion()); } $media->setAdditionalVersionData($versionData); // set properties $properties = $media->getFileVersion()->getProperties(); if ($properties !== null) { $media->setProperties($properties); } // Set Current Url if (isset($versionData[$media->getVersion()]) && isset($versionData[$media->getVersion()]['url'])) { $media->setUrl($versionData[$media->getVersion()]['url']); } return $media; }
private function serialize(Media $media) { return ['id' => $media->getId(), 'title' => $media->getTitle(), 'tags' => array_map(function ($tag) { return $tag->getName(); }, $media->getTags())]; }
/** * Returns true when collection of media contains media with specific id * * @param Media $media * @return bool */ public function containsMedia(Media $media) { return $this->entity->getMedia()->contains($media->getEntity()); }
/** * @param Media $media * * @return Media */ public function addFormatsAndUrl(Media $media) { // Set Formats $media->setFormats($this->formatManager->getFormats($media->getId(), $media->getName(), $media->getStorageOptions(), $media->getVersion(), $media->getMimeType())); // Set Version Urls $versionData = []; foreach ($media->getFile()->getFileVersions() as $fileVersion) { $versionData[$fileVersion->getVersion()] = []; $versionData[$fileVersion->getVersion()]['url'] = $this->getUrl($media->getId(), $fileVersion->getName(), $fileVersion->getVersion()); } $media->setAdditionalVersionData($versionData); // Set Current Url if (isset($versionData[$media->getVersion()]) && isset($versionData[$media->getVersion()]['url'])) { $media->setUrl($versionData[$media->getVersion()]['url']); } return $media; }