Skip to content
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
12 changes: 11 additions & 1 deletion config/classification_store.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ services:
Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\CollectionServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\CollectionService

Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\GroupServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\GroupService


#
# Repositories
Expand All @@ -30,9 +33,16 @@ services:
Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository\CollectionConfigRepositoryInterface:
class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository\CollectionConfigRepository

Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository\GroupConfigRepositoryInterface:
class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository\GroupConfigRepository


#
# Hydrators
#

Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator\CollectionHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator\CollectionHydrator
class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator\CollectionHydrator

Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator\GroupHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator\GroupHydrator
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,15 @@
/**
* @internal
*/
final class GetCollectionController extends AbstractApiController
final class GetCollectionsController extends AbstractApiController
{
use PaginatedResponseTrait;

private CollectionServiceInterface $collectionService;

public function __construct(
SerializerInterface $serializer,
CollectionServiceInterface $collectionService,
private readonly CollectionServiceInterface $collectionService,
) {
parent::__construct($serializer);
$this->collectionService = $collectionService;
}

#[Route(
Expand All @@ -72,11 +69,11 @@ public function __construct(
content: new CollectionJson(new GenericCollection(Collection::class))
)]
#[IdParameter(
description: 'Classification Store',
description: 'Classification Store ID',
namePrefix: 'store',
)]
#[IdParameter(
description: 'object',
description: 'object ID',
namePrefix: 'object',
required: false
)]
Expand Down
99 changes: 99 additions & 0 deletions src/ClassificationStore/Controller/GetGroupsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?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\StudioBackendBundle\ClassificationStore\Controller;

use OpenApi\Attributes\Get;
use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\MappedParameter\ListClassificationStoreParameter;
use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Schema\Group;
use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\GroupServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\IdParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\PageParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\PageSizeParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\TextFieldParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\GenericCollection;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\CollectionJson;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\PaginatedResponseTrait;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Component\Serializer\SerializerInterface;

/**
* @internal
*/
final class GetGroupsController extends AbstractApiController
{
use PaginatedResponseTrait;

public function __construct(
SerializerInterface $serializer,
private readonly GroupServiceInterface $groupService,
) {
parent::__construct($serializer);
}

#[Route(
path: '/classification-store/groups',
name: 'pimcore_studio_api_classification_store_get_groups',
methods: ['GET']
)]
#[IsGranted(UserPermissions::DATA_OBJECTS->value)]
#[Get(
path: self::PREFIX . '/classification-store/groups',
operationId: 'classification_store_get_groups',
description: 'classification_store_get_groups_description',
summary: 'classification_store_get_groups_summary',
tags: [Tags::ClassificationStore->value]
)]
#[SuccessResponse(
description: 'classification_store_get_groups_response',
content: new CollectionJson(new GenericCollection(Group::class))
)]
#[IdParameter(
description: 'Classification Store ID',
namePrefix: 'store',
)]
#[IdParameter(
description: 'object ID',
namePrefix: 'object',
required: false
)]
#[PageParameter]
#[PageSizeParameter]
#[TextFieldParameter(
name: 'fieldName',
description: 'Field Name',
required: true,
example: 'technicalAttributes'
)]
public function getCollections(
#[MapQueryString] ListClassificationStoreParameter $parameters
): JsonResponse {
$collection = $this->groupService->getGroups($parameters);

return $this->getPaginatedCollection(
$this->serializer,
$collection->getItems(),
$collection->getTotalItems()
);
}
}
42 changes: 42 additions & 0 deletions src/ClassificationStore/Event/GroupEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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\StudioBackendBundle\ClassificationStore\Event;

use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Schema\Group;
use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent;

/**
* @internal
*/
final class GroupEvent extends AbstractPreResponseEvent
{
public const EVENT_NAME = 'pre_response.classification_store.group';

public function __construct(
private readonly Group $group
) {
parent::__construct($group);
}

/**
* Use this to get additional infos out of the response object
*/
public function getGroup(): Group
{
return $this->group;
}
}
35 changes: 35 additions & 0 deletions src/ClassificationStore/Hydrator/GroupHydrator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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\StudioBackendBundle\ClassificationStore\Hydrator;

use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Schema\Group;
use Pimcore\Model\DataObject\Classificationstore\GroupConfig;

/**
* @internal
*/
final class GroupHydrator implements GroupHydratorInterface
{
public function hydrate(GroupConfig $data): Group
{
return new Group(
id: $data->getId(),
name: $data->getName(),
description: $data->getDescription()
);
}
}
28 changes: 28 additions & 0 deletions src/ClassificationStore/Hydrator/GroupHydratorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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\StudioBackendBundle\ClassificationStore\Hydrator;

use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Schema\Group;
use Pimcore\Model\DataObject\Classificationstore\GroupConfig;

/**
* @internal
*/
interface GroupHydratorInterface
{
public function hydrate(GroupConfig $data): Group;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
namespace Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository;

use Pimcore\Bundle\StudioBackendBundle\MappedParameter\CollectionParametersInterface;
use Pimcore\Model\DataObject\Classificationstore\CollectionConfig;

/**
* @internal
*/
interface CollectionConfigRepositoryInterface
{
/**
* @param CollectionParametersInterface $collectionParameters
* @param array<int, int>|null $collectionIds
*
* @return array
* @return CollectionConfig[]
*/
public function getPaginatedCollectionsByStore(
int $storeId,
Expand Down
69 changes: 69 additions & 0 deletions src/ClassificationStore/Repository/GroupConfigRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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\StudioBackendBundle\ClassificationStore\Repository;

use Pimcore\Bundle\StudioBackendBundle\MappedParameter\CollectionParametersInterface;
use Pimcore\Model\DataObject\Classificationstore\GroupConfig\Listing;
use function count;

/**
* @internal
*/
final class GroupConfigRepository implements GroupConfigRepositoryInterface
{
/**
* {@inheritDoc}
*/
public function getPaginatedGroupsByStore(
int $storeId,
CollectionParametersInterface $collectionParameters,
?array $groupIds = null
): array {
$listing = new Listing();

$listing->setLimit($collectionParameters->getPageSize());
$listing->setOffset($this->getOffset($collectionParameters));
$listing->setOrder('ASC');
$listing->setOrderKey('id');
$listing->setCondition('storeId = ?', $storeId);

if ($groupIds !== null) {
$this->applyGroupIdsFilter($listing, $groupIds);
}

return $listing->load();
}

public function getCountByStoreId(int $storeId): int
{
$listing = new Listing();
$listing->setCondition('storeId = ?', $storeId);

return $listing->count();
}

private function applyGroupIdsFilter(Listing $list, array $groupIds): void
{
$placeholders = implode(',', array_fill(0, count($groupIds), '?'));
$list->addConditionParam('id IN ('. $placeholders .')', $groupIds);
}

private function getOffset(CollectionParametersInterface $collectionParameters): int
{
return ($collectionParameters->getPage() - 1) * $collectionParameters->getPageSize();
}
}
Loading