cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,22 +1,29 @@
<?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\Repository\Household;
use Chill\MainBundle\Entity\AddressReference;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Security\Authorization\HouseholdVoter;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Security\Core\Security;
final class HouseholdACLAwareRepository implements HouseholdACLAwareRepositoryInterface
{
private AuthorizationHelper $authorizationHelper;
private EntityManagerInterface $em;
private AuthorizationHelper $authorizationHelper;
private Security $security;
public function __construct(EntityManagerInterface $em, AuthorizationHelper $authorizationHelper, Security $security)
@@ -26,6 +33,54 @@ final class HouseholdACLAwareRepository implements HouseholdACLAwareRepositoryIn
$this->security = $security;
}
public function addACL(QueryBuilder $qb, string $alias = 'h'): QueryBuilder
{
$centers = $this->authorizationHelper->getReachableCenters(
$this->security->getUser(),
HouseholdVoter::SHOW
);
if ([] === $centers) {
return $qb
->andWhere("'FALSE' = 'TRUE'");
}
$qb
->join($alias . '.members', 'members')
->join('members.person', 'person')
->andWhere(
$qb->expr()->in('person.center', ':centers')
)
->setParameter('centers', $centers);
return $qb;
}
public function buildQueryByAddressReference(AddressReference $addressReference): QueryBuilder
{
$qb = $this->em->createQueryBuilder();
$qb
->select('h')
->from(Household::class, 'h')
->join('h.addresses', 'address')
->where(
$qb->expr()->eq('address.addressReference', ':reference')
)
->setParameter(':reference', $addressReference)
->andWhere(
$qb->expr()->andX(
$qb->expr()->lte('address.validFrom', ':today'),
$qb->expr()->orX(
$qb->expr()->isNull('address.validTo'),
$qb->expr()->gt('address.validTo', ':today')
)
)
)
->setParameter('today', new DateTime('today'));
return $qb;
}
public function countByAddressReference(AddressReference $addressReference): int
{
$qb = $this->buildQueryByAddressReference($addressReference);
@@ -51,53 +106,4 @@ final class HouseholdACLAwareRepository implements HouseholdACLAwareRepositoryIn
->getQuery()
->getResult();
}
public function buildQueryByAddressReference(AddressReference $addressReference): QueryBuilder
{
$qb = $this->em->createQueryBuilder();
$qb
->select('h')
->from(Household::class, 'h')
->join('h.addresses', 'address')
->where(
$qb->expr()->eq('address.addressReference', ':reference')
)
->setParameter(':reference', $addressReference)
->andWhere(
$qb->expr()->andX(
$qb->expr()->lte('address.validFrom', ':today'),
$qb->expr()->orX(
$qb->expr()->isNull('address.validTo'),
$qb->expr()->gt('address.validTo', ':today')
)
)
)
->setParameter('today', new \DateTime('today'))
;
return $qb;
}
public function addACL(QueryBuilder $qb, string $alias = 'h'): QueryBuilder
{
$centers = $this->authorizationHelper->getReachableCenters(
$this->security->getUser(),
HouseholdVoter::SHOW
);
if ([] === $centers) {
return $qb
->andWhere("'FALSE' = 'TRUE'");
}
$qb
->join($alias.'.members', 'members')
->join('members.person', 'person')
->andWhere(
$qb->expr()->in('person.center', ':centers')
)
->setParameter('centers', $centers);
return $qb;
}
}

View File

@@ -1,5 +1,12 @@
<?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\Repository\Household;
use Chill\MainBundle\Entity\AddressReference;
@@ -10,9 +17,6 @@ interface HouseholdACLAwareRepositoryInterface
public function countByAddressReference(AddressReference $addressReference): int;
/**
* @param AddressReference $addressReference
* @param int|null $firstResult
* @param int|null $maxResult
* @return array|Household[]
*/
public function findByAddressReference(

View File

@@ -1,5 +1,12 @@
<?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.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Repository\Household;

View File

@@ -1,5 +1,12 @@
<?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\Repository\Household;
use Chill\PersonBundle\Entity\Household\Household;
@@ -8,18 +15,45 @@ use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
use Doctrine\Persistence\ObjectRepository;
use function strtr;
final class HouseholdRepository implements ObjectRepository
{
private EntityRepository $repository;
private const SQL_BY_ACCOMPANYING_PERIOD_PARTICIPATION = <<<'SQL'
WITH participations AS (
SELECT DISTINCT part.accompanyingperiod_id
FROM chill_person_accompanying_period_participation AS part
WHERE person_id = ?),
other_participants AS (
SELECT person_id, startDate, endDate
FROM chill_person_accompanying_period_participation
JOIN participations USING (accompanyingperiod_id)
WHERE person_id != ?
),
households AS (SELECT DISTINCT household.*
FROM chill_person_household_members AS hmembers
JOIN other_participants AS op USING (person_id)
JOIN chill_person_household AS household ON hmembers.household_id = household.id
WHERE daterange(op.startDate, op.endDate) && daterange(hmembers.startDate, hmembers.endDate)
)
SELECT {select} FROM households {limits}
SQL;
private EntityManagerInterface $em;
private EntityRepository $repository;
public function __construct(EntityManagerInterface $entityManager)
{
$this->repository = $entityManager->getRepository(Household::class);
$this->em = $entityManager;
}
public function countByAccompanyingPeriodParticipation(Person $person)
{
return $this->buildQueryByAccompanyingPeriodParticipation($person, true);
}
public function find($id)
{
return $this->repository->find($id);
@@ -35,6 +69,11 @@ final class HouseholdRepository implements ObjectRepository
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function findByAccompanyingPeriodParticipation(Person $person, int $limit, int $offset)
{
return $this->buildQueryByAccompanyingPeriodParticipation($person, false, $limit, $offset);
}
public function findOneBy(array $criteria)
{
return $this->findOneBy($criteria);
@@ -45,16 +84,6 @@ final class HouseholdRepository implements ObjectRepository
return Household::class;
}
public function countByAccompanyingPeriodParticipation(Person $person)
{
return $this->buildQueryByAccompanyingPeriodParticipation($person, true);
}
public function findByAccompanyingPeriodParticipation(Person $person, int $limit, int $offset)
{
return $this->buildQueryByAccompanyingPeriodParticipation($person, false, $limit, $offset);
}
private function buildQueryByAccompanyingPeriodParticipation(Person $person, bool $isCount = false, int $limit = 50, int $offset = 0)
{
$rsm = new ResultSetMappingBuilder($this->em);
@@ -62,14 +91,14 @@ final class HouseholdRepository implements ObjectRepository
if ($isCount) {
$rsm->addScalarResult('count', 'count');
$sql = \strtr(self::SQL_BY_ACCOMPANYING_PERIOD_PARTICIPATION, [
$sql = strtr(self::SQL_BY_ACCOMPANYING_PERIOD_PARTICIPATION, [
'{select}' => 'COUNT(households.*) AS count',
'{limits}' => ''
'{limits}' => '',
]);
} else {
$sql = \strtr(self::SQL_BY_ACCOMPANYING_PERIOD_PARTICIPATION, [
$sql = strtr(self::SQL_BY_ACCOMPANYING_PERIOD_PARTICIPATION, [
'{select}' => $rsm->generateSelectClause(['h' => 'households']),
'{limits}' => "OFFSET {$offset} LIMIT {$limit}"
'{limits}' => "OFFSET {$offset} LIMIT {$limit}",
]);
}
$native = $this->em->createNativeQuery($sql, $rsm);
@@ -77,28 +106,8 @@ final class HouseholdRepository implements ObjectRepository
if ($isCount) {
return $native->getSingleScalarResult();
} else {
return $native->getResult();
}
}
private CONST SQL_BY_ACCOMPANYING_PERIOD_PARTICIPATION = <<<SQL
WITH participations AS (
SELECT DISTINCT part.accompanyingperiod_id
FROM chill_person_accompanying_period_participation AS part
WHERE person_id = ?),
other_participants AS (
SELECT person_id, startDate, endDate
FROM chill_person_accompanying_period_participation
JOIN participations USING (accompanyingperiod_id)
WHERE person_id != ?
),
households AS (SELECT DISTINCT household.*
FROM chill_person_household_members AS hmembers
JOIN other_participants AS op USING (person_id)
JOIN chill_person_household AS household ON hmembers.household_id = household.id
WHERE daterange(op.startDate, op.endDate) && daterange(hmembers.startDate, hmembers.endDate)
)
SELECT {select} FROM households {limits}
SQL;
return $native->getResult();
}
}

View File

@@ -1,5 +1,12 @@
<?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\Repository\Household;
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
@@ -21,11 +28,6 @@ final class PersonHouseholdAddressRepository implements ObjectRepository
return $this->repository->find($id, $lockMode, $lockVersion);
}
public function findOneBy(array $criteria, array $orderBy = null): ?PersonHouseholdAddress
{
return $this->repository->findOneBy($criteria, $orderBy);
}
/**
* @return PersonHouseholdAddress[]
*/
@@ -35,14 +37,23 @@ final class PersonHouseholdAddressRepository implements ObjectRepository
}
/**
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return PersonHouseholdAddress[]
*/
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
public function getClassName() {
public function findOneBy(array $criteria, ?array $orderBy = null): ?PersonHouseholdAddress
{
return $this->repository->findOneBy($criteria, $orderBy);
}
public function getClassName()
{
return PersonHouseholdAddress::class;
}
}

View File

@@ -1,5 +1,12 @@
<?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\Repository\Household;
use Chill\PersonBundle\Entity\Household\Position;
@@ -18,6 +25,16 @@ final class PositionRepository implements ObjectRepository
$this->repository = $entityManager->getRepository(Position::class);
}
/**
* @param mixed $id
*
* @return Position
*/
public function find($id)
{
return $this->repository->find($id);
}
/**
* @return Position[]
*/
@@ -26,6 +43,17 @@ final class PositionRepository implements ObjectRepository
return $this->repository->findAll();
}
/**
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return Position[]
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
/**
* @return Position[]
*/
@@ -38,14 +66,6 @@ final class PositionRepository implements ObjectRepository
->getResult();
}
/**
* @return Position[]
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
/**
* @return Position[]
*/
@@ -54,14 +74,6 @@ final class PositionRepository implements ObjectRepository
return $this->repository->findOneBy($criteria);
}
/**
* @return Position
*/
public function find($id)
{
return $this->repository->find($id);
}
public function getClassName()
{
return Position::class;