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

public setFormats ( array $formats )
$formats array
Пример #1
0
 /**
  * @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());
 }
Пример #2
0
 /**
  * @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;
 }
Пример #3
0
 /**
  * @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;
 }