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/classification_store.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ services:
Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\KeyGroupRelationServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\KeyGroupRelationService

Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\SearchHelperServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\SearchHelperService


#
# Repositories
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ public function __construct(
required: true,
example: 'technicalAttributes'
)]
#[TextFieldParameter(
name: 'searchTerm',
description: 'Search Term',
required: false,
example: 'search term'
)]
#[DefaultResponses([
HttpResponseCodes::FORBIDDEN,
HttpResponseCodes::UNAUTHORIZED,
Expand Down
6 changes: 6 additions & 0 deletions src/ClassificationStore/Controller/GetGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public function __construct(
namePrefix: 'object',
required: false
)]
#[TextFieldParameter(
name: 'searchTerm',
description: 'Search Term',
required: false,
example: 'search term'
)]
#[PageParameter]
#[PageSizeParameter]
#[TextFieldParameter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public function __construct(
namePrefix: 'object',
required: false
)]
#[TextFieldParameter(
name: 'searchTerm',
description: 'Search Term',
required: false,
example: 'search term'
)]
#[PageParameter]
#[PageSizeParameter]
#[TextFieldParameter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function __construct(
#[NotBlank(message: 'The page size name must not be empty.')]
private int $pageSize,
private ?int $objectId = null,
private ?string $searchTerm = null,
) {
}

Expand Down Expand Up @@ -61,4 +62,9 @@ public function getPageSize(): int
{
return $this->pageSize;
}

public function getSearchTerm(): ?string
{
return $this->searchTerm;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository;

use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\SearchHelperServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\CollectionParametersInterface;
use Pimcore\Model\DataObject\Classificationstore\CollectionConfig\Listing;
use function count;
Expand All @@ -25,13 +26,19 @@
*/
final class CollectionConfigRepository implements CollectionConfigRepositoryInterface
{
public function __construct(
private SearchHelperServiceInterface $searchHelperService
) {
}

/**
* {@inheritDoc}
*/
public function getPaginatedCollectionsByStore(
int $storeId,
CollectionParametersInterface $collectionParameters,
?array $collectionIds = null
?array $collectionIds = null,
?string $searchTerm = null
): array {
$list = new Listing();

Expand All @@ -45,6 +52,10 @@ public function getPaginatedCollectionsByStore(
$this->applyCollectionIdsFilter($list, $collectionIds);
}

if ($searchTerm !== null) {
$this->searchHelperService->applySearchTermFilter($list, $searchTerm);
}

return $list->load();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ interface CollectionConfigRepositoryInterface
public function getPaginatedCollectionsByStore(
int $storeId,
CollectionParametersInterface $collectionParameters,
?array $collectionIds = null
?array $collectionIds = null,
?string $searchTerm = null
): array;

public function getCountByStoreId(int $storeId): int;
Expand Down
13 changes: 12 additions & 1 deletion src/ClassificationStore/Repository/GroupConfigRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository;

use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\SearchHelperServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\CollectionParametersInterface;
use Pimcore\Model\DataObject\Classificationstore\GroupConfig\Listing;
use function count;
Expand All @@ -25,13 +26,19 @@
*/
final class GroupConfigRepository implements GroupConfigRepositoryInterface
{
public function __construct(
private SearchHelperServiceInterface $searchHelperService
) {
}

/**
* {@inheritDoc}
*/
public function getPaginatedGroupsByStore(
int $storeId,
CollectionParametersInterface $collectionParameters,
?array $groupIds = null
?array $groupIds = null,
?string $searchTerm = null
): array {
$listing = new Listing();

Expand All @@ -41,6 +48,10 @@ public function getPaginatedGroupsByStore(
$listing->setOrderKey('id');
$listing->setCondition('storeId = ?', $storeId);

if ($searchTerm !== null) {
$this->searchHelperService->applySearchTermFilter($listing, $searchTerm);
}

if ($groupIds !== null) {
$this->applyGroupIdsFilter($listing, $groupIds);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ interface GroupConfigRepositoryInterface
public function getPaginatedGroupsByStore(
int $storeId,
CollectionParametersInterface $collectionParameters,
?array $groupIds = null
?array $groupIds = null,
?string $searchTerm = null
): array;

public function getAllGroupsByStore(
Expand Down
33 changes: 29 additions & 4 deletions src/ClassificationStore/Repository/KeyGroupRelationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@

namespace Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository;

use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\SearchHelperServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\CollectionParametersInterface;
use Pimcore\Model\DataObject\Classificationstore\GroupConfig\Dao as GroupConfigDao;
use Pimcore\Model\DataObject\Classificationstore\KeyConfig\Dao as KeyConfigDao;
use Pimcore\Model\DataObject\Classificationstore\KeyGroupRelation\Listing;
use function count;

/**
* @internal
*/
final class KeyGroupRelationRepository implements KeyGroupRelationRepositoryInterface
final readonly class KeyGroupRelationRepository implements KeyGroupRelationRepositoryInterface
{
public function __construct(
private GroupConfigRepositoryInterface $groupConfigRepository
private GroupConfigRepositoryInterface $groupConfigRepository,
private SearchHelperServiceInterface $searchHelperService
) {
}

Expand All @@ -36,7 +40,8 @@ public function __construct(
public function getPaginatedKeyGroupRelationByStore(
int $storeId,
CollectionParametersInterface $collectionParameters,
?array $groupIds = null
?array $groupIds = null,
?string $searchTerm = null
): array {

$groupIds = array_map(
Expand All @@ -50,7 +55,11 @@ public function getPaginatedKeyGroupRelationByStore(
$listing->setOrderKey('sorter');
$this->applyGroupIdsFilter($listing, $groupIds);

return $listing->load();
if ($searchTerm !== null) {
$this->applySearchTermFilter($listing, $searchTerm);
}

return $listing->getList();
}

public function getCountByStoreId(int $storeId, ?array $groupIds = null): int
Expand All @@ -66,6 +75,22 @@ public function getCountByStoreId(int $storeId, ?array $groupIds = null): int
return $listing->count();
}

private function applySearchTermFilter(Listing $list, string $searchTerm): void
{
$searchTerms = $this->searchHelperService->getTranslatedSearchFilterTerms($searchTerm);
$searchFilterConditions = [];

foreach ($searchTerms as $term) {
$searchFilterConditions[] =
KeyConfigDao::TABLE_NAME_KEYS.'.name LIKE '.$list->quote('%'.$term.'%')
.' OR '.GroupConfigDao::TABLE_NAME_GROUPS.'.name LIKE '.$list->quote('%'.$term.'%')
.' OR '.KeyConfigDao::TABLE_NAME_KEYS.'.description LIKE '.$list->quote('%'.$term.'%');
}
$list->setResolveGroupName(true);

$list->addConditionParam(implode(' OR ', $searchFilterConditions));
}

private function applyGroupIdsFilter(Listing $list, array $groupIds): void
{
$placeholders = implode(',', array_fill(0, count($groupIds), '?'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ interface KeyGroupRelationRepositoryInterface
public function getPaginatedKeyGroupRelationByStore(
int $storeId,
CollectionParametersInterface $collectionParameters,
?array $groupIds = null
?array $groupIds = null,
?string $searchTerm = null
): array;

public function getCountByStoreId(int $storeId, ?array $groupIds = null): int;
Expand Down
3 changes: 2 additions & 1 deletion src/ClassificationStore/Service/CollectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public function getCollections(ListClassificationStoreParameter $parameter): Col
$collections = $this->collectionConfigRepository->getPaginatedCollectionsByStore(
$parameter->getStoreId(),
$parameter,
$allowedCollectionIds
$allowedCollectionIds,
$parameter->getSearchTerm()
);

$hydratedCollections = [];
Expand Down
3 changes: 2 additions & 1 deletion src/ClassificationStore/Service/GroupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public function getGroups(ListClassificationStoreParameter $parameter): Collecti
$groups = $this->groupConfigRepository->getPaginatedGroupsByStore(
$parameter->getStoreId(),
$parameter,
$allowedGroupIds
$allowedGroupIds,
$parameter->getSearchTerm()
);

$hydratedGroups = [];
Expand Down
3 changes: 2 additions & 1 deletion src/ClassificationStore/Service/KeyGroupRelationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public function getKeyGroupRelations(ListClassificationStoreParameter $parameter
$keyGroupRelations = $this->keyGroupRelationRepository->getPaginatedKeyGroupRelationByStore(
$parameter->getStoreId(),
$parameter,
$allowedGroupIds
$allowedGroupIds,
$parameter->getSearchTerm()
);

foreach ($keyGroupRelations as $keyGroupRelation) {
Expand Down
70 changes: 70 additions & 0 deletions src/ClassificationStore/Service/SearchHelperService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?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\ClassificationStore\Service;

use Pimcore\Bundle\StudioBackendBundle\Exception\Api\UserNotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Security\Service\SecurityServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Translation\Repository\TranslationRepositoryInterface;
use Pimcore\Model\DataObject\Classificationstore\CollectionConfig\Listing as CollectionConfigListing;
use Pimcore\Model\DataObject\Classificationstore\GroupConfig\Listing as GroupConfigListing;
use Pimcore\Model\Translation;

/**
* @internal
*/
final readonly class SearchHelperService implements SearchHelperServiceInterface
{
public function __construct(
private TranslationRepositoryInterface $translationRepository,
private SecurityServiceInterface $securityService
) {
}

public function applySearchTermFilter(GroupConfigListing|CollectionConfigListing $list, string $searchTerm): void
{
$searchTerms = $this->getTranslatedSearchFilterTerms($searchTerm);

$conditions = [];
$preparedSearchTerms = [];
foreach ($searchTerms as $term) {
$conditions[] = 'name LIKE ? OR description LIKE ?';
$preparedSearchTerms[] = '%' . $term . '%';
$preparedSearchTerms[] = '%' . $term . '%';
}

$list->addConditionParam('(' . implode(' OR ', $conditions) . ')', $preparedSearchTerms);
}

public function getTranslatedSearchFilterTerms(string $searchTerm): array
{
try {
$user = $this->securityService->getCurrentUser();

$translatedSearchKeys = $this->translationRepository->getTranslationKeysWithTextFilter(
$searchTerm,
$user->getLanguage(),
Translation::DOMAIN_ADMIN
);

$searchTerms = array_merge([$searchTerm], $translatedSearchKeys);
} catch (UserNotFoundException) {
$searchTerms = [$searchTerm];
}

return $searchTerms;
}
}
30 changes: 30 additions & 0 deletions src/ClassificationStore/Service/SearchHelperServiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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\ClassificationStore\Service;

use Pimcore\Model\DataObject\Classificationstore\CollectionConfig\Listing as CollectionConfigListing;
use Pimcore\Model\DataObject\Classificationstore\GroupConfig\Listing as GroupConfigListing;

/**
* @internal
*/
interface SearchHelperServiceInterface
{
public function applySearchTermFilter(GroupConfigListing|CollectionConfigListing $list, string $searchTerm): void;

public function getTranslatedSearchFilterTerms(string $searchTerm): array;
}
Loading