mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-11 17:25:02 +00:00
Add search functionality for user groups
Implemented `SearchUserGroupApiProvider` to handle user group search requests. Added `UserGroupRepository` and its interface to support search queries. Updated API specs to include user group as a searchable type.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Search\Entity;
|
||||
|
||||
use Chill\MainBundle\Repository\UserGroupRepositoryInterface;
|
||||
use Chill\MainBundle\Search\SearchApiInterface;
|
||||
use Chill\MainBundle\Search\SearchApiQuery;
|
||||
use Symfony\Contracts\Translation\LocaleAwareInterface;
|
||||
|
||||
/**
|
||||
* Provide search api for user group.
|
||||
*/
|
||||
class SearchUserGroupApiProvider implements SearchApiInterface, LocaleAwareInterface
|
||||
{
|
||||
private string $locale;
|
||||
|
||||
public function __construct(private readonly UserGroupRepositoryInterface $userGroupRepository) {}
|
||||
|
||||
public function setLocale(string $locale): void
|
||||
{
|
||||
$this->locale = $locale;
|
||||
}
|
||||
|
||||
public function getLocale(): string
|
||||
{
|
||||
return $this->locale;
|
||||
}
|
||||
|
||||
public function getResult(string $key, array $metadata, float $pertinence)
|
||||
{
|
||||
return $this->userGroupRepository->find($metadata['id']);
|
||||
}
|
||||
|
||||
public function prepare(array $metadatas): void {}
|
||||
|
||||
public function provideQuery(string $pattern, array $parameters): SearchApiQuery
|
||||
{
|
||||
return $this->userGroupRepository->provideSearchApiQuery($pattern, $this->getLocale(), 'user-group');
|
||||
}
|
||||
|
||||
public function supportsResult(string $key, array $metadatas): bool
|
||||
{
|
||||
return 'user-group' === $key;
|
||||
}
|
||||
|
||||
public function supportsTypes(string $pattern, array $types, array $parameters): bool
|
||||
{
|
||||
return in_array('user-group', $types, true);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user