/** * @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; }
/** * @param NodeInterface|null $node * @param array $arguments * @return \TYPO3\Flow\Persistence\QueryResultInterface */ public function getData(NodeInterface $node = null, array $arguments) { $tagCollection = $this->tagRepository->findAll(); $tags = []; foreach ($tagCollection as $tag) { /** @var \TYPO3\Media\Domain\Model\Tag $tag */ $tags[$this->persistenceManager->getIdentifierByObject($tag)] = $tag; } return $tags; }
/** * @test */ public function addTag() { $asset = $this->buildAssetObject(); $tag = new Tag('test'); $this->tagRepository->add($tag); $asset->addTag($tag); $this->persistenceManager->persistAll(); $this->persistenceManager->clearState(); $asset = $this->assetRepository->findAll()->getFirst(); $this->assertAssetHasTags($asset, ['test']); }
/** * Creates a user based on the given information * * The created user and account are automatically added to their respective repositories and thus be persisted. * * @param string $username The username of the user to be created. * @param string $password Password of the user to be created * @param string $firstName First name of the user to be created * @param string $lastName Last name of the user to be created * @param string $department department of the user to be created * @param string $photo photo of the user to be created * @param array $roleIdentifiers A list of role identifiers to assign * @param string $authenticationProviderName Name of the authentication provider to use. Example: "Typo3BackendProvider" * @return User The created user instance * @api */ public function createUserPhlu($username, $password, $firstName, $lastName, $department, $photo, array $roleIdentifiers = null, $authenticationProviderName = null) { $collection = $this->assetCollectionRepository->findByCollectionName('phluCollection2')->getFirst(); if (!$collection) { $collection = new \TYPO3\Media\Domain\Model\AssetCollection('phluCollection2'); $this->assetCollectionRepository->add($collection); $this->persistenceManager->persistAll(); } $user = new User(); $user->setDepartment($department); $name = new PersonName('', $firstName, '', $lastName, '', $username); $user->setName($name); $resource = $this->resourceManager->importResource($photo); $image = new Image($resource); $image->setTitle($name->getFullName()); $tag = $this->tagRepository->findBySearchTerm('Hauswart')->getFirst(); if (!$tag) { $tag = new Tag(); $tag->setLabel('Hauswart'); $this->tagRepository->add($tag); $collection->addTag($tag); } $image->addTag($tag); $user->setPhoto($image); $this->assetRepository->add($image); $collection->addAsset($image); $this->assetCollectionRepository->update($collection); return $this->addUserPhlu($username, $password, $user, $roleIdentifiers, $authenticationProviderName); }
/** * @param string $label * * @return Tag */ protected function getOrCreateTag($label) { if (isset($this->tagFirstLevelCache[$label])) { return $this->tagFirstLevelCache[$label]; } $tag = $this->tagRepository->findOneByLabel($label); if ($tag === null) { $tag = new Tag($label); $this->tagRepository->add($tag); } $this->tagFirstLevelCache[$label] = $tag; return $tag; }
/** * @test */ public function findBySearchTermReturnsFilteredResult() { $tag1 = new Tag('foobar'); $tag2 = new Tag('foo bar'); $tag3 = new Tag('bar foo bar'); $this->tagRepository->add($tag1); $this->tagRepository->add($tag2); $this->tagRepository->add($tag3); $this->persistenceManager->persistAll(); $this->persistenceManager->clearState(); $this->assertCount(3, $this->tagRepository->findBySearchTerm('foo')); $this->assertCount(2, $this->tagRepository->findBySearchTerm('foo bar')); $this->assertCount(1, $this->tagRepository->findBySearchTerm(' foo ')); }
/** * @param NodeInterface $node * @param Image $newImage * @param string $title * @param string|array $tagLabel * @param string $propertyName * @param boolean $removePreviousProfileImage * @return NodeInterface */ public function setImageToNode(NodeInterface $node, Image $newImage, $title, $tagLabel = NULL, $propertyName = 'image', $removePreviousProfileImage = FALSE) { $newImage->setTitle($title); if ($tagLabel !== NULL) { if (is_array($tagLabel) && !is_string($tagLabel)) { if ($removePreviousProfileImage === TRUE) { $this->removePreviousProfilePictureBasedOnTags($title, $tagLabel); } foreach ($tagLabel as $key => $label) { $tag = $this->tagRepository->findOneByLabel($label); if (!$tag instanceof Tag) { $tag = new Tag($label); $this->tagRepository->add($tag); } $newImage->addTag($tag); } } elseif (is_string($tagLabel) && !is_array($tagLabel)) { $tag = $this->tagRepository->findOneByLabel($tagLabel); if (!$tag instanceof Tag) { $tag = new Tag($tagLabel); $this->tagRepository->add($tag); } $newImage->addTag($tag); } } /** @var Image $image */ $image = $this->imageRepository->findByIdentifier($newImage->getIdentifier()); if ($image !== NULL) { try { $this->imageRepository->update($image); $node->setProperty($propertyName, $image); } catch (\Exception $exception) { // Image repository might give back an image while not stored for some reason. If so, catch that error and store it anyway $image->setTitle($title); $this->imageRepository->add($image); $node->setProperty($propertyName, $image); $this->systemLogger->log('Image with identifier ' . $image->getIdentifier() . ' stored while preceding an error that is not stored yet fetched using ImageRepository', LOG_CRIT); } } else { $this->imageRepository->add($newImage); $node->setProperty($propertyName, $newImage); } return $node; }
/** * @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(); } }
/** * @param AssetCollection $assetCollection * @return void */ public function editAssetCollectionAction(AssetCollection $assetCollection) { $this->view->assignMultiple(array('assetCollection' => $assetCollection, 'tags' => $this->tagRepository->findAll())); }
/** * Shows a list of assets * * @param string $searchTerm An optional search term used for filtering the list of assets * @return string */ public function indexAction($searchTerm = '') { $assets = $this->assetRepository->findBySearchTermOrTags($searchTerm, $this->tagRepository->findBySearchTerm($searchTerm)->toArray()); $this->view->assign('assets', $assets); }