Skip to content

Commit

Permalink
Tags resolver (#38)
Browse files Browse the repository at this point in the history
* Add Tag resolver

---------

Co-authored-by: alexz707 <alexz707@users.noreply.github.com>
  • Loading branch information
alexz707 and alexz707 authored Jun 5, 2024
1 parent f00da3b commit 69236fa
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
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;
}

0 comments on commit 69236fa

Please sign in to comment.