Skip to content

Commit 9daff7c

Browse files
authored
[Task] Get classification store groups (#975)
* Get classification store groups * Apply php-cs-fixer changes * Style. * Apply php-cs-fixer changes --------- Co-authored-by: martineiber <11687066+martineiber@users.noreply.github.com>
1 parent da94cfc commit 9daff7c

14 files changed

Lines changed: 533 additions & 32 deletions

config/classification_store.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ services:
1919
Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\CollectionServiceInterface:
2020
class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\CollectionService
2121

22+
Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\GroupServiceInterface:
23+
class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\GroupService
24+
2225

2326
#
2427
# Repositories
@@ -30,9 +33,16 @@ services:
3033
Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository\CollectionConfigRepositoryInterface:
3134
class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository\CollectionConfigRepository
3235

36+
Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository\GroupConfigRepositoryInterface:
37+
class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository\GroupConfigRepository
38+
39+
3340
#
3441
# Hydrators
3542
#
3643

3744
Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator\CollectionHydratorInterface:
38-
class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator\CollectionHydrator
45+
class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator\CollectionHydrator
46+
47+
Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator\GroupHydratorInterface:
48+
class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator\GroupHydrator

src/ClassificationStore/Controller/GetCollectionController.php renamed to src/ClassificationStore/Controller/GetCollectionsController.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,15 @@
4040
/**
4141
* @internal
4242
*/
43-
final class GetCollectionController extends AbstractApiController
43+
final class GetCollectionsController extends AbstractApiController
4444
{
4545
use PaginatedResponseTrait;
4646

47-
private CollectionServiceInterface $collectionService;
48-
4947
public function __construct(
5048
SerializerInterface $serializer,
51-
CollectionServiceInterface $collectionService,
49+
private readonly CollectionServiceInterface $collectionService,
5250
) {
5351
parent::__construct($serializer);
54-
$this->collectionService = $collectionService;
5552
}
5653

5754
#[Route(
@@ -72,11 +69,11 @@ public function __construct(
7269
content: new CollectionJson(new GenericCollection(Collection::class))
7370
)]
7471
#[IdParameter(
75-
description: 'Classification Store',
72+
description: 'Classification Store ID',
7673
namePrefix: 'store',
7774
)]
7875
#[IdParameter(
79-
description: 'object',
76+
description: 'object ID',
8077
namePrefix: 'object',
8178
required: false
8279
)]
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* Pimcore
6+
*
7+
* This source file is available under two different licenses:
8+
* - GNU General Public License version 3 (GPLv3)
9+
* - Pimcore Commercial License (PCL)
10+
* Full copyright and license information is available in
11+
* LICENSE.md which is distributed with this source code.
12+
*
13+
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
14+
* @license http://www.pimcore.org/license GPLv3 and PCL
15+
*/
16+
17+
namespace Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Controller;
18+
19+
use OpenApi\Attributes\Get;
20+
use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\MappedParameter\ListClassificationStoreParameter;
21+
use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Schema\Group;
22+
use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\GroupServiceInterface;
23+
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
24+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\IdParameter;
25+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\PageParameter;
26+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\PageSizeParameter;
27+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\TextFieldParameter;
28+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Property\GenericCollection;
29+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\CollectionJson;
30+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
31+
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
32+
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
33+
use Pimcore\Bundle\StudioBackendBundle\Util\Trait\PaginatedResponseTrait;
34+
use Symfony\Component\HttpFoundation\JsonResponse;
35+
use Symfony\Component\HttpKernel\Attribute\MapQueryString;
36+
use Symfony\Component\Routing\Attribute\Route;
37+
use Symfony\Component\Security\Http\Attribute\IsGranted;
38+
use Symfony\Component\Serializer\SerializerInterface;
39+
40+
/**
41+
* @internal
42+
*/
43+
final class GetGroupsController extends AbstractApiController
44+
{
45+
use PaginatedResponseTrait;
46+
47+
public function __construct(
48+
SerializerInterface $serializer,
49+
private readonly GroupServiceInterface $groupService,
50+
) {
51+
parent::__construct($serializer);
52+
}
53+
54+
#[Route(
55+
path: '/classification-store/groups',
56+
name: 'pimcore_studio_api_classification_store_get_groups',
57+
methods: ['GET']
58+
)]
59+
#[IsGranted(UserPermissions::DATA_OBJECTS->value)]
60+
#[Get(
61+
path: self::PREFIX . '/classification-store/groups',
62+
operationId: 'classification_store_get_groups',
63+
description: 'classification_store_get_groups_description',
64+
summary: 'classification_store_get_groups_summary',
65+
tags: [Tags::ClassificationStore->value]
66+
)]
67+
#[SuccessResponse(
68+
description: 'classification_store_get_groups_response',
69+
content: new CollectionJson(new GenericCollection(Group::class))
70+
)]
71+
#[IdParameter(
72+
description: 'Classification Store ID',
73+
namePrefix: 'store',
74+
)]
75+
#[IdParameter(
76+
description: 'object ID',
77+
namePrefix: 'object',
78+
required: false
79+
)]
80+
#[PageParameter]
81+
#[PageSizeParameter]
82+
#[TextFieldParameter(
83+
name: 'fieldName',
84+
description: 'Field Name',
85+
required: true,
86+
example: 'technicalAttributes'
87+
)]
88+
public function getCollections(
89+
#[MapQueryString] ListClassificationStoreParameter $parameters
90+
): JsonResponse {
91+
$collection = $this->groupService->getGroups($parameters);
92+
93+
return $this->getPaginatedCollection(
94+
$this->serializer,
95+
$collection->getItems(),
96+
$collection->getTotalItems()
97+
);
98+
}
99+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* Pimcore
6+
*
7+
* This source file is available under two different licenses:
8+
* - GNU General Public License version 3 (GPLv3)
9+
* - Pimcore Commercial License (PCL)
10+
* Full copyright and license information is available in
11+
* LICENSE.md which is distributed with this source code.
12+
*
13+
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
14+
* @license http://www.pimcore.org/license GPLv3 and PCL
15+
*/
16+
17+
namespace Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Event;
18+
19+
use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Schema\Group;
20+
use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent;
21+
22+
/**
23+
* @internal
24+
*/
25+
final class GroupEvent extends AbstractPreResponseEvent
26+
{
27+
public const EVENT_NAME = 'pre_response.classification_store.group';
28+
29+
public function __construct(
30+
private readonly Group $group
31+
) {
32+
parent::__construct($group);
33+
}
34+
35+
/**
36+
* Use this to get additional infos out of the response object
37+
*/
38+
public function getGroup(): Group
39+
{
40+
return $this->group;
41+
}
42+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* Pimcore
6+
*
7+
* This source file is available under two different licenses:
8+
* - GNU General Public License version 3 (GPLv3)
9+
* - Pimcore Commercial License (PCL)
10+
* Full copyright and license information is available in
11+
* LICENSE.md which is distributed with this source code.
12+
*
13+
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
14+
* @license http://www.pimcore.org/license GPLv3 and PCL
15+
*/
16+
17+
namespace Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator;
18+
19+
use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Schema\Group;
20+
use Pimcore\Model\DataObject\Classificationstore\GroupConfig;
21+
22+
/**
23+
* @internal
24+
*/
25+
final class GroupHydrator implements GroupHydratorInterface
26+
{
27+
public function hydrate(GroupConfig $data): Group
28+
{
29+
return new Group(
30+
id: $data->getId(),
31+
name: $data->getName(),
32+
description: $data->getDescription()
33+
);
34+
}
35+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* Pimcore
6+
*
7+
* This source file is available under two different licenses:
8+
* - GNU General Public License version 3 (GPLv3)
9+
* - Pimcore Commercial License (PCL)
10+
* Full copyright and license information is available in
11+
* LICENSE.md which is distributed with this source code.
12+
*
13+
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
14+
* @license http://www.pimcore.org/license GPLv3 and PCL
15+
*/
16+
17+
namespace Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator;
18+
19+
use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Schema\Group;
20+
use Pimcore\Model\DataObject\Classificationstore\GroupConfig;
21+
22+
/**
23+
* @internal
24+
*/
25+
interface GroupHydratorInterface
26+
{
27+
public function hydrate(GroupConfig $data): Group;
28+
}

src/ClassificationStore/Repository/CollectionConfigRepositoryInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
namespace Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository;
1818

1919
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\CollectionParametersInterface;
20+
use Pimcore\Model\DataObject\Classificationstore\CollectionConfig;
2021

2122
/**
2223
* @internal
2324
*/
2425
interface CollectionConfigRepositoryInterface
2526
{
2627
/**
27-
* @param CollectionParametersInterface $collectionParameters
2828
* @param array<int, int>|null $collectionIds
2929
*
30-
* @return array
30+
* @return CollectionConfig[]
3131
*/
3232
public function getPaginatedCollectionsByStore(
3333
int $storeId,
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* Pimcore
6+
*
7+
* This source file is available under two different licenses:
8+
* - GNU General Public License version 3 (GPLv3)
9+
* - Pimcore Commercial License (PCL)
10+
* Full copyright and license information is available in
11+
* LICENSE.md which is distributed with this source code.
12+
*
13+
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
14+
* @license http://www.pimcore.org/license GPLv3 and PCL
15+
*/
16+
17+
namespace Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository;
18+
19+
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\CollectionParametersInterface;
20+
use Pimcore\Model\DataObject\Classificationstore\GroupConfig\Listing;
21+
use function count;
22+
23+
/**
24+
* @internal
25+
*/
26+
final class GroupConfigRepository implements GroupConfigRepositoryInterface
27+
{
28+
/**
29+
* {@inheritDoc}
30+
*/
31+
public function getPaginatedGroupsByStore(
32+
int $storeId,
33+
CollectionParametersInterface $collectionParameters,
34+
?array $groupIds = null
35+
): array {
36+
$listing = new Listing();
37+
38+
$listing->setLimit($collectionParameters->getPageSize());
39+
$listing->setOffset($this->getOffset($collectionParameters));
40+
$listing->setOrder('ASC');
41+
$listing->setOrderKey('id');
42+
$listing->setCondition('storeId = ?', $storeId);
43+
44+
if ($groupIds !== null) {
45+
$this->applyGroupIdsFilter($listing, $groupIds);
46+
}
47+
48+
return $listing->load();
49+
}
50+
51+
public function getCountByStoreId(int $storeId): int
52+
{
53+
$listing = new Listing();
54+
$listing->setCondition('storeId = ?', $storeId);
55+
56+
return $listing->count();
57+
}
58+
59+
private function applyGroupIdsFilter(Listing $list, array $groupIds): void
60+
{
61+
$placeholders = implode(',', array_fill(0, count($groupIds), '?'));
62+
$list->addConditionParam('id IN ('. $placeholders .')', $groupIds);
63+
}
64+
65+
private function getOffset(CollectionParametersInterface $collectionParameters): int
66+
{
67+
return ($collectionParameters->getPage() - 1) * $collectionParameters->getPageSize();
68+
}
69+
}

0 commit comments

Comments
 (0)