diff --git a/src/DataIndex/AssetSearchResult.php b/src/DataIndex/AssetSearchResult.php index 021f3b74..6233a187 100644 --- a/src/DataIndex/AssetSearchResult.php +++ b/src/DataIndex/AssetSearchResult.php @@ -25,8 +25,10 @@ use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\Type\Text; use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\Type\Unknown; use Pimcore\Bundle\StudioBackendBundle\Asset\Schema\Type\Video; +use Pimcore\Bundle\StudioBackendBundle\DataIndex\SearchResult\SearchResultItemInterface; +use Pimcore\Bundle\StudioBackendBundle\DataIndex\SearchResult\SearchResultPaginationInterface; -final readonly class AssetSearchResult +final readonly class AssetSearchResult implements SearchResultItemInterface, SearchResultPaginationInterface { /** * @param array $items diff --git a/src/DataIndex/DataObjectSearchResult.php b/src/DataIndex/DataObjectSearchResult.php index 98d579b3..75b64a6c 100644 --- a/src/DataIndex/DataObjectSearchResult.php +++ b/src/DataIndex/DataObjectSearchResult.php @@ -16,7 +16,10 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataIndex; -final readonly class DataObjectSearchResult +use Pimcore\Bundle\StudioBackendBundle\DataIndex\SearchResult\SearchResultItemInterface; +use Pimcore\Bundle\StudioBackendBundle\DataIndex\SearchResult\SearchResultPaginationInterface; + +final readonly class DataObjectSearchResult implements SearchResultItemInterface, SearchResultPaginationInterface { /** * @param array $items diff --git a/src/DataIndex/Grid/GridSearch.php b/src/DataIndex/Grid/GridSearch.php index e04967c8..f8622732 100644 --- a/src/DataIndex/Grid/GridSearch.php +++ b/src/DataIndex/Grid/GridSearch.php @@ -19,6 +19,8 @@ use Pimcore\Bundle\StudioBackendBundle\Asset\Service\AssetServiceInterface; use Pimcore\Bundle\StudioBackendBundle\DataIndex\AssetSearchResult; use Pimcore\Bundle\StudioBackendBundle\DataIndex\AssetSearchServiceInterface; +use Pimcore\Bundle\StudioBackendBundle\DataIndex\DataObjectSearchResult; +use Pimcore\Bundle\StudioBackendBundle\DataIndex\DataObjectSearchServiceInterface; use Pimcore\Bundle\StudioBackendBundle\DataIndex\OpenSearchFilterInterface; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; @@ -32,11 +34,15 @@ */ final readonly class GridSearch implements GridSearchInterface { + private OpenSearchFilterInterface $filterService; + public function __construct( private FilterServiceProviderInterface $filterServiceProvider, private AssetSearchServiceInterface $assetSearchService, + private DataObjectSearchServiceInterface $dataObjectSearchService, private AssetServiceInterface $assetService ) { + $this->filterService = $this->filterServiceProvider->create(OpenSearchFilterInterface::SERVICE_TYPE); } /** @@ -44,19 +50,33 @@ public function __construct( */ public function searchAssets(GridParameter $gridParameter): AssetSearchResult { - /** @var OpenSearchFilterInterface $filterService */ - $filterService = $this->filterServiceProvider->create(OpenSearchFilterInterface::SERVICE_TYPE); $filter = $gridParameter->getFilters(); $asset = $this->assetService->getAssetFolder($gridParameter->getFolderId()); $filter->setPath($asset->getFullPath()); - $assetQuery = $filterService->applyFilters( + $assetQuery = $this->filterService->applyFilters( $filter, ElementTypes::TYPE_ASSET ); return $this->assetSearchService->searchAssets($assetQuery); } + + public function searchDataObjects(GridParameter $gridParameter): DataObjectSearchResult + { + $filter = $gridParameter->getFilters(); + + $folder = $this->dataObjectSearchService->getDataObjectById($gridParameter->getFolderId()); + + $filter->setPath($folder->getFullPath()); + + $query = $this->filterService->applyFilters( + $filter, + ElementTypes::TYPE_DATA_OBJECT + ); + + return $this->dataObjectSearchService->searchDataObjects($query); + } } diff --git a/src/DataIndex/Grid/GridSearchInterface.php b/src/DataIndex/Grid/GridSearchInterface.php index c5209559..0b966cda 100644 --- a/src/DataIndex/Grid/GridSearchInterface.php +++ b/src/DataIndex/Grid/GridSearchInterface.php @@ -17,6 +17,7 @@ namespace Pimcore\Bundle\StudioBackendBundle\DataIndex\Grid; use Pimcore\Bundle\StudioBackendBundle\DataIndex\AssetSearchResult; +use Pimcore\Bundle\StudioBackendBundle\DataIndex\DataObjectSearchResult; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\SearchException; use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\GridParameter; @@ -30,4 +31,6 @@ interface GridSearchInterface * @throws NotFoundException|SearchException */ public function searchAssets(GridParameter $gridParameter): AssetSearchResult; + + public function searchDataObjects(GridParameter $gridParameter): DataObjectSearchResult; } diff --git a/src/DataIndex/SearchResult/SearchResultItemInterface.php b/src/DataIndex/SearchResult/SearchResultItemInterface.php new file mode 100644 index 00000000..865a342a --- /dev/null +++ b/src/DataIndex/SearchResult/SearchResultItemInterface.php @@ -0,0 +1,27 @@ +value)] + #[Post( + path: self::API_PATH . '/data-objects/grid', + operationId: 'data_object_get_grid', + description: 'data_object_get_grid_description', + summary: 'data_object_get_grid_summary', + tags: [Tags::DataObjectsGrid->value] + )] + #[GridRequestBody] + #[SuccessResponse( + description: 'data_object_get_grid_success_response', + content: new CollectionJson( + collection: new GridCollection() + ) + )] + #[DefaultResponses([ + HttpResponseCodes::UNAUTHORIZED, + HttpResponseCodes::NOT_FOUND, + HttpResponseCodes::BAD_REQUEST, + ])] + public function getDataObjectGrid(#[MapRequestPayload] GridParameter $gridParameter): JsonResponse + { + return $this->jsonResponse($this->gridService->getDataObjectGrid($gridParameter)); + } +} diff --git a/src/DataObject/Schema/DataObject.php b/src/DataObject/Schema/DataObject.php index a6b82632..424a5507 100644 --- a/src/DataObject/Schema/DataObject.php +++ b/src/DataObject/Schema/DataObject.php @@ -133,4 +133,9 @@ public function getIndex(): int { return $this->index; } + + public function getFilename(): string + { + return $this->key; + } } diff --git a/src/Grid/Service/GridService.php b/src/Grid/Service/GridService.php index d09ebeec..d44c9dc3 100644 --- a/src/Grid/Service/GridService.php +++ b/src/Grid/Service/GridService.php @@ -18,6 +18,7 @@ use Exception; use Pimcore\Bundle\StudioBackendBundle\DataIndex\Grid\GridSearchInterface; +use Pimcore\Bundle\StudioBackendBundle\DataIndex\SearchResult\SearchResultItemInterface; use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnCollectorInterface; use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnDefinitionInterface; @@ -73,25 +74,15 @@ public function __construct( public function getAssetGrid(GridParameter $gridParameter): Collection { $result = $this->gridSearch->searchAssets($gridParameter); - $items = $result->getItems(); - if (empty($items)) { - return new Collection(totalItems: 0, items: []); - } + return $this->getCollectionFromSearchResult($result, $gridParameter); + } - $data = []; - foreach ($items as $item) { - $data[] = $this->getGridDataForElement( - $this->getConfigurationFromArray($gridParameter->getColumns()), - $item, - ElementTypes::TYPE_ASSET - ); - } + public function getDataObjectGrid(GridParameter $gridParameter): Collection + { + $result = $this->gridSearch->searchDataObjects($gridParameter); - return new Collection( - totalItems: $result->getTotalItems(), - items: $data - ); + return $this->getCollectionFromSearchResult($result, $gridParameter); } /** @@ -249,4 +240,29 @@ private function isExportable(string $type): bool return $this->getColumnDefinitions()[$type]->isExportable(); } + + private function getCollectionFromSearchResult( + SearchResultItemInterface $searchResultItem, + GridParameter $gridParameter + ): Collection { + $items = $searchResultItem->getItems(); + + if (empty($items)) { + return new Collection(totalItems: 0, items: []); + } + + $data = []; + foreach ($items as $item) { + $data[] = $this->getGridDataForElement( + $this->getConfigurationFromArray($gridParameter->getColumns()), + $item, + ElementTypes::TYPE_ASSET + ); + } + + return new Collection( + totalItems: $searchResultItem->getTotalItems(), + items: $data + ); + } } diff --git a/src/Grid/Service/GridServiceInterface.php b/src/Grid/Service/GridServiceInterface.php index ded8710f..b340942a 100644 --- a/src/Grid/Service/GridServiceInterface.php +++ b/src/Grid/Service/GridServiceInterface.php @@ -57,6 +57,8 @@ public function getConfigurationFromArray(array $config, bool $isExport = false) public function getAssetGrid(GridParameter $gridParameter): Collection; + public function getDataObjectGrid(GridParameter $gridParameter): Collection; + public function getColumnKeys(ColumnCollection $columnCollection, bool $withGroup = false): array; /** diff --git a/translations/studio_api_docs.en.yaml b/translations/studio_api_docs.en.yaml index 2b7043be..271f2800 100644 --- a/translations/studio_api_docs.en.yaml +++ b/translations/studio_api_docs.en.yaml @@ -381,7 +381,7 @@ system_settings_get_success_response: System settings data system_settings_get_summary: Get system settings tag_asset_thumbnail_description: List thumbnails for assets like videos and images tag_assets_description: Asset operations to get/update/create/delete assets -data: Asset Grid operations +tag_asset_grid_description: Asset Grid operations tag_assign_to_element_description: | Assign a specific tag based on the given {tagId} to an element based on {elementType} and {id}.
The {id} must be an ID of an existing element of the provided {elementType}. @@ -555,4 +555,14 @@ user_get_collection_success_response: List of users data_object_get_available_grid_columns_description: | Get all available grid columns for data objects data_object_get_available_grid_columns_summary: Get all available grid columns for data objects -data_object_get_available_grid_columns_success_response: List of available grid columns for data objects \ No newline at end of file +data_object_get_available_grid_columns_success_response: List of available grid columns for data objects +data_object_get_grid_description: | + Retrieve data objects data for grid.
+ You can use different query parameters to filter the data objects data:
+ +data_object_get_grid_success_response: Data object grid data +data_object_get_grid_summary: Get data object data for grid \ No newline at end of file