Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/grid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
78 changes: 78 additions & 0 deletions src/Asset/Controller/Search/GetSearchResultController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?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\Asset\Controller\Search;

use OpenApi\Attributes\Post;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
use Pimcore\Bundle\StudioBackendBundle\Grid\Attribute\Property\GridCollection;
use Pimcore\Bundle\StudioBackendBundle\Grid\Attribute\Request\SearchGridRequestBody;
use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\SearchGridParameter;
use Pimcore\Bundle\StudioBackendBundle\Grid\Service\GridSearchServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\Content\CollectionJson;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\DefaultResponses;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attribute\Response\SuccessResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\HttpResponseCodes;
use Pimcore\Bundle\StudioBackendBundle\Util\Constant\UserPermissions;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Component\Serializer\SerializerInterface;

/**
* @internal
*/
final class GetSearchResultController extends AbstractApiController
{
public function __construct(
SerializerInterface $serializer,
private readonly GridSearchServiceInterface $searchService,
) {
parent::__construct($serializer);
}

/**
* @throws InvalidArgumentException
*/
#[Route('/assets/search', name: 'pimcore_studio_api_get_asset_search', methods: ['POST'])]
#[IsGranted(UserPermissions::ASSETS->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));
}
}
9 changes: 8 additions & 1 deletion src/Filter/MappedParameter/FilterParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
55 changes: 55 additions & 0 deletions src/Grid/Attribute/Request/SearchGridRequestBody.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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\Grid\Attribute\Request;

use Attribute;
use OpenApi\Attributes\Items;
use OpenApi\Attributes\JsonContent;
use OpenApi\Attributes\Property;
use OpenApi\Attributes\RequestBody;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column;
use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Filter;

/**
* @internal
*/
#[Attribute(Attribute::TARGET_METHOD)]
final class SearchGridRequestBody extends RequestBody
{
public function __construct()
{
parent::__construct(
required: true,
content: new JsonContent(
required: ['columns'],
properties: [
new Property(
property: 'columns',
type: 'array',
items: new Items(ref: Column::class)
),
new Property(
property: 'filters',
ref: Filter::class,
type: 'object'
),
],
type: 'object',
),
);
}
}
41 changes: 41 additions & 0 deletions src/Grid/MappedParameter/SearchGridParameter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?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\Grid\MappedParameter;

use Pimcore\Bundle\StudioBackendBundle\Filter\MappedParameter\FilterParameter;

/**
* @internal
*/
final readonly class SearchGridParameter
{
public function __construct(
private array $columns,
private ?FilterParameter $filters
) {
}

public function getColumns(): array
{
return $this->columns;
}

public function getFilters(): FilterParameter
{
return $this->filters ?? new FilterParameter();
}
}
48 changes: 48 additions & 0 deletions src/Grid/Service/GridSearchService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?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\Grid\Service;

use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\GridParameter;
use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\SearchGridParameter;
use Pimcore\Bundle\StudioBackendBundle\Response\Collection;

/**
* @internal
*/
final readonly class GridSearchService implements GridSearchServiceInterface
{
public function __construct(
private GridServiceInterface $gridService
) {
}

/**
* {@inheritDoc}
*/
public function getAssetSearchGrid(SearchGridParameter $gridParameter): Collection
{
$filter = $gridParameter->getFilters();
$filter->setExcludeFolders(false);
$parameter = new GridParameter(
folderId: 1,
columns: $gridParameter->getColumns(),
filters: $filter
);

return $this->gridService->getAssetGrid($parameter);
}
}
32 changes: 32 additions & 0 deletions src/Grid/Service/GridSearchServiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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\Grid\Service;

use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
use Pimcore\Bundle\StudioBackendBundle\Grid\MappedParameter\SearchGridParameter;
use Pimcore\Bundle\StudioBackendBundle\Response\Collection;

/**
* @internal
*/
interface GridSearchServiceInterface
{
/**
* @throws InvalidArgumentException
*/
public function getAssetSearchGrid(SearchGridParameter $gridParameter): Collection;
}
2 changes: 1 addition & 1 deletion src/Grid/Service/GridService.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __construct(
}

/**
* @throws InvalidArgumentException
* {@inheritDoc}
*/
public function getAssetGrid(GridParameter $gridParameter): Collection
{
Expand Down
3 changes: 3 additions & 0 deletions src/Grid/Service/GridServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public function getGridValuesForElement(

public function getConfigurationFromArray(array $config, bool $isExport = false): ColumnCollection;

/**
* @throws InvalidArgumentException
*/
public function getAssetGrid(GridParameter $gridParameter): Collection;

/**
Expand Down
3 changes: 3 additions & 0 deletions translations/studio_api_docs.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ asset_get_grid_description: |
</ul>
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 <strong>{id}</strong>. <br> The <strong>{id}</strong> must be an ID of existing asset.
asset_get_text_data_by_id_success_response: Successfully retrieved UTF8 encoded text data of asset
Expand Down
Loading