|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +/** |
| 5 | + * This source file is available under the terms of the |
| 6 | + * Pimcore Open Core License (POCL) |
| 7 | + * Full copyright and license information is available in |
| 8 | + * LICENSE.md which is distributed with this source code. |
| 9 | + * |
| 10 | + * @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com) |
| 11 | + * @license Pimcore Open Core License (POCL) |
| 12 | + */ |
| 13 | + |
| 14 | +namespace Pimcore\Bundle\StudioBackendBundle\Class\Controller; |
| 15 | + |
| 16 | +use OpenApi\Attributes\Get; |
| 17 | +use Pimcore\Bundle\StudioBackendBundle\Class\Attribute\Response\Property\AnyOfClassDefinitionNodes; |
| 18 | +use Pimcore\Bundle\StudioBackendBundle\Class\MappedParameter\ClassDefinitionTreeParameter; |
| 19 | +use Pimcore\Bundle\StudioBackendBundle\Class\Service\ClassDefinitionTreeServiceInterface; |
| 20 | +use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; |
| 21 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Parameter\Query\BoolParameter; |
| 22 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\CollectionJson; |
| 23 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses; |
| 24 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse; |
| 25 | +use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; |
| 26 | +use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes; |
| 27 | +use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions; |
| 28 | +use Pimcore\Bundle\StudioBackendBundle\Util\Trait\PaginatedResponseTrait; |
| 29 | +use Symfony\Component\HttpFoundation\JsonResponse; |
| 30 | +use Symfony\Component\HttpKernel\Attribute\MapQueryString; |
| 31 | +use Symfony\Component\Routing\Attribute\Route; |
| 32 | +use Symfony\Component\Security\Http\Attribute\IsGranted; |
| 33 | +use Symfony\Component\Serializer\SerializerInterface; |
| 34 | +use function count; |
| 35 | + |
| 36 | +/** |
| 37 | + * @internal |
| 38 | + */ |
| 39 | +final class TreeController extends AbstractApiController |
| 40 | +{ |
| 41 | + use PaginatedResponseTrait; |
| 42 | + |
| 43 | + private const string ROUTE = '/class/definition/configuration-view/tree'; |
| 44 | + |
| 45 | + public function __construct( |
| 46 | + SerializerInterface $serializer, |
| 47 | + private readonly ClassDefinitionTreeServiceInterface $treeService, |
| 48 | + ) { |
| 49 | + parent::__construct($serializer); |
| 50 | + } |
| 51 | + |
| 52 | + #[Route(self::ROUTE, name: 'pimcore_studio_api_classes_tree', methods: ['GET'])] |
| 53 | + #[IsGranted(UserPermissions::CLASS_DEFINITION->value)] |
| 54 | + #[Get( |
| 55 | + path: self::PREFIX . self::ROUTE, |
| 56 | + operationId: 'class_definition_get_tree', |
| 57 | + description: 'class_definition_get_tree_description', |
| 58 | + summary: 'class_definition_get_tree_summary', |
| 59 | + tags: [Tags::ClassDefinition->value] |
| 60 | + )] |
| 61 | + #[BoolParameter('withGroup', description: 'Whether to group the results.', example: true)] |
| 62 | + #[SuccessResponse( |
| 63 | + description: 'class_definition_get_tree_success_response', |
| 64 | + content: new CollectionJson(new AnyOfClassDefinitionNodes()) |
| 65 | + )] |
| 66 | + #[DefaultResponses([HttpResponseCodes::UNAUTHORIZED])] |
| 67 | + public function getClassDefinitionTree(#[MapQueryString] ClassDefinitionTreeParameter $parameters): JsonResponse |
| 68 | + { |
| 69 | + $definitions = $this->treeService->getTree($parameters->isWithGroup()); |
| 70 | + |
| 71 | + return $this->getPaginatedCollection( |
| 72 | + $this->serializer, |
| 73 | + $definitions, |
| 74 | + count($definitions) |
| 75 | + ); |
| 76 | + } |
| 77 | +} |
0 commit comments