mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-01 12:33:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,25 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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\PersonBundle\Search;
|
||||
|
||||
use Chill\MainBundle\Search\SearchApiInterface;
|
||||
use Chill\MainBundle\Search\SearchApiQuery;
|
||||
use Chill\MainBundle\Search\Utils\ExtractDateFromPattern;
|
||||
use Chill\MainBundle\Search\Utils\ExtractPhonenumberFromPattern;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||
use Chill\PersonBundle\Repository\PersonACLAwareRepositoryInterface;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
use Chill\MainBundle\Search\SearchApiQuery;
|
||||
use Chill\MainBundle\Search\SearchApiInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use function array_map;
|
||||
use function in_array;
|
||||
|
||||
class SearchPersonApiProvider implements SearchApiInterface
|
||||
{
|
||||
private PersonRepository $personRepository;
|
||||
private Security $security;
|
||||
private AuthorizationHelperInterface $authorizationHelper;
|
||||
|
||||
private ExtractDateFromPattern $extractDateFromPattern;
|
||||
private PersonACLAwareRepositoryInterface $personACLAwareRepository;
|
||||
|
||||
private ExtractPhonenumberFromPattern $extractPhonenumberFromPattern;
|
||||
|
||||
private PersonACLAwareRepositoryInterface $personACLAwareRepository;
|
||||
|
||||
private PersonRepository $personRepository;
|
||||
|
||||
private Security $security;
|
||||
|
||||
public function __construct(
|
||||
PersonRepository $personRepository,
|
||||
PersonACLAwareRepositoryInterface $personACLAwareRepository,
|
||||
@@ -36,6 +50,18 @@ class SearchPersonApiProvider implements SearchApiInterface
|
||||
$this->extractPhonenumberFromPattern = $extractPhonenumberFromPattern;
|
||||
}
|
||||
|
||||
public function getResult(string $key, array $metadata, float $pertinence)
|
||||
{
|
||||
return $this->personRepository->find($metadata['id']);
|
||||
}
|
||||
|
||||
public function prepare(array $metadatas): void
|
||||
{
|
||||
$ids = array_map(fn ($m) => $m['id'], $metadatas);
|
||||
|
||||
$this->personRepository->findByIds($ids);
|
||||
}
|
||||
|
||||
public function provideQuery(string $pattern, array $parameters): SearchApiQuery
|
||||
{
|
||||
$datesResult = $this->extractDateFromPattern->extractDates($pattern);
|
||||
@@ -43,40 +69,27 @@ class SearchPersonApiProvider implements SearchApiInterface
|
||||
$filtered = $phoneResult->getFilteredSubject();
|
||||
|
||||
return $this->personACLAwareRepository->buildAuthorizedQuery(
|
||||
$filtered,
|
||||
null,
|
||||
null,
|
||||
count($datesResult->getFound()) > 0 ? $datesResult->getFound()[0] : null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
count($phoneResult->getFound()) > 0 ? $phoneResult->getFound()[0] : null
|
||||
)
|
||||
->setSelectKey("person")
|
||||
$filtered,
|
||||
null,
|
||||
null,
|
||||
count($datesResult->getFound()) > 0 ? $datesResult->getFound()[0] : null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
count($phoneResult->getFound()) > 0 ? $phoneResult->getFound()[0] : null
|
||||
)
|
||||
->setSelectKey('person')
|
||||
->setSelectJsonbMetadata("jsonb_build_object('id', person.id)");
|
||||
}
|
||||
|
||||
|
||||
public function supportsTypes(string $pattern, array $types, array $parameters): bool
|
||||
{
|
||||
return \in_array('person', $types);
|
||||
}
|
||||
|
||||
public function prepare(array $metadatas): void
|
||||
{
|
||||
$ids = \array_map(fn($m) => $m['id'], $metadatas);
|
||||
|
||||
$this->personRepository->findByIds($ids);
|
||||
}
|
||||
|
||||
public function supportsResult(string $key, array $metadatas): bool
|
||||
{
|
||||
return $key === 'person';
|
||||
return 'person' === $key;
|
||||
}
|
||||
|
||||
public function getResult(string $key, array $metadata, float $pertinence)
|
||||
public function supportsTypes(string $pattern, array $types, array $parameters): bool
|
||||
{
|
||||
return $this->personRepository->find($metadata['id']);
|
||||
return in_array('person', $types);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user