-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathCollectionService.php
More file actions
94 lines (81 loc) · 3.33 KB
/
Copy pathCollectionService.php
File metadata and controls
94 lines (81 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?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\Service;
use Exception;
use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Event\CollectionEvent;
use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Hydrator\CollectionHydratorInterface;
use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\MappedParameter\ListClassificationStoreParameter;
use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository\CollectionConfigRepositoryInterface;
use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository\CollectionRelationsRepositoryInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\DatabaseException;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Response\Collection;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use function count;
/**
* @internal
*/
final readonly class CollectionService implements CollectionServiceInterface
{
public function __construct(
private CollectionRelationsRepositoryInterface $collectionRelationsRepository,
private CollectionConfigRepositoryInterface $collectionConfigRepository,
private CollectionHydratorInterface $collectionHydrator,
private EventDispatcherInterface $eventDispatcher,
private GroupServiceInterface $groupService,
) {
}
/**
* {@inheritDoc}
*/
public function getCollections(ListClassificationStoreParameter $parameter): Collection
{
$allowedCollectionIds = $this->getAllowedCollectionIds($parameter);
if (count($allowedCollectionIds) === 0) {
$allowedCollectionIds = null;
}
$collections = $this->collectionConfigRepository->getPaginatedCollectionsByStore(
$parameter->getStoreId(),
$parameter,
$allowedCollectionIds,
$parameter->getSearchTerm()
);
$hydratedCollections = [];
foreach ($collections as $collection) {
$hydratedCollection = $this->collectionHydrator->hydrate($collection);
$this->eventDispatcher->dispatch(
new CollectionEvent($hydratedCollection),
CollectionEvent::EVENT_NAME
);
$hydratedCollections[] = $hydratedCollection;
}
return new Collection(
totalItems: $this->collectionConfigRepository->getCountByStoreId($parameter->getStoreId()),
items: $hydratedCollections
);
}
/**
* @return array<int, int>
*
* @throws Exception
* @throws NotFoundException
* @throws DatabaseException
*/
private function getAllowedCollectionIds(ListClassificationStoreParameter $parameter): array
{
$allowedGroupIds = $this->groupService->getAllowedGroupIds($parameter);
return $this->collectionRelationsRepository->getCollectionIdsWith($allowedGroupIds);
}
}