mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
show documents from person in list of document from course
This commit is contained in:
@@ -22,6 +22,8 @@ use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
@@ -29,19 +31,14 @@ use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
class PersonDocumentACLAwareRepository implements PersonDocumentACLAwareRepositoryInterface
|
||||
final readonly class PersonDocumentACLAwareRepository implements PersonDocumentACLAwareRepositoryInterface
|
||||
{
|
||||
private AuthorizationHelperForCurrentUserInterface $authorizationHelperForCurrentUser;
|
||||
|
||||
private CenterResolverManagerInterface $centerResolverManager;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em, CenterResolverManagerInterface $centerResolverManager, AuthorizationHelperForCurrentUserInterface $authorizationHelperForCurrentUser)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->centerResolverManager = $centerResolverManager;
|
||||
$this->authorizationHelperForCurrentUser = $authorizationHelperForCurrentUser;
|
||||
public function __construct(
|
||||
private EntityManagerInterface $em,
|
||||
private CenterResolverManagerInterface $centerResolverManager,
|
||||
private AuthorizationHelperForCurrentUserInterface $authorizationHelperForCurrentUser,
|
||||
private Security $security,
|
||||
) {
|
||||
}
|
||||
|
||||
public function buildQueryByPerson(Person $person): QueryBuilder
|
||||
@@ -63,6 +60,66 @@ class PersonDocumentACLAwareRepository implements PersonDocumentACLAwareReposito
|
||||
return $this->addFetchQueryByPersonACL($query, $person);
|
||||
}
|
||||
|
||||
public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $period, ?\DateTimeImmutable $startDate = null, ?\DateTimeImmutable $endDate = null, ?string $content = null): FetchQueryInterface
|
||||
{
|
||||
$personDocMetadata = $this->em->getClassMetadata(PersonDocument::class);
|
||||
$participationMetadata = $this->em->getClassMetadata(AccompanyingPeriodParticipation::class);
|
||||
|
||||
$query = new FetchQuery(
|
||||
PersonDocumentGenericDocProvider::KEY,
|
||||
sprintf('jsonb_build_object(\'id\', person_document.%s)', $personDocMetadata->getSingleIdentifierColumnName()),
|
||||
sprintf('person_document.%s', $personDocMetadata->getColumnName('date')),
|
||||
sprintf('%s AS person_document', $personDocMetadata->getSchemaName().'.'.$personDocMetadata->getTableName())
|
||||
);
|
||||
|
||||
$query->addJoinClause(
|
||||
sprintf(
|
||||
'JOIN %s AS participation ON participation.%s = person_document.%s '.
|
||||
'AND person_document.%s BETWEEN participation.%s AND COALESCE(participation.%s, \'infinity\'::date)',
|
||||
$participationMetadata->getTableName(),
|
||||
$participationMetadata->getSingleAssociationJoinColumnName('person'),
|
||||
$personDocMetadata->getSingleAssociationJoinColumnName('person'),
|
||||
$personDocMetadata->getColumnName('date'),
|
||||
$participationMetadata->getColumnName('startDate'),
|
||||
$participationMetadata->getColumnName('endDate')
|
||||
)
|
||||
);
|
||||
|
||||
$query->addWhereClause(
|
||||
sprintf('participation.%s = ?', $participationMetadata->getSingleAssociationJoinColumnName('accompanyingPeriod')),
|
||||
[$period->getId()],
|
||||
[Types::INTEGER]
|
||||
);
|
||||
|
||||
// can we see the document for this person ?
|
||||
$orPersonId = [];
|
||||
foreach ($period->getParticipations() as $participation) {
|
||||
if (!$this->security->isGranted(PersonDocumentVoter::SEE, $participation->getPerson())) {
|
||||
continue;
|
||||
}
|
||||
$orPersonId[] = $participation->getPerson()->getId();
|
||||
|
||||
}
|
||||
|
||||
if ([] === $orPersonId) {
|
||||
$query->addWhereClause('FALSE = TRUE');
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
$query->addWhereClause(
|
||||
sprintf(
|
||||
'participation.%s IN (%s)',
|
||||
$participationMetadata->getSingleAssociationJoinColumnName('person'),
|
||||
implode(', ', array_fill(0, count($orPersonId), '?'))
|
||||
),
|
||||
$orPersonId,
|
||||
array_fill(0, count($orPersonId), Types::INTEGER)
|
||||
);
|
||||
|
||||
return $this->addFilterClauses($query, $startDate, $endDate, $content);
|
||||
}
|
||||
|
||||
public function buildBaseFetchQueryForPerson(Person $person, ?DateTimeImmutable $startDate = null, ?DateTimeImmutable $endDate = null, ?string $content = null): FetchQuery
|
||||
{
|
||||
$personDocMetadata = $this->em->getClassMetadata(PersonDocument::class);
|
||||
@@ -80,6 +137,13 @@ class PersonDocumentACLAwareRepository implements PersonDocumentACLAwareReposito
|
||||
[Types::INTEGER]
|
||||
);
|
||||
|
||||
return $this->addFilterClauses($query, $startDate, $endDate, $content);
|
||||
}
|
||||
|
||||
private function addFilterClauses(FetchQuery $query, ?DateTimeImmutable $startDate = null, ?DateTimeImmutable $endDate = null, ?string $content = null): FetchQuery
|
||||
{
|
||||
$personDocMetadata = $this->em->getClassMetadata(PersonDocument::class);
|
||||
|
||||
if (null !== $startDate) {
|
||||
$query->addWhereClause(
|
||||
sprintf('? <= %s', $personDocMetadata->getColumnName('date')),
|
||||
@@ -107,7 +171,6 @@ class PersonDocumentACLAwareRepository implements PersonDocumentACLAwareReposito
|
||||
[Types::STRING, Types::STRING]
|
||||
);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user