From a842e7cfa497cf4f75d99e154422107ec7962b29 Mon Sep 17 00:00:00 2001 From: Martin Eiber Date: Mon, 17 Mar 2025 13:32:38 +0100 Subject: [PATCH 1/2] Implement grid for asset search. --- config/grid.yaml | 3 + .../Search/GetSearchResultController.php | 78 +++++++++++++++++++ .../MappedParameter/FilterParameter.php | 9 ++- .../Request/SearchGridRequestBody.php | 55 +++++++++++++ .../MappedParameter/SearchGridParameter.php | 41 ++++++++++ src/Grid/Service/GridSearchService.php | 47 +++++++++++ .../Service/GridSearchServiceInterface.php | 30 +++++++ src/Grid/Service/GridService.php | 2 +- src/Grid/Service/GridServiceInterface.php | 3 + translations/studio_api_docs.en.yaml | 3 + 10 files changed, 269 insertions(+), 2 deletions(-) create mode 100644 src/Asset/Controller/Search/GetSearchResultController.php create mode 100644 src/Grid/Attribute/Request/SearchGridRequestBody.php create mode 100644 src/Grid/MappedParameter/SearchGridParameter.php create mode 100644 src/Grid/Service/GridSearchService.php create mode 100644 src/Grid/Service/GridSearchServiceInterface.php diff --git a/config/grid.yaml b/config/grid.yaml index 75ac833b3..30edd11eb 100644 --- a/config/grid.yaml +++ b/config/grid.yaml @@ -123,6 +123,9 @@ services: Pimcore\Bundle\StudioBackendBundle\Grid\Column\Definition\Metadata\DataObjectDefinition: tags: [ 'pimcore.studio_backend.grid_column_definition' ] + Pimcore\Bundle\StudioBackendBundle\Grid\Service\GridSearchServiceInterface: + class: Pimcore\Bundle\StudioBackendBundle\Grid\Service\GridSearchService + # # Column Resolver # diff --git a/src/Asset/Controller/Search/GetSearchResultController.php b/src/Asset/Controller/Search/GetSearchResultController.php new file mode 100644 index 000000000..6652a2751 --- /dev/null +++ b/src/Asset/Controller/Search/GetSearchResultController.php @@ -0,0 +1,78 @@ +value)] + #[Post( + path: self::PREFIX . '/assets/search', + operationId: 'asset_get_search', + description: 'asset_get_search_description', + summary: 'asset_get_search_summary', + tags: [Tags::AssetSearch->value] + )] + #[SearchGridRequestBody] + #[SuccessResponse( + description: 'asset_get_search_success_response', + content: new CollectionJson( + collection: new GridCollection() + ) + )] + #[DefaultResponses([ + HttpResponseCodes::UNAUTHORIZED, + HttpResponseCodes::NOT_FOUND, + HttpResponseCodes::BAD_REQUEST, + ])] + public function getAssetGrid(#[MapRequestPayload] SearchGridParameter $searchGridParameter): JsonResponse + { + return $this->jsonResponse($this->searchService->getAssetSearchGrid($searchGridParameter)); + } +} diff --git a/src/Filter/MappedParameter/FilterParameter.php b/src/Filter/MappedParameter/FilterParameter.php index 256d13e4e..88eaef83d 100644 --- a/src/Filter/MappedParameter/FilterParameter.php +++ b/src/Filter/MappedParameter/FilterParameter.php @@ -45,6 +45,8 @@ final class FilterParameter implements private ?string $className = null; + private bool $excludeFolders = true; + public function __construct( private readonly int $page = 1, private readonly int $pageSize = 50, @@ -66,7 +68,12 @@ public function getPageSize(): int public function getExcludeFolders(): bool { - return true; + return $this->excludeFolders; + } + + public function setExcludeFolders(bool $excludeFolders): void + { + $this->excludeFolders = $excludeFolders; } public function getPath(): ?string diff --git a/src/Grid/Attribute/Request/SearchGridRequestBody.php b/src/Grid/Attribute/Request/SearchGridRequestBody.php new file mode 100644 index 000000000..65607c29e --- /dev/null +++ b/src/Grid/Attribute/Request/SearchGridRequestBody.php @@ -0,0 +1,55 @@ +columns; + } + + public function getFilters(): FilterParameter + { + return $this->filters ?? new FilterParameter(); + } +} diff --git a/src/Grid/Service/GridSearchService.php b/src/Grid/Service/GridSearchService.php new file mode 100644 index 000000000..3f88e63bb --- /dev/null +++ b/src/Grid/Service/GridSearchService.php @@ -0,0 +1,47 @@ +getFilters(); + $filter->setExcludeFolders(false); + $parameter = new GridParameter( + folderId: 1, + columns: $gridParameter->getColumns(), + filters: $filter + ); + + return $this->gridService->getAssetGrid($parameter); + } +} \ No newline at end of file diff --git a/src/Grid/Service/GridSearchServiceInterface.php b/src/Grid/Service/GridSearchServiceInterface.php new file mode 100644 index 000000000..2f56f85e3 --- /dev/null +++ b/src/Grid/Service/GridSearchServiceInterface.php @@ -0,0 +1,30 @@ + asset_get_grid_success_response: Asset grid data asset_get_grid_summary: Get asset data for grid +asset_get_search_description: Asset grid for search +asset_get_search_summary: Get asset data for search +asset_get_search_success_response: Assets for search grid asset_get_text_data_by_id_description: | Retrieves the text data in UTF8 representation of the asset based on the given {id}.
The {id} must be an ID of existing asset. asset_get_text_data_by_id_success_response: Successfully retrieved UTF8 encoded text data of asset From dac713c0ff5323cd5e339eb49cd3089a68b2576d Mon Sep 17 00:00:00 2001 From: martineiber <11687066+martineiber@users.noreply.github.com> Date: Mon, 17 Mar 2025 12:34:51 +0000 Subject: [PATCH 2/2] Apply php-cs-fixer changes --- .../Search/GetSearchResultController.php | 2 +- src/Grid/Service/GridSearchService.php | 15 ++++++++------- src/Grid/Service/GridSearchServiceInterface.php | 12 +++++++----- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Asset/Controller/Search/GetSearchResultController.php b/src/Asset/Controller/Search/GetSearchResultController.php index 6652a2751..34d47552b 100644 --- a/src/Asset/Controller/Search/GetSearchResultController.php +++ b/src/Asset/Controller/Search/GetSearchResultController.php @@ -41,7 +41,7 @@ final class GetSearchResultController extends AbstractApiController { public function __construct( - SerializerInterface $serializer, + SerializerInterface $serializer, private readonly GridSearchServiceInterface $searchService, ) { parent::__construct($serializer); diff --git a/src/Grid/Service/GridSearchService.php b/src/Grid/Service/GridSearchService.php index 3f88e63bb..1e656455b 100644 --- a/src/Grid/Service/GridSearchService.php +++ b/src/Grid/Service/GridSearchService.php @@ -4,14 +4,16 @@ /** * Pimcore * - * This source file is available under following license: + * 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 PCL + * @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) + * @license http://www.pimcore.org/license GPLv3 and PCL */ - namespace Pimcore\Bundle\StudioBackendBundle\Grid\Service; use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\GridParameter; @@ -25,8 +27,7 @@ { public function __construct( private GridServiceInterface $gridService - ) - { + ) { } /** @@ -44,4 +45,4 @@ public function getAssetSearchGrid(SearchGridParameter $gridParameter): Collecti return $this->gridService->getAssetGrid($parameter); } -} \ No newline at end of file +} diff --git a/src/Grid/Service/GridSearchServiceInterface.php b/src/Grid/Service/GridSearchServiceInterface.php index 2f56f85e3..d7635bdf0 100644 --- a/src/Grid/Service/GridSearchServiceInterface.php +++ b/src/Grid/Service/GridSearchServiceInterface.php @@ -4,14 +4,16 @@ /** * Pimcore * - * This source file is available under following license: + * 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 PCL + * @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) + * @license http://www.pimcore.org/license GPLv3 and PCL */ - namespace Pimcore\Bundle\StudioBackendBundle\Grid\Service; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; @@ -27,4 +29,4 @@ interface GridSearchServiceInterface * @throws InvalidArgumentException */ public function getAssetSearchGrid(SearchGridParameter $gridParameter): Collection; -} \ No newline at end of file +}