mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user