Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tags resolver #38

Merged
merged 8 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/Models/Tag/TagResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StaticResolverBundle\Models\Tag;

use Pimcore\Model\Element\Tag;

class TagResolver implements TagResolverInterface
{
public function getById(int $id): ?Tag
{
return Tag::getById($id);
}

/**
* @return array<int, Tag>
*/
public function getTagsForElement(string $cType, int $cId): array
{
return Tag::getTagsForElement($cType, $cId);
}

public function assignTagToElement(string $cType, int $cId, Tag $tag): void
{
Tag::addTagToElement($cType, $cId, $tag);
}

public function unassignTagFromElement(string $cType, int $cId, Tag $tag): void
{
Tag::removeTagFromElement($cType, $cId, $tag);
}

/**
* @param array<int, int> $cIds
* @param array<int, int> $tagIds
*/
public function batchAssignTagsToElements(string $cType, array $cIds, array $tagIds): void
{
Tag::batchAssignTagsToElement($cType, $cIds, $tagIds);
}

/**
* @param array<int, int> $cIds
* @param array<int, int> $tagIds
*/
public function batchReplaceTagsForElements(string $cType, array $cIds, array $tagIds): void
{
Tag::batchAssignTagsToElement($cType, $cIds, $tagIds, true);
}
}
45 changes: 45 additions & 0 deletions src/Models/Tag/TagResolverInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StaticResolverBundle\Models\Tag;

use Pimcore\Model\Element\Tag;

interface TagResolverInterface
{
public function getById(int $id): ?Tag;

/**
* @return array<int, Tag>
*/
public function getTagsForElement(string $cType, int $cId): array;

public function assignTagToElement(string $cType, int $cId, Tag $tag): void;

public function unassignTagFromElement(string $cType, int $cId, Tag $tag): void;

/**
* @param array<int, int> $cIds
* @param array<int, int> $tagIds
*/
public function batchAssignTagsToElements(string $cType, array $cIds, array $tagIds): void;

/**
* @param array<int, int> $cIds
* @param array<int, int> $tagIds
*/
public function batchReplaceTagsForElements(string $cType, array $cIds, array $tagIds): void;
}
Loading