Exemplo n.º 1
0
 /**
  * @param Node $galleryNode
  * @return \TYPO3\Flow\Persistence\QueryResultInterface
  */
 protected function selectImages(Node $galleryNode)
 {
     $tagIdentifier = $galleryNode->getProperty('tag');
     $tag = $this->tagRepository->findByIdentifier($tagIdentifier);
     /** @var \TYPO3\Media\Domain\Model\Tag $tag */
     $images = $this->imageRepository->findByTag($tag);
     return $images;
 }
 /**
  * Upload a new image, and return its metadata.
  *
  * Depending on the $metadata argument it will return asset metadata for the AssetEditor
  * or image metadata for the ImageEditor
  *
  * @param Asset $asset
  * @param string $metadata Type of metadata to return ("Asset" or "Image")
  * @return string
  */
 public function uploadAssetAction(Asset $asset, $metadata)
 {
     $this->response->setHeader('Content-Type', 'application/json');
     /** @var Site $currentSite */
     $currentSite = $this->siteRepository->findOneByNodeName($this->request->getInternalArgument('__siteNodeName'));
     if ($currentSite !== null && $currentSite->getAssetCollection() !== null) {
         $currentSite->getAssetCollection()->addAsset($asset);
         $this->assetCollectionRepository->update($currentSite->getAssetCollection());
     }
     switch ($metadata) {
         case 'Asset':
             $result = $this->getAssetProperties($asset);
             if ($this->persistenceManager->isNewObject($asset)) {
                 $this->assetRepository->add($asset);
             }
             break;
         case 'Image':
             $result = $this->getImageInterfacePreviewData($asset);
             if ($this->persistenceManager->isNewObject($asset)) {
                 $this->imageRepository->add($asset);
             }
             break;
         default:
             $this->response->setStatus(400);
             $result = array('error' => 'Invalid "metadata" type: ' . $metadata);
     }
     return json_encode($result);
 }
 /**
  * @param string $title
  * @param array $tagLabels
  * @return void
  */
 protected function removePreviousProfilePictureBasedOnTags($title, array $tagLabels)
 {
     $images = $this->imageRepository->findBySearchTermOrTags($title, $tagLabels);
     foreach ($images as $image) {
         $this->imageRepository->remove($image);
     }
 }
 protected function importImage($filename)
 {
     $resource = $this->resourceManager->importResource($filename);
     $image = new Image($resource);
     $this->imageRepository->add($image);
     $processingInstructions = array();
     return $this->objectManager->get('TYPO3\\Media\\Domain\\Model\\ImageVariant', $image, $processingInstructions);
 }
 /**
  * @param FluidView $view
  * @return void
  */
 public function initializeView(FluidView $view)
 {
     $assets = $this->tsValue('assets');
     $processedAssets = array();
     /** @var Asset $asset */
     if (is_array($assets)) {
         foreach ($assets as $asset) {
             if ($asset->getResource() === null) {
                 if ($asset instanceof Image) {
                     $processedAssets[] = $this->imageRepository->findByIdentifier($asset->getIdentifier());
                 } elseif ($asset instanceof Asset) {
                     $processedAssets[] = $this->assetRepository->findByIdentifier($asset->getIdentifier());
                 }
             } else {
                 $processedAssets[] = $asset;
             }
         }
     }
     $view->assign('assets', $processedAssets);
 }
 /**
  * Converts the given $objectXml to an ImageVariant instance and returns it
  *
  * @param \SimpleXMLElement $objectXml
  * @param string $className the concrete class name of the ImageVariant to create (ImageVariant or a subclass)
  * @return ImageVariant
  * @throws NeosException
  */
 protected function importImageVariant(\SimpleXMLElement $objectXml, $className)
 {
     $processingInstructions = unserialize(trim((string) $objectXml->processingInstructions));
     if (isset($objectXml->originalImage['__identifier'])) {
         $image = $this->imageRepository->findByIdentifier((string) $objectXml->originalImage['__identifier']);
         if (is_object($image)) {
             return $this->objectManager->get($className, $image, $processingInstructions);
         }
     }
     $resourceHash = (string) $objectXml->originalImage->resource->hash;
     $resourceData = trim((string) $objectXml->originalImage->resource->content);
     if ((string) $objectXml->originalImage->resource['__identifier'] !== '') {
         $resource = $this->persistenceManager->getObjectByIdentifier((string) $objectXml->originalImage->resource['__identifier'], 'TYPO3\\Flow\\Resource\\Resource');
     }
     if (!isset($resource) || $resource === null) {
         $resource = $this->importResource((string) $objectXml->originalImage->resource->filename, $resourceHash !== '' ? $resourceHash : null, !empty($resourceData) ? $resourceData : null, (string) $objectXml->originalImage->resource['__identifier'] !== '' ? (string) $objectXml->originalImage->resource['__identifier'] : null);
     }
     $image = new Image($resource);
     if ((string) $objectXml->originalImage['__identifier'] !== '') {
         ObjectAccess::setProperty($image, 'Persistence_Object_Identifier', (string) $objectXml->originalImage['__identifier'], true);
     }
     $this->imageRepository->add($image);
     return $this->objectManager->get($className, $image, $processingInstructions);
 }
Exemplo n.º 7
0
 /**
  * Upload a new image, and return its metadata.
  *
  * @param \TYPO3\Media\Domain\Model\Image $image
  * @return string
  */
 public function uploadImageAction(\TYPO3\Media\Domain\Model\Image $image)
 {
     $this->imageRepository->add($image);
     return $this->imageWithMetadataAction($image);
 }
 /**
  * @return ImageVariant
  */
 protected function getRandommImageVariant()
 {
     $image = new Image($this->resourceManager->importResource(sprintf('resource://Flowpack.NodeGenerator/Private/Images/Sample%d.jpg', rand(1, 3))));
     $this->imageRepository->add($image);
     return $image->createImageVariant(array(array('command' => 'thumbnail', 'options' => array('size' => array('width' => 1500, 'height' => 1024)))));
 }
Exemplo n.º 9
0
 /**
  * Updates the given news object
  *
  * @param \Lelesys\Plugin\News\Domain\Model\News $news The news to update
  * @param array $media  News media
  * @param array $file News file
  * @param array $tags News tags
  * @param array $relatedLink News related links
  * @return void
  */
 public function update(\Lelesys\Plugin\News\Domain\Model\News $news, $media, $file, $relatedLink, $tags)
 {
     if (!empty($tags['title'])) {
         $tagsArray = array_unique(\TYPO3\Flow\Utility\Arrays::trimExplode(',', strtolower($tags['title'])));
         foreach ($tagsArray as $tag) {
             $existTag = $this->tagService->findTagByName($tag);
             if (!empty($existTag)) {
                 $newsTags = $news->getTags()->toArray();
                 if (!in_array($existTag, $newsTags)) {
                     $news->addTags($existTag);
                 }
             } else {
                 $newTag = new \Lelesys\Plugin\News\Domain\Model\Tag();
                 $newTag->setTitle($tag);
                 $this->tagService->create($newTag);
                 $news->addTags($newTag);
             }
         }
     }
     $news->setUpdatedDate(new \DateTime());
     $mediaPath = $media;
     foreach ($mediaPath as $mediaSource) {
         if (!empty($mediaSource['uuid'])) {
             $updateAsset = $this->propertyMapper->convert($mediaSource['uuid']['__identity'], '\\TYPO3\\Media\\Domain\\Model\\Image');
             $updateAsset->setCaption($mediaSource['caption']);
             $this->imageRepository->update($updateAsset);
         } else {
             if (!empty($mediaSource['resource']['name'])) {
                 $resource = $this->propertyMapper->convert($mediaSource['resource'], 'TYPO3\\Flow\\Resource\\Resource');
                 $media = new \TYPO3\Media\Domain\Model\Image($resource);
                 $media->setCaption($mediaSource['caption']);
                 $this->imageRepository->add($media);
                 $news->addAssets($media);
             }
         }
     }
     $filePath = $file;
     foreach ($filePath as $fileSource) {
         if (isset($fileSource['uuid'])) {
             $updateFile = $this->propertyMapper->convert($fileSource['uuid']['__identity'], '\\TYPO3\\Media\\Domain\\Model\\Document');
             $updateFile->setTitle($fileSource['title']);
             $this->assetRepository->update($updateFile);
         } else {
             if (!empty($fileSource['resource']['name'])) {
                 $resource = $this->propertyMapper->convert($fileSource['resource'], 'TYPO3\\Flow\\Resource\\Resource');
                 $file = new \TYPO3\Media\Domain\Model\Document($resource);
                 $file->setTitle($fileSource['title']);
                 $this->assetRepository->add($file);
                 $news->addFiles($file);
             }
         }
     }
     $related = $relatedLink;
     foreach ($related as $link) {
         if (isset($link['uuid'])) {
             $updateLink = $this->linkService->findById($link['uuid']);
             $updateLink->setUri($link['relatedUri']);
             $updateLink->setTitle($link['relatedUriTitle']);
             $updateLink->setDescription($link['relatedUriDescription']);
             $updateLink->setHidden($link['hidden']);
             $this->linkService->update($updateLink);
         } else {
             if (!empty($link['relatedUri'])) {
                 $newLink = new \Lelesys\Plugin\News\Domain\Model\Link();
                 $newLink->setTitle($link['relatedUriTitle']);
                 $newLink->setUri($link['relatedUri']);
                 $newLink->setDescription($link['relatedUriDescription']);
                 $newLink->setHidden($link['hidden']);
                 $this->linkService->create($newLink);
                 $news->addRelatedLinks($newLink);
             }
         }
     }
     $this->newsRepository->update($news);
     $this->emitNewsUpdated($news);
 }