mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-04 13:54:59 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -18,35 +18,26 @@ use Chill\MainBundle\Search\SearchApiQuery;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\NonUniqueResultException;
|
||||
use Doctrine\ORM\Query;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
use function array_fill;
|
||||
use function array_map;
|
||||
use function array_merge;
|
||||
use function array_push;
|
||||
use function count;
|
||||
use function explode;
|
||||
use function implode;
|
||||
|
||||
final readonly class PersonACLAwareRepository implements PersonACLAwareRepositoryInterface
|
||||
{
|
||||
public function __construct(private Security $security, private EntityManagerInterface $em, private CountryRepository $countryRepository, private AuthorizationHelperInterface $authorizationHelper) {}
|
||||
|
||||
public function buildAuthorizedQuery(
|
||||
?string $default = null,
|
||||
?string $firstname = null,
|
||||
?string $lastname = null,
|
||||
?DateTimeInterface $birthdate = null,
|
||||
?DateTimeInterface $birthdateBefore = null,
|
||||
?DateTimeInterface $birthdateAfter = null,
|
||||
?string $gender = null,
|
||||
?string $countryCode = null,
|
||||
?string $phonenumber = null,
|
||||
?string $city = null
|
||||
string $default = null,
|
||||
string $firstname = null,
|
||||
string $lastname = null,
|
||||
\DateTimeInterface $birthdate = null,
|
||||
\DateTimeInterface $birthdateBefore = null,
|
||||
\DateTimeInterface $birthdateAfter = null,
|
||||
string $gender = null,
|
||||
string $countryCode = null,
|
||||
string $phonenumber = null,
|
||||
string $city = null
|
||||
): SearchApiQuery {
|
||||
$query = $this->createSearchQuery(
|
||||
$default,
|
||||
@@ -65,16 +56,16 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
|
||||
}
|
||||
|
||||
public function countBySearchCriteria(
|
||||
?string $default = null,
|
||||
?string $firstname = null,
|
||||
?string $lastname = null,
|
||||
?DateTimeInterface $birthdate = null,
|
||||
?DateTimeInterface $birthdateBefore = null,
|
||||
?DateTimeInterface $birthdateAfter = null,
|
||||
?string $gender = null,
|
||||
?string $countryCode = null,
|
||||
?string $phonenumber = null,
|
||||
?string $city = null
|
||||
string $default = null,
|
||||
string $firstname = null,
|
||||
string $lastname = null,
|
||||
\DateTimeInterface $birthdate = null,
|
||||
\DateTimeInterface $birthdateBefore = null,
|
||||
\DateTimeInterface $birthdateAfter = null,
|
||||
string $gender = null,
|
||||
string $countryCode = null,
|
||||
string $phonenumber = null,
|
||||
string $city = null
|
||||
): int {
|
||||
$query = $this->buildAuthorizedQuery(
|
||||
$default,
|
||||
@@ -99,16 +90,16 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
|
||||
* @throws ParsingException
|
||||
*/
|
||||
public function createSearchQuery(
|
||||
?string $default = null,
|
||||
?string $firstname = null,
|
||||
?string $lastname = null,
|
||||
?DateTimeInterface $birthdate = null,
|
||||
?DateTimeInterface $birthdateBefore = null,
|
||||
?DateTimeInterface $birthdateAfter = null,
|
||||
?string $gender = null,
|
||||
?string $countryCode = null,
|
||||
?string $phonenumber = null,
|
||||
?string $city = null
|
||||
string $default = null,
|
||||
string $firstname = null,
|
||||
string $lastname = null,
|
||||
\DateTimeInterface $birthdate = null,
|
||||
\DateTimeInterface $birthdateBefore = null,
|
||||
\DateTimeInterface $birthdateAfter = null,
|
||||
string $gender = null,
|
||||
string $countryCode = null,
|
||||
string $phonenumber = null,
|
||||
string $city = null
|
||||
): SearchApiQuery {
|
||||
$query = new SearchApiQuery();
|
||||
$query
|
||||
@@ -120,25 +111,25 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
|
||||
$andWhereSearchClauseArgs = [];
|
||||
|
||||
if ('' !== trim($default)) {
|
||||
foreach (explode(' ', $default) as $str) {
|
||||
foreach (\explode(' ', $default) as $str) {
|
||||
if ('' === trim($str)) {
|
||||
continue;
|
||||
}
|
||||
$pertinence[] =
|
||||
'STRICT_WORD_SIMILARITY(LOWER(UNACCENT(?)), person.fullnamecanonical) + ' .
|
||||
"(person.fullnamecanonical LIKE '%' || LOWER(UNACCENT(?)) || '%')::int + " .
|
||||
"(EXISTS (SELECT 1 FROM unnest(string_to_array(fullnamecanonical, ' ')) AS t WHERE starts_with(t, UNACCENT(LOWER(?)))))::int + " .
|
||||
'STRICT_WORD_SIMILARITY(LOWER(UNACCENT(?)), person.fullnamecanonical) + '.
|
||||
"(person.fullnamecanonical LIKE '%' || LOWER(UNACCENT(?)) || '%')::int + ".
|
||||
"(EXISTS (SELECT 1 FROM unnest(string_to_array(fullnamecanonical, ' ')) AS t WHERE starts_with(t, UNACCENT(LOWER(?)))))::int + ".
|
||||
'(starts_with(LOWER(UNACCENT(lastname)), UNACCENT(LOWER(?))))::int';
|
||||
array_push($pertinenceArgs, $str, $str, $str, $str);
|
||||
\array_push($pertinenceArgs, $str, $str, $str, $str);
|
||||
|
||||
$andWhereSearchClause[] =
|
||||
'(LOWER(UNACCENT(?)) <<% person.fullnamecanonical OR ' .
|
||||
'(LOWER(UNACCENT(?)) <<% person.fullnamecanonical OR '.
|
||||
"person.fullnamecanonical LIKE '%' || LOWER(UNACCENT(?)) || '%' )";
|
||||
array_push($andWhereSearchClauseArgs, $str, $str);
|
||||
\array_push($andWhereSearchClauseArgs, $str, $str);
|
||||
}
|
||||
|
||||
$query->andWhereClause(
|
||||
implode(' AND ', $andWhereSearchClause),
|
||||
\implode(' AND ', $andWhereSearchClause),
|
||||
$andWhereSearchClauseArgs
|
||||
);
|
||||
} else {
|
||||
@@ -146,7 +137,7 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
|
||||
$pertinenceArgs = [];
|
||||
}
|
||||
$query
|
||||
->setSelectPertinence(implode(' + ', $pertinence), $pertinenceArgs);
|
||||
->setSelectPertinence(\implode(' + ', $pertinence), $pertinenceArgs);
|
||||
|
||||
if (null !== $birthdate) {
|
||||
$query->andWhereClause(
|
||||
@@ -188,16 +179,16 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
|
||||
"person.phonenumber LIKE '%' || ? || '%' OR person.mobilenumber LIKE '%' || ? || '%' OR pp.phonenumber LIKE '%' || ? || '%'",
|
||||
[$phonenumber, $phonenumber, $phonenumber]
|
||||
);
|
||||
$query->setFromClause($query->getFromClause() . ' LEFT JOIN chill_person_phone pp ON pp.person_id = person.id');
|
||||
$query->setFromClause($query->getFromClause().' LEFT JOIN chill_person_phone pp ON pp.person_id = person.id');
|
||||
}
|
||||
|
||||
if (null !== $city) {
|
||||
$query->setFromClause($query->getFromClause() . ' ' .
|
||||
'JOIN view_chill_person_current_address vcpca ON vcpca.person_id = person.id ' .
|
||||
'JOIN chill_main_address cma ON vcpca.address_id = cma.id ' .
|
||||
$query->setFromClause($query->getFromClause().' '.
|
||||
'JOIN view_chill_person_current_address vcpca ON vcpca.person_id = person.id '.
|
||||
'JOIN chill_main_address cma ON vcpca.address_id = cma.id '.
|
||||
'JOIN chill_main_postal_code cmpc ON cma.postcode_id = cmpc.id');
|
||||
|
||||
foreach (explode(' ', $city) as $cityStr) {
|
||||
foreach (\explode(' ', $city) as $cityStr) {
|
||||
$query->andWhereClause(
|
||||
"(UNACCENT(LOWER(cmpc.label)) LIKE '%' || UNACCENT(LOWER(?)) || '%' OR cmpc.code LIKE '%' || UNACCENT(LOWER(?)) || '%')",
|
||||
[$cityStr, $city]
|
||||
@@ -206,7 +197,7 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
|
||||
}
|
||||
|
||||
if (null !== $countryCode) {
|
||||
$query->setFromClause($query->getFromClause() . ' JOIN country ON person.nationality_id = country.id');
|
||||
$query->setFromClause($query->getFromClause().' JOIN country ON person.nationality_id = country.id');
|
||||
$query->andWhereClause('country.countrycode = UPPER(?)', [$countryCode]);
|
||||
}
|
||||
|
||||
@@ -239,33 +230,33 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
|
||||
$query->addSelectClause($rsm->generateSelectClause());
|
||||
|
||||
$nql = $this->em->createNativeQuery(
|
||||
$query->buildQuery() . ' ORDER BY pertinence DESC OFFSET ? LIMIT ?',
|
||||
$query->buildQuery().' ORDER BY pertinence DESC OFFSET ? LIMIT ?',
|
||||
$rsm
|
||||
)->setParameters(array_merge($query->buildParameters(), [$start, $limit]));
|
||||
)->setParameters(\array_merge($query->buildParameters(), [$start, $limit]));
|
||||
|
||||
return $nql->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|Person[]
|
||||
*
|
||||
* @throws NonUniqueResultException
|
||||
* @throws ParsingException
|
||||
*
|
||||
* @return array|Person[]
|
||||
*/
|
||||
public function findBySearchCriteria(
|
||||
int $start,
|
||||
int $limit,
|
||||
bool $simplify = false,
|
||||
?string $default = null,
|
||||
?string $firstname = null,
|
||||
?string $lastname = null,
|
||||
?DateTimeInterface $birthdate = null,
|
||||
?DateTimeInterface $birthdateBefore = null,
|
||||
?DateTimeInterface $birthdateAfter = null,
|
||||
?string $gender = null,
|
||||
?string $countryCode = null,
|
||||
?string $phonenumber = null,
|
||||
?string $city = null
|
||||
string $default = null,
|
||||
string $firstname = null,
|
||||
string $lastname = null,
|
||||
\DateTimeInterface $birthdate = null,
|
||||
\DateTimeInterface $birthdateBefore = null,
|
||||
\DateTimeInterface $birthdateAfter = null,
|
||||
string $gender = null,
|
||||
string $countryCode = null,
|
||||
string $phonenumber = null,
|
||||
string $city = null
|
||||
): array {
|
||||
$query = $this->buildAuthorizedQuery(
|
||||
$default,
|
||||
@@ -293,18 +284,18 @@ final readonly class PersonACLAwareRepository implements PersonACLAwareRepositor
|
||||
}
|
||||
|
||||
return $query
|
||||
->setFromClause($query->getFromClause() . ' JOIN view_chill_person_person_center_history_current vcppchc ON vcppchc.person_id = person.id', $query->getFromParams())
|
||||
->setFromClause($query->getFromClause().' JOIN view_chill_person_person_center_history_current vcppchc ON vcppchc.person_id = person.id', $query->getFromParams())
|
||||
->andWhereClause(
|
||||
strtr(
|
||||
'vcppchc.center_id IN ({{ center_ids }})',
|
||||
[
|
||||
'{{ center_ids }}' => implode(
|
||||
'{{ center_ids }}' => \implode(
|
||||
', ',
|
||||
array_fill(0, count($authorizedCenters), '?')
|
||||
\array_fill(0, \count($authorizedCenters), '?')
|
||||
),
|
||||
]
|
||||
),
|
||||
array_map(static fn (Center $c) => $c->getId(), $authorizedCenters)
|
||||
\array_map(static fn (Center $c) => $c->getId(), $authorizedCenters)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user