mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-29 02:53:50 +00:00
Fixing generic doc providers from calendar + fix cs
This commit is contained in:
@@ -24,9 +24,15 @@ use DateTimeImmutable;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Mapping\MappingException;
|
||||
use Service\GenericDoc\Providers\PersonCalendarGenericDocProviderTest;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
final class PersonCalendarGenericDocProvider implements GenericDocForPersonProviderInterface
|
||||
/**
|
||||
* Provide calendar documents for calendar associated to persons
|
||||
*
|
||||
* @see PersonCalendarGenericDocProviderTest
|
||||
*/
|
||||
final readonly class PersonCalendarGenericDocProvider implements GenericDocForPersonProviderInterface
|
||||
{
|
||||
public const KEY = 'person_calendar_document';
|
||||
|
||||
@@ -36,7 +42,6 @@ final class PersonCalendarGenericDocProvider implements GenericDocForPersonProvi
|
||||
) {
|
||||
}
|
||||
|
||||
|
||||
private function addWhereClausesToQuery(FetchQuery $query, ?\DateTimeImmutable $startDate = null, ?\DateTimeImmutable $endDate = null, ?string $content = null): FetchQuery
|
||||
{
|
||||
$storedObjectMetadata = $this->em->getClassMetadata(StoredObject::class);
|
||||
@@ -84,50 +89,30 @@ final class PersonCalendarGenericDocProvider implements GenericDocForPersonProvi
|
||||
$classMetadata->getSchemaName().'.'.$classMetadata->getTableName().' AS cd'
|
||||
);
|
||||
$query->addJoinClause(
|
||||
sprintf('JOIN %s doc_store ON doc_store.%s = cd.%s',
|
||||
sprintf(
|
||||
'JOIN %s doc_store ON doc_store.%s = cd.%s',
|
||||
$storedObjectMetadata->getSchemaName().'.'.$storedObjectMetadata->getTableName(),
|
||||
$storedObjectMetadata->getColumnName('id'),
|
||||
$classMetadata->getSingleAssociationJoinColumnName('storedObject')
|
||||
));
|
||||
)
|
||||
);
|
||||
|
||||
$query->addJoinClause(
|
||||
sprintf('JOIN %s calendar ON calendar.%s = cd.%s',
|
||||
sprintf(
|
||||
'JOIN %s calendar ON calendar.%s = cd.%s',
|
||||
$calendarMetadata->getSchemaName().'.'.$calendarMetadata->getTableName(),
|
||||
$calendarMetadata->getColumnName('id'),
|
||||
$classMetadata->getSingleAssociationJoinColumnName('calendar')
|
||||
)
|
||||
);
|
||||
|
||||
// get the documents associated with accompanying periods in which person participates
|
||||
$or = [];
|
||||
$orParams = [];
|
||||
$orTypes = [];
|
||||
foreach ($person->getAccompanyingPeriodParticipations() as $participation) {
|
||||
if (!$this->security->isGranted(CalendarVoter::SEE, $participation->getAccompanyingPeriod())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$or[] = sprintf(
|
||||
'(calendar.%s = ? AND cd.%s BETWEEN ?::date AND COALESCE(?::date, \'infinity\'::date))',
|
||||
$calendarMetadata->getSingleAssociationJoinColumnName('accompanyingPeriod'),
|
||||
$storedObjectMetadata->getColumnName('createdAt')
|
||||
);
|
||||
$orParams = [...$orParams, $participation->getAccompanyingPeriod()->getId(),
|
||||
DateTimeImmutable::createFromInterface($participation->getStartDate()),
|
||||
null === $participation->getEndDate() ? null : DateTimeImmutable::createFromInterface($participation->getEndDate())];
|
||||
$orTypes = [...$orTypes, Types::INTEGER, Types::DATE_IMMUTABLE, Types::DATE_IMMUTABLE];
|
||||
}
|
||||
|
||||
if ([] === $or) {
|
||||
$query->addWhereClause('TRUE = FALSE');
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
// $query->addWhereClause(sprintf('(%s)', implode(' OR ', $or)), $orParams, $orTypes);
|
||||
$query->addWhereClause(
|
||||
sprintf('calendar.%s = ?', $calendarMetadata->getSingleAssociationJoinColumnName('person')),
|
||||
[$person->getId()],
|
||||
[Types::INTEGER]
|
||||
);
|
||||
|
||||
return $this->addWhereClausesToQuery($query, $startDate, $endDate, $content);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user