diff --git a/config/properties.yaml b/config/properties.yaml new file mode 100644 index 000000000..be0531281 --- /dev/null +++ b/config/properties.yaml @@ -0,0 +1,26 @@ +services: + _defaults: + autowire: true + autoconfigure: true + public: false + + # controllers are imported separately to make sure they're public + # and have a tag that allows actions to type-hint services + Pimcore\Bundle\StudioBackendBundle\Property\Controller\: + resource: '../src/Property/Controller' + public: true + tags: [ 'controller.service_arguments' ] + + + Pimcore\Bundle\StudioBackendBundle\Property\RepositoryInterface: + class: Pimcore\Bundle\StudioBackendBundle\Property\Repository + + + Pimcore\Bundle\StudioBackendBundle\Property\Service\PropertyHydratorServiceInterface: + class: Pimcore\Bundle\StudioBackendBundle\Property\Service\PropertyHydratorService + + Pimcore\Bundle\StudioBackendBundle\Property\Hydrator\DataPropertyHydratorInterface: + class: Pimcore\Bundle\StudioBackendBundle\Property\Hydrator\DataPropertyHydrator + + Pimcore\Bundle\StudioBackendBundle\Property\Hydrator\PredefinedPropertyHydratorInterface: + class: Pimcore\Bundle\StudioBackendBundle\Property\Hydrator\PredefinedPropertyHydrator \ No newline at end of file diff --git a/src/DependencyInjection/PimcoreStudioBackendExtension.php b/src/DependencyInjection/PimcoreStudioBackendExtension.php index 4dc56ec00..e431c5726 100644 --- a/src/DependencyInjection/PimcoreStudioBackendExtension.php +++ b/src/DependencyInjection/PimcoreStudioBackendExtension.php @@ -59,6 +59,7 @@ public function load(array $configs, ContainerBuilder $container): void $loader->load('filters.yaml'); $loader->load('icon.yaml'); $loader->load('open_api.yaml'); + $loader->load('properties.yaml'); $loader->load('security.yaml'); $loader->load('services.yaml'); $loader->load('translation.yaml'); diff --git a/src/OpenApi/Attributes/Parameters/Path/ElementTypeParameter.php b/src/OpenApi/Attributes/Parameters/Path/ElementTypeParameter.php new file mode 100644 index 000000000..a23747650 --- /dev/null +++ b/src/OpenApi/Attributes/Parameters/Path/ElementTypeParameter.php @@ -0,0 +1,45 @@ +name, description: 'DataObject operations to get/update/create/delete data objects' )] +#[Tag( + name: Tags::Properties->name, + description: 'Get properties for elements' +)] #[Tag( name: Tags::Translation->name, description: 'Get translations either for a single key or multiple keys' @@ -46,6 +50,7 @@ enum Tags case Assets; case Authorization; case DataObjects; + case Properties; case Translation; case Versions; } diff --git a/src/Property/Controller/CollectionController.php b/src/Property/Controller/CollectionController.php new file mode 100644 index 000000000..754251d2b --- /dev/null +++ b/src/Property/Controller/CollectionController.php @@ -0,0 +1,81 @@ +name] + )] + #[ElementTypeParameter] + #[SuccessResponse( + description: 'Paginated properties with total count as header param', + content: new ItemsJson(PredefinedProperty::class) + )] + #[BadRequestResponse] + #[UnauthorizedResponse] + #[MethodNotAllowedResponse] + #[UnsupportedMediaTypeResponse] + #[UnprocessableContentResponse] + public function getProperties(#[MapQueryString] PropertiesParameters $parameters): JsonResponse + { + return $this->jsonResponse($this->hydratorService->getHydratedProperties($parameters)); + } +} diff --git a/src/Property/Controller/GetController.php b/src/Property/Controller/GetController.php new file mode 100644 index 000000000..6f99b52fe --- /dev/null +++ b/src/Property/Controller/GetController.php @@ -0,0 +1,72 @@ +name] + )] + #[IdParameter(type: 'element')] + #[ElementTypeParameter] + #[SuccessResponse( + description: 'Version data as json', + content: new OneOfVersionJson() + )] + #[UnauthorizedResponse] + #[NotFoundResponse] + #[MethodNotAllowedResponse] + #[UnsupportedMediaTypeResponse] + #[UnprocessableContentResponse] + public function getProperties(string $elementType, int $id): JsonResponse + { + + return $this->jsonResponse([]); + } +} diff --git a/src/Property/Hydrator/DataPropertyHydrator.php b/src/Property/Hydrator/DataPropertyHydrator.php new file mode 100644 index 000000000..5974bc50c --- /dev/null +++ b/src/Property/Hydrator/DataPropertyHydrator.php @@ -0,0 +1,71 @@ +extractData($property)); + die(); + } + + private function extractData(Property $property): array + { + $data = match (true) { + $property->getData() instanceof Document || + $property->getData() instanceof Asset || + $property->getData() instanceof AbstractObject => $this->extractDataFromModel($property->getData()), + default => [], + }; + + return [... $this->excludeProperties($property->getObjectVars()), ...$data]; + + } + + private function extractDataFromModel(Document|Asset|AbstractObject $data): array + { + return array_intersect_key($data->getObjectVars(), array_flip(self::ALLOWED_MODEL_PROPERTIES)); + } + + private function excludeProperties(array $values): array { + return array_diff_key($values, array_flip(self::EXCLUDED_PROPERTIES)); + } + +} \ No newline at end of file diff --git a/src/Property/Hydrator/DataPropertyHydratorInterface.php b/src/Property/Hydrator/DataPropertyHydratorInterface.php new file mode 100644 index 000000000..8ed438f1d --- /dev/null +++ b/src/Property/Hydrator/DataPropertyHydratorInterface.php @@ -0,0 +1,28 @@ +getId(), + $property->getName(), + $property->getDescription(), + $property->getKey(), + $property->getType(), + $property->getConfig(), + $property->getInheritable(), + $property->getCreationDate(), + $property->getModificationDate() + ); + } +} \ No newline at end of file diff --git a/src/Property/Hydrator/PredefinedPropertyHydratorInterface.php b/src/Property/Hydrator/PredefinedPropertyHydratorInterface.php new file mode 100644 index 000000000..887dd462c --- /dev/null +++ b/src/Property/Hydrator/PredefinedPropertyHydratorInterface.php @@ -0,0 +1,28 @@ +getElementType(); + $query = $parameters->getQuery(); + $translator = $this->translator; + $list->setFilter(static function (Predefined $predefined) use ($type, $query, $translator) { + if (!str_contains($predefined->getCtype(), $type)) { + return false; + } + if ($query && stripos($translator->trans($predefined->getName(), [], 'admin'), $query) === false) { + return false; + } + + return true; + }); + + return $list; + } +} \ No newline at end of file diff --git a/src/Property/RepositoryInterface.php b/src/Property/RepositoryInterface.php new file mode 100644 index 000000000..55119be0d --- /dev/null +++ b/src/Property/RepositoryInterface.php @@ -0,0 +1,28 @@ +query; + } + + public function getElementType(): string + { + if ($this->elementType === ElementTypes::TYPE_DATA_OBJECT) { + return ElementTypes::TYPE_OBJECT; + } + + return $this->elementType; + } +} diff --git a/src/Property/Schema/DataProperty.php b/src/Property/Schema/DataProperty.php new file mode 100644 index 000000000..1882dcdeb --- /dev/null +++ b/src/Property/Schema/DataProperty.php @@ -0,0 +1,54 @@ +name; + } + + public function getData(): string + { + return $this->data; + } + + public function getType(): string + { + return $this->type; + } + + public function getIsInheritable(): bool + { + return $this->inheritable; + } + + public function getIsInherited(): bool + { + return $this->inherited; + } +} \ No newline at end of file diff --git a/src/Property/Schema/PredefinedProperty.php b/src/Property/Schema/PredefinedProperty.php new file mode 100644 index 000000000..d3ffe3d7e --- /dev/null +++ b/src/Property/Schema/PredefinedProperty.php @@ -0,0 +1,97 @@ +id; + } + + public function getName(): string + { + return $this->name; + } + + public function getDescription(): ?string + { + return $this->description; + } + + public function getKey(): string + { + return $this->key; + } + + public function getType(): string + { + return $this->type; + } + + public function getConfig(): ?string + { + return $this->config; + } + + public function getIsInheritable(): bool + { + return $this->inheritable; + } + + public function getCreationDate(): int + { + return $this->creationDate; + } + + public function getModificationDate(): int + { + return $this->modificationDate; + } +} \ No newline at end of file diff --git a/src/Property/Service/PropertyHydratorService.php b/src/Property/Service/PropertyHydratorService.php new file mode 100644 index 000000000..8b666c783 --- /dev/null +++ b/src/Property/Service/PropertyHydratorService.php @@ -0,0 +1,50 @@ +repository->listProperties($parameters); + $hydratedProperties = []; + foreach ($properties->load() as $property) { + $hydratedProperties[] = $this->propertyHydrator->hydrate($property); + } + + return $hydratedProperties; + } + + public function getHydratedPropertyForElement(int $id, string $type): array + { + $element = $this->getElement($this->serviceResolver, $type, $id); + + foreach($element->getProperties() as $property) { + $hydratedProperties[] = $this->dataPropertyHydrator->hydrate($property); + } + + return $hydratedProperties; + } +} \ No newline at end of file diff --git a/src/Property/Service/PropertyHydratorServiceInterface.php b/src/Property/Service/PropertyHydratorServiceInterface.php new file mode 100644 index 000000000..4d5d8c677 --- /dev/null +++ b/src/Property/Service/PropertyHydratorServiceInterface.php @@ -0,0 +1,16 @@ +