/** * Refreshes this asset after the Resource has been modified * * @return void */ public function refresh() { $adjustments = array(new ResizeImageAdjustment(array('maximumWidth' => $this->maximumWidth, 'maximumHeight' => $this->maximumHeight, 'ratioMode' => $this->ratioMode, 'allowUpScaling' => $this->allowUpScaling))); $processedImageInfo = $this->imageService->processImage($this->originalAsset->getResource(), $adjustments); $this->resource = $processedImageInfo['resource']; $this->width = $processedImageInfo['width']; $this->height = $processedImageInfo['height']; }
/** * @test */ public function findBySearchTermAndTagsReturnsFilteredResult() { $tag = new Tag('home'); $this->tagRepository->add($tag); $resource1 = $this->resourceManager->importResource(__DIR__ . '/../../Fixtures/Resources/license.txt'); $resource2 = $this->resourceManager->importResource(__DIR__ . '/../../Fixtures/Resources/417px-Mihaly_Csikszentmihalyi.jpg'); $asset1 = new Asset($resource1); $asset1->setTitle('asset for homepage'); $asset2 = new Asset($resource2); $asset2->setTitle('just another asset'); $asset2->addTag($tag); $this->assetRepository->add($asset1); $this->assetRepository->add($asset2); $this->persistenceManager->persistAll(); $this->persistenceManager->clearState(); $this->assertCount(2, $this->assetRepository->findBySearchTermOrTags('home', array($tag))); $this->assertCount(2, $this->assetRepository->findBySearchTermOrTags('homepage', array($tag))); $this->assertCount(1, $this->assetRepository->findBySearchTermOrTags('baz', array($tag))); // This is necessary to initialize all resource instances before the tables are deleted foreach ($this->assetRepository->findAll() as $asset) { $asset->getResource()->getSha1(); } }
/** * Constructs the object and sets default values for width and height */ public function __construct() { parent::__construct(); $this->width = -1; $this->height = -1; }
/** * @param Asset $asset * @param Workspace $workspace */ public function removeByAsset(Asset $asset, Workspace $workspace) { $assetNodeData = $this->findOneByAssetIdentifier($asset->getIdentifier(), $workspace); $this->remove($assetNodeData); }
/** * Tags an asset with a tag. * * No redirection and no response body, no flash message, for use by plupload (or similar). * * @param Asset $asset * @param Tag $tag * @return boolean */ public function tagAssetAction(Asset $asset, Tag $tag) { $success = false; if ($asset->addTag($tag)) { $this->assetRepository->update($asset); $success = true; } $this->view->assign('value', $success); }
/** * @param Asset $asset * @param MetaDataCollection $metaDataCollection */ protected function buildAssetMetaData(Asset $asset, MetaDataCollection $metaDataCollection) { $tags = []; /** @var \TYPO3\Media\Domain\Model\Tag $tagObject */ foreach ($asset->getTags() as $tagObject) { $tags[] = $tagObject->getLabel(); } $collections = []; /** @var \TYPO3\Media\Domain\Model\AssetCollection $collectionObject */ foreach ($asset->getAssetCollections() as $collectionObject) { $collections[] = $collectionObject->getTitle(); } $assetDto = new Dto\Asset(['Caption' => $asset->getCaption(), 'Identifier' => $asset->getIdentifier(), 'Title' => $asset->getTitle(), 'FileName' => $asset->getResource()->getFilename(), 'Collections' => $collections, 'Tags' => $tags, 'AssetObject' => $asset]); $metaDataCollection->set('asset', $assetDto); }
/** * @param Asset $asset * @param $tagLabels */ protected function assertAssetHasTags(Asset $asset, $tagLabels) { $tags = $asset->getTags(); $tagLabels = array_combine(array_values($tagLabels), array_values($tagLabels)); $expectedTagLabels = $tagLabels; foreach ($tags as $tag) { $this->assertArrayHasKey($tag->getLabel(), $expectedTagLabels); unset($expectedTagLabels[$tag->getLabel()]); } $this->assertCount(0, $expectedTagLabels); }
/** * Calculates image width and height from the image resource. * * @throws ImageFileException * @return void */ public function refresh() { $this->calculateDimensionsFromResource($this->resource); parent::refresh(); }
/** * @param Asset $asset * @param MetaDataCollection $metaDataCollection */ public function mapMetaData(Asset $asset, MetaDataCollection $metaDataCollection) { $contextVariables = array_merge($this->defaultContextVariables, $metaDataCollection->toArray()); if (isset($this->metaDataMappingConfiguration['title'])) { $asset->setTitle(substr((string) EelUtility::evaluateEelExpression($this->metaDataMappingConfiguration['title'], $this->eelEvaluator, $contextVariables), 0, 255)); } if (isset($this->metaDataMappingConfiguration['caption'])) { $asset->setCaption((string) EelUtility::evaluateEelExpression($this->metaDataMappingConfiguration['caption'], $this->eelEvaluator, $contextVariables)); } if (isset($this->metaDataMappingConfiguration['tags'])) { $tagLabels = EelUtility::evaluateEelExpression($this->metaDataMappingConfiguration['tags'], $this->eelEvaluator, $contextVariables); $tagLabels = array_unique($tagLabels); $tags = new ArrayCollection(); foreach ($tagLabels as $tagLabel) { if (trim($tagLabel) !== '') { $tags->add($this->getOrCreateTag(trim($tagLabel))); } } $asset->setTags($tags); } if (isset($this->metaDataMappingConfiguration['collections'])) { $collectionTitles = EelUtility::evaluateEelExpression($this->metaDataMappingConfiguration['collections'], $this->eelEvaluator, $contextVariables); $collectionTitles = array_unique($collectionTitles); $collections = new ArrayCollection(); foreach ($collectionTitles as $collectionTitle) { if (trim($collectionTitle) !== '') { $collections->add($this->getOrCreateCollection(trim($collectionTitle))); } } $asset->setAssetCollections($collections); } if (!$this->persistenceManager->isNewObject($asset)) { $this->assetRepository->update($asset); } }
/** * Refreshes this image variant: according to the added adjustments, a new image is rendered and stored as this * image variant's resource. * * @return void * @see getResource() */ public function refresh() { // Several refresh() calls might happen during one request. If that is the case, the Resource Manager can't know // that the first created resource object doesn't have to be persisted / published anymore. Thus we need to // delete the resource manually in order to avoid orphaned resource objects: if ($this->resource !== null) { $this->resourceManager->deleteResource($this->resource); } parent::refresh(); $this->renderResource(); }
/** * Constructs the object and sets default values for width and height * * @param FlowResource $resource */ public function __construct(FlowResource $resource) { parent::__construct($resource); $this->width = -1; $this->height = -1; }