mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
FEATURE [calendar][docs] try to implement showing calendar docs from parcours context in person context
This commit is contained in:
parent
5196d26a3e
commit
59e1e02b92
@ -19,6 +19,7 @@ use Chill\DocStoreBundle\GenericDoc\FetchQuery;
|
|||||||
use Chill\DocStoreBundle\GenericDoc\FetchQueryInterface;
|
use Chill\DocStoreBundle\GenericDoc\FetchQueryInterface;
|
||||||
use Chill\DocStoreBundle\GenericDoc\GenericDocForPersonProviderInterface;
|
use Chill\DocStoreBundle\GenericDoc\GenericDocForPersonProviderInterface;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkVoter;
|
||||||
use DateTimeImmutable;
|
use DateTimeImmutable;
|
||||||
use Doctrine\DBAL\Types\Types;
|
use Doctrine\DBAL\Types\Types;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
@ -35,6 +36,38 @@ 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);
|
||||||
|
|
||||||
|
if (null !== $startDate) {
|
||||||
|
$query->addWhereClause(
|
||||||
|
sprintf('doc_store.%s >= ?', $storedObjectMetadata->getColumnName('createdAt')),
|
||||||
|
[$startDate],
|
||||||
|
[Types::DATE_IMMUTABLE]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $endDate) {
|
||||||
|
$query->addWhereClause(
|
||||||
|
sprintf('doc_store.%s < ?', $storedObjectMetadata->getColumnName('createdAt')),
|
||||||
|
[$endDate],
|
||||||
|
[Types::DATE_IMMUTABLE]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $content) {
|
||||||
|
$query->addWhereClause(
|
||||||
|
sprintf('doc_store.%s ilike ?', $storedObjectMetadata->getColumnName('title')),
|
||||||
|
['%' . $content . '%'],
|
||||||
|
[Types::STRING]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws MappingException
|
* @throws MappingException
|
||||||
*/
|
*/
|
||||||
@ -72,33 +105,36 @@ final class PersonCalendarGenericDocProvider implements GenericDocForPersonProvi
|
|||||||
[Types::INTEGER]
|
[Types::INTEGER]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (null !== $startDate) {
|
// get the documents associated with accompanying periods in which person participates
|
||||||
$query->addWhereClause(
|
$or = [];
|
||||||
sprintf('doc_store.%s >= ?', $storedObjectMetadata->getColumnName('createdAt')),
|
$orParams = [];
|
||||||
[$startDate],
|
$orTypes = [];
|
||||||
[Types::DATE_IMMUTABLE]
|
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 (null !== $endDate) {
|
if ([] === $or) {
|
||||||
$query->addWhereClause(
|
$query->addWhereClause('TRUE = FALSE');
|
||||||
sprintf('doc_store.%s < ?', $storedObjectMetadata->getColumnName('createdAt')),
|
|
||||||
[$endDate],
|
return $query;
|
||||||
[Types::DATE_IMMUTABLE]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $content) {
|
// $query->addWhereClause(sprintf('(%s)', implode(' OR ', $or)), $orParams, $orTypes);
|
||||||
$query->addWhereClause(
|
|
||||||
sprintf('doc_store.%s ilike ?', $storedObjectMetadata->getColumnName('title')),
|
|
||||||
['%' . $content . '%'],
|
|
||||||
[Types::STRING]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
dump($query);
|
return $this->addWhereClausesToQuery($query, $startDate, $endDate, $content);
|
||||||
|
|
||||||
return $query;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,6 +13,7 @@ namespace Chill\CalendarBundle\Service\GenericDoc\Renderers;
|
|||||||
|
|
||||||
use Chill\CalendarBundle\Repository\CalendarDocRepository;
|
use Chill\CalendarBundle\Repository\CalendarDocRepository;
|
||||||
use Chill\CalendarBundle\Service\GenericDoc\Providers\AccompanyingPeriodCalendarGenericDocProvider;
|
use Chill\CalendarBundle\Service\GenericDoc\Providers\AccompanyingPeriodCalendarGenericDocProvider;
|
||||||
|
use Chill\CalendarBundle\Service\GenericDoc\Providers\PersonCalendarGenericDocProvider;
|
||||||
use Chill\DocStoreBundle\GenericDoc\GenericDocDTO;
|
use Chill\DocStoreBundle\GenericDoc\GenericDocDTO;
|
||||||
use Chill\DocStoreBundle\GenericDoc\Twig\GenericDocRendererInterface;
|
use Chill\DocStoreBundle\GenericDoc\Twig\GenericDocRendererInterface;
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ final class AccompanyingPeriodCalendarGenericDocRenderer implements GenericDocRe
|
|||||||
|
|
||||||
public function supports(GenericDocDTO $genericDocDTO, $options = []): bool
|
public function supports(GenericDocDTO $genericDocDTO, $options = []): bool
|
||||||
{
|
{
|
||||||
return $genericDocDTO->key === AccompanyingPeriodCalendarGenericDocProvider::KEY;
|
return $genericDocDTO->key === AccompanyingPeriodCalendarGenericDocProvider::KEY || $genericDocDTO->key === PersonCalendarGenericDocProvider::KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTemplate(GenericDocDTO $genericDocDTO, $options = []): string
|
public function getTemplate(GenericDocDTO $genericDocDTO, $options = []): string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user