From 90a5a735aafebb58ba16d8ea17e2383fe0d2f13f Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 30 May 2023 14:38:16 +0200 Subject: [PATCH 01/18] FIX [route] adjust to using new route name in redirect --- .../Controller/DocumentAccompanyingCourseController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php b/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php index 8762050aa..384eeb510 100644 --- a/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php +++ b/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php @@ -160,7 +160,7 @@ class DocumentAccompanyingCourseController extends AbstractController $this->addFlash('success', $this->translator->trans('The document is successfully registered')); - return $this->redirectToRoute('accompanying_course_document_index', ['course' => $course->getId()]); + return $this->redirectToRoute('chill_docstore_generic-doc_by-period_index', ['id' => $course->getId()]); } if ($form->isSubmitted() && !$form->isValid()) { From 101cca8662e0aef2444cfd189975cec118fd98da Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 30 May 2023 16:56:20 +0200 Subject: [PATCH 02/18] FEATURE [genericDoc] generic doc interface implemented for rendez-vous --- .../GenericDoc/calendar_document.html.twig | 72 +++++++++++++ ...anyingPeriodCalendarGenericDocProvider.php | 101 ++++++++++++++++++ ...anyingPeriodCalendarGenericDocRenderer.php | 44 ++++++++ .../translations/messages.fr.yml | 2 + .../translations/messages.fr.yml | 1 + 5 files changed, 220 insertions(+) create mode 100644 src/Bundle/ChillCalendarBundle/Resources/views/GenericDoc/calendar_document.html.twig create mode 100644 src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php create mode 100644 src/Bundle/ChillCalendarBundle/Service/GenericDoc/Renderers/AccompanyingPeriodCalendarGenericDocRenderer.php diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/GenericDoc/calendar_document.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/GenericDoc/calendar_document.html.twig new file mode 100644 index 000000000..712b362f5 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Resources/views/GenericDoc/calendar_document.html.twig @@ -0,0 +1,72 @@ +{% import "@ChillDocStore/Macro/macro.html.twig" as m %} +{% import "@ChillDocStore/Macro/macro_mimeicon.html.twig" as mm %} +{% import '@ChillPerson/Macro/updatedBy.html.twig' as mmm %} + +{% set c = document.calendar %} + +
+
+
+ {% if document.storedObject.isPending %} +
{{ 'docgen.Doc generation is pending'|trans }}
+ {% elseif document.storedObject.isFailure %} +
{{ 'docgen.Doc generation failed'|trans }}
+ {% endif %} +
+ {{ document.storedObject.title }} +
+
+ {{ 'chill_calendar.Document'|trans }} +
+ {% if document.storedObject.hasTemplate %} +
+

{{ document.storedObject.template.name|localize_translatable_string }}

+
+ {% endif %} +
+ +
+
+
+ {{ document.storedObject.createdAt|format_date('short') }} +
+
+
+
+ +
+
+

+ {% if c.endDate.diff(c.startDate).days >= 1 %} + {{ c.startDate|format_datetime('short', 'short') }} + - {{ c.endDate|format_datetime('short', 'short') }} + {% else %} + {{ c.startDate|format_datetime('short', 'short') }} + - {{ c.endDate|format_datetime('none', 'short') }} + {% endif %} +

+
+
+ +
+
+ {{ mmm.createdBy(document) }} +
+
    +
  • + {{ chill_entity_workflow_list('Chill\\PersonBundle\\Entity\\AccompanyingPeriod\\AccompanyingPeriodWorkEvaluationDocument', document.id) }} +
  • + {% if is_granted('CHILL_CALENDAR_DOC_SEE', document) %} +
  • + {{ document.storedObject|chill_document_button_group(document.storedObject.title, is_granted('CHILL_CALENDAR_CALENDAR_EDIT', c)) }} +
  • + {% endif %} + {% if is_granted('CHILL_CALENDAR_CALENDAR_EDIT', c) %} +
  • + +
  • + {% endif %} +
+ +
+
diff --git a/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php new file mode 100644 index 000000000..ff2cdbcf5 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php @@ -0,0 +1,101 @@ +security = $security; + $this->em = $entityManager; + } + + public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?\DateTimeImmutable $startDate = null, ?\DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface + { + $classMetadata = $this->em->getClassMetadata(CalendarDoc::class); + $storedObjectMetadata = $this->em->getClassMetadata(StoredObject::class); + $calendarMetadata = $this->em->getClassMetadata(Calendar::class); + + $query = new FetchQuery( + self::KEY, + sprintf("jsonb_build_object('id', cd.%s)", $classMetadata->getColumnName('id')), + 'cd.'.$storedObjectMetadata->getColumnName('createdAt'), + $classMetadata->getSchemaName().'.'.$classMetadata->getTableName().' AS cd' + ); + $query->addJoinClause( + 'JOIN chill_doc.stored_object doc_store ON doc_store.id = cd.storedobject_id' + ); + + $query->addJoinClause( + 'JOIN chill_calendar.calendar calendar ON calendar.id = cd.calendar_id' + ); + + $query->addWhereClause( + 'calendar.accompanyingperiod_id = ?', + [$accompanyingPeriod->getId()], + [Types::INTEGER] + ); + + 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( + 'doc_store.title ilike ?', + ['%' . $content . '%'], + [Types::STRING] + ); + } + + return $query; + } + + public function isAllowedForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod): bool + { + return $this->security->isGranted(CalendarVoter::SEE, $accompanyingPeriod); + } + + +} diff --git a/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Renderers/AccompanyingPeriodCalendarGenericDocRenderer.php b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Renderers/AccompanyingPeriodCalendarGenericDocRenderer.php new file mode 100644 index 000000000..0f680797c --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Renderers/AccompanyingPeriodCalendarGenericDocRenderer.php @@ -0,0 +1,44 @@ +repository = $calendarDocRepository; + } + + public function supports(GenericDocDTO $genericDocDTO, $options = []): bool + { + return $genericDocDTO->key === AccompanyingPeriodCalendarGenericDocProvider::KEY; + } + + public function getTemplate(GenericDocDTO $genericDocDTO, $options = []): string + { + return '@ChillCalendar/GenericDoc/calendar_document.html.twig'; + } + + public function getTemplateData(GenericDocDTO $genericDocDTO, $options = []): array + { + return [ + 'document' => $this->repository->find($genericDocDTO->identifiers['id']) + ]; + } +} diff --git a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml index eb02be280..5e1fc971a 100644 --- a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml @@ -43,6 +43,7 @@ crud: title_edit: Modifier le motif d'annulation chill_calendar: + Document: Document d'un rendez-vous form: The main user is mandatory. He will organize the appointment.: L'utilisateur principal est obligatoire. Il est l'organisateur de l'événement. Create for referrer: Créer pour le référent @@ -65,6 +66,7 @@ chill_calendar: Document outdated: La date et l'heure du rendez-vous ont été modifiés après la création du document + remote_ms_graph: freebusy_statuses: busy: Occupé diff --git a/src/Bundle/ChillDocStoreBundle/translations/messages.fr.yml b/src/Bundle/ChillDocStoreBundle/translations/messages.fr.yml index 1dde57eee..4fa41f180 100644 --- a/src/Bundle/ChillDocStoreBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillDocStoreBundle/translations/messages.fr.yml @@ -26,6 +26,7 @@ generic_doc: filter: keys: accompanying_course_document: Document du parcours + accompanying_period_calendar_document: Document des rendez-vous date-range: Date du document # delete From d09e5d33db2b3d2001208d1097b0915412b9137f Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 30 May 2023 16:59:16 +0200 Subject: [PATCH 03/18] WIP [genericDoc][activity] implementing generic doc for activities --- ...anyingPeriodActivityGenericDocProvider.php | 110 ++++++++++++++++++ ...anyingPeriodActivityGenericDocRenderer.php | 45 +++++++ 2 files changed, 155 insertions(+) create mode 100644 src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php create mode 100644 src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php diff --git a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php new file mode 100644 index 000000000..fc7484edf --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php @@ -0,0 +1,110 @@ +em = $entityManager; + $this->security = $security; + } + + /** + * @param AccompanyingPeriod $accompanyingPeriod + * @param DateTimeImmutable|null $startDate + * @param DateTimeImmutable|null $endDate + * @param string|null $content + * @param string|null $origin + * @return FetchQueryInterface + * @throws MappingException + */ + public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?DateTimeImmutable $startDate = null, ?DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface + { + $storedObjectMetadata = $this->em->getClassMetadata(StoredObject::class); +// $activityMetadata = $this->em->getClassMetadata(Activity::class); + + $query = new FetchQuery( + self::KEY, + "jsonb_build_object('id', doc_obj.id)", + 'doc_obj.'.$storedObjectMetadata->getColumnName('createdAt'), + $storedObjectMetadata->getSchemaName().'.'.$storedObjectMetadata->getTableName().' AS doc_obj' + ); + + $query->addJoinClause( + 'JOIN public.activity_storedobject activity_doc ON activity_doc.storedobject_id = doc_obj.id' + ); + + $query->addJoinClause( + 'JOIN public.activity activity ON activity.id = activity_doc.activity_id' + ); + + $query->addWhereClause( + 'activity.accompanyingperiod_id = ?', + [$accompanyingPeriod->getId()], + [Types::INTEGER] + ); + + if (null !== $startDate) { + $query->addWhereClause( + sprintf('doc_obj.%s >= ?', $storedObjectMetadata->getColumnName('createdAt')), + [$startDate], + [Types::DATE_IMMUTABLE] + ); + } + + if (null !== $endDate) { + $query->addWhereClause( + sprintf('doc_obj.%s < ?', $storedObjectMetadata->getColumnName('createdAt')), + [$endDate], + [Types::DATE_IMMUTABLE] + ); + } + + if (null !== $content) { + $query->addWhereClause( + 'doc_obj.title ilike ?', + ['%' . $content . '%'], + [Types::STRING] + ); + } + + return $query; + } + + /** + * @param AccompanyingPeriod $accompanyingPeriod + * @return bool + */ + public function isAllowedForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod): bool + { + return $this->security->isGranted(ActivityVoter::SEE, $accompanyingPeriod); + } +} diff --git a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php new file mode 100644 index 000000000..eddcc6828 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php @@ -0,0 +1,45 @@ +repository = $storedObjectRepository; + } + + public function supports(GenericDocDTO $genericDocDTO, $options = []): bool + { + return $genericDocDTO->key === AccompanyingPeriodActivityGenericDocProvider::KEY; + } + + public function getTemplate(GenericDocDTO $genericDocDTO, $options = []): string + { + return '@ChillCalendar/GenericDoc/activity_document.html.twig'; + } + + public function getTemplateData(GenericDocDTO $genericDocDTO, $options = []): array + { + return [ + 'document' => $this->repository->find($genericDocDTO->identifiers['id']) + ]; + } +} + From bd074ebade229eaf747dd9be8f914e0f09f883a9 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 30 May 2023 17:50:32 +0200 Subject: [PATCH 04/18] FEATURE [genericDoc][calendar] use metadatas --- ...anyingPeriodCalendarGenericDocProvider.php | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php index ff2cdbcf5..e653cfc25 100644 --- a/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php +++ b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php @@ -21,6 +21,7 @@ use Chill\DocStoreBundle\GenericDoc\GenericDocForAccompanyingPeriodProviderInter use Chill\PersonBundle\Entity\AccompanyingPeriod; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Mapping\MappingException; use Symfony\Component\Security\Core\Security; final class AccompanyingPeriodCalendarGenericDocProvider implements GenericDocForAccompanyingPeriodProviderInterface @@ -39,6 +40,9 @@ final class AccompanyingPeriodCalendarGenericDocProvider implements GenericDocFo $this->em = $entityManager; } + /** + * @throws MappingException + */ public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?\DateTimeImmutable $startDate = null, ?\DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface { $classMetadata = $this->em->getClassMetadata(CalendarDoc::class); @@ -52,15 +56,23 @@ final class AccompanyingPeriodCalendarGenericDocProvider implements GenericDocFo $classMetadata->getSchemaName().'.'.$classMetadata->getTableName().' AS cd' ); $query->addJoinClause( - 'JOIN chill_doc.stored_object doc_store ON doc_store.id = cd.storedobject_id' - ); + sprintf('JOIN %s doc_store ON doc_store.%s = cd.%s', + $storedObjectMetadata->getSchemaName().'.'.$storedObjectMetadata->getTableName(), + $storedObjectMetadata->getColumnName('id'), + $classMetadata->getSingleAssociationJoinColumnName('storedObject') + )); $query->addJoinClause( - 'JOIN chill_calendar.calendar calendar ON calendar.id = cd.calendar_id' + sprintf('JOIN %s calendar ON calendar.%s = cd.%s', + $calendarMetadata->getSchemaName().'.'.$calendarMetadata->getTableName(), + $calendarMetadata->getColumnName('id'), + $classMetadata->getSingleAssociationJoinColumnName('calendar') + ) ); $query->addWhereClause( - 'calendar.accompanyingperiod_id = ?', + sprintf('calendar.%s = ?', + $calendarMetadata->getAssociationMapping('accompanyingPeriod')['joinColumns'][0]['name']), [$accompanyingPeriod->getId()], [Types::INTEGER] ); @@ -83,7 +95,7 @@ final class AccompanyingPeriodCalendarGenericDocProvider implements GenericDocFo if (null !== $content) { $query->addWhereClause( - 'doc_store.title ilike ?', + sprintf('doc_store.%s ilike ?', $storedObjectMetadata->getColumnName('title')), ['%' . $content . '%'], [Types::STRING] ); From c245ffe559196e37eb38dd5aeb41f83fa13212a7 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 30 May 2023 18:14:32 +0200 Subject: [PATCH 05/18] WIP [genericDoc][activity] add repository method to get activity linked to storedObject --- .../Repository/ActivityRepository.php | 12 ++++ .../GenericDoc/activity_document.html.twig | 72 +++++++++++++++++++ ...anyingPeriodActivityGenericDocProvider.php | 3 +- ...anyingPeriodActivityGenericDocRenderer.php | 13 ++-- 4 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 src/Bundle/ChillActivityBundle/Resources/views/GenericDoc/activity_document.html.twig diff --git a/src/Bundle/ChillActivityBundle/Repository/ActivityRepository.php b/src/Bundle/ChillActivityBundle/Repository/ActivityRepository.php index 5a6e16cd5..02658b03d 100644 --- a/src/Bundle/ChillActivityBundle/Repository/ActivityRepository.php +++ b/src/Bundle/ChillActivityBundle/Repository/ActivityRepository.php @@ -15,6 +15,7 @@ use Chill\ActivityBundle\Entity\Activity; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Person; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\ORM\Query\Expr; use Doctrine\Persistence\ManagerRegistry; /** @@ -97,4 +98,15 @@ class ActivityRepository extends ServiceEntityRepository return $qb->getQuery()->getResult(); } + + public function findOneByDocument(int $documentId): Activity + { + $qb = $this->createQueryBuilder('a'); + $qb->select('a'); + + $qb->innerJoin('a.documents', 'd', Expr\Join::WITH, 'd.storedobject_id = :documentId'); + $qb->setParameter('documentId', $documentId); + + return $qb->getQuery()->getResult(); + } } diff --git a/src/Bundle/ChillActivityBundle/Resources/views/GenericDoc/activity_document.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/GenericDoc/activity_document.html.twig new file mode 100644 index 000000000..aeaea0872 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Resources/views/GenericDoc/activity_document.html.twig @@ -0,0 +1,72 @@ +{% import "@ChillDocStore/Macro/macro.html.twig" as m %} +{% import "@ChillDocStore/Macro/macro_mimeicon.html.twig" as mm %} +{% import '@ChillPerson/Macro/updatedBy.html.twig' as mmm %} + +{% set a = document.calendar %} + +
+
+
+ {% if document.storedObject.isPending %} +
{{ 'docgen.Doc generation is pending'|trans }}
+ {% elseif document.storedObject.isFailure %} +
{{ 'docgen.Doc generation failed'|trans }}
+ {% endif %} +
+ {{ document.storedObject.title }} +
+
+ {{ 'chill_calendar.Document'|trans }} +
+ {% if document.storedObject.hasTemplate %} +
+

{{ document.storedObject.template.name|localize_translatable_string }}

+
+ {% endif %} +
+ +
+
+
+ {{ document.storedObject.createdAt|format_date('short') }} +
+
+
+
+ +
+
+

+ {% if c.endDate.diff(c.startDate).days >= 1 %} + {{ c.startDate|format_datetime('short', 'short') }} + - {{ c.endDate|format_datetime('short', 'short') }} + {% else %} + {{ c.startDate|format_datetime('short', 'short') }} + - {{ c.endDate|format_datetime('none', 'short') }} + {% endif %} +

+
+
+ +
+
+ {{ mmm.createdBy(document) }} +
+
    +
  • + {{ chill_entity_workflow_list('Chill\\PersonBundle\\Entity\\AccompanyingPeriod\\AccompanyingPeriodWorkEvaluationDocument', document.id) }} +
  • + {% if is_granted('CHILL_CALENDAR_DOC_SEE', document) %} +
  • + {{ document.storedObject|chill_document_button_group(document.storedObject.title, is_granted('CHILL_CALENDAR_CALENDAR_EDIT', c)) }} +
  • + {% endif %} + {% if is_granted('CHILL_CALENDAR_CALENDAR_EDIT', c) %} +
  • + +
  • + {% endif %} +
+ +
+
diff --git a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php index fc7484edf..bf7a022f1 100644 --- a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php +++ b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php @@ -27,7 +27,7 @@ final class AccompanyingPeriodActivityGenericDocProvider implements GenericDocFo { public const KEY = 'accompanying_period_activity_document'; - private EntityManagerInterface $em; + private EntityManagerInterface $em; private Security $security; @@ -49,7 +49,6 @@ final class AccompanyingPeriodActivityGenericDocProvider implements GenericDocFo public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?DateTimeImmutable $startDate = null, ?DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface { $storedObjectMetadata = $this->em->getClassMetadata(StoredObject::class); -// $activityMetadata = $this->em->getClassMetadata(Activity::class); $query = new FetchQuery( self::KEY, diff --git a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php index eddcc6828..f243fb941 100644 --- a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php +++ b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\ActivityBundle\Service\GenericDoc\Renderers; +use Chill\ActivityBundle\Repository\ActivityRepository; use Chill\ActivityBundle\Service\GenericDoc\Providers\AccompanyingPeriodActivityGenericDocProvider; use Chill\DocStoreBundle\GenericDoc\GenericDocDTO; use Chill\DocStoreBundle\GenericDoc\Twig\GenericDocRendererInterface; @@ -18,11 +19,14 @@ use Chill\DocStoreBundle\Repository\StoredObjectRepository; final class AccompanyingPeriodActivityGenericDocRenderer implements GenericDocRendererInterface { - private StoredObjectRepository $repository; + private StoredObjectRepository $objectRepository; - public function __construct(StoredObjectRepository $storedObjectRepository) + private ActivityRepository $activityRepository; + + public function __construct(StoredObjectRepository $storedObjectRepository, ActivityRepository $activityRepository) { - $this->repository = $storedObjectRepository; + $this->objectRepository = $storedObjectRepository; + $this->activityRepository = $activityRepository; } public function supports(GenericDocDTO $genericDocDTO, $options = []): bool @@ -38,7 +42,8 @@ final class AccompanyingPeriodActivityGenericDocRenderer implements GenericDocRe public function getTemplateData(GenericDocDTO $genericDocDTO, $options = []): array { return [ - 'document' => $this->repository->find($genericDocDTO->identifiers['id']) + 'activity' => $this->activityRepository->findOneByDocument($genericDocDTO->identifiers['id']), + 'document' => $this->objectRepository->find($genericDocDTO->identifiers['id']) ]; } } From 20489813f068c6147976ee1e6ed50b1b5dc2c66c Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 30 May 2023 14:38:16 +0200 Subject: [PATCH 06/18] FIX [route] adjust to using new route name in redirect --- .../Controller/DocumentAccompanyingCourseController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php b/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php index 8762050aa..384eeb510 100644 --- a/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php +++ b/src/Bundle/ChillDocStoreBundle/Controller/DocumentAccompanyingCourseController.php @@ -160,7 +160,7 @@ class DocumentAccompanyingCourseController extends AbstractController $this->addFlash('success', $this->translator->trans('The document is successfully registered')); - return $this->redirectToRoute('accompanying_course_document_index', ['course' => $course->getId()]); + return $this->redirectToRoute('chill_docstore_generic-doc_by-period_index', ['id' => $course->getId()]); } if ($form->isSubmitted() && !$form->isValid()) { From 47a3e30ec532e6cf27ba00e049a2e90c6ea7bd9b Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 30 May 2023 16:56:20 +0200 Subject: [PATCH 07/18] FEATURE [genericDoc] generic doc interface implemented for rendez-vous --- .../GenericDoc/calendar_document.html.twig | 72 +++++++++++++ ...anyingPeriodCalendarGenericDocProvider.php | 101 ++++++++++++++++++ ...anyingPeriodCalendarGenericDocRenderer.php | 44 ++++++++ .../translations/messages.fr.yml | 2 + .../translations/messages.fr.yml | 1 + 5 files changed, 220 insertions(+) create mode 100644 src/Bundle/ChillCalendarBundle/Resources/views/GenericDoc/calendar_document.html.twig create mode 100644 src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php create mode 100644 src/Bundle/ChillCalendarBundle/Service/GenericDoc/Renderers/AccompanyingPeriodCalendarGenericDocRenderer.php diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/GenericDoc/calendar_document.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/GenericDoc/calendar_document.html.twig new file mode 100644 index 000000000..712b362f5 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Resources/views/GenericDoc/calendar_document.html.twig @@ -0,0 +1,72 @@ +{% import "@ChillDocStore/Macro/macro.html.twig" as m %} +{% import "@ChillDocStore/Macro/macro_mimeicon.html.twig" as mm %} +{% import '@ChillPerson/Macro/updatedBy.html.twig' as mmm %} + +{% set c = document.calendar %} + +
+
+
+ {% if document.storedObject.isPending %} +
{{ 'docgen.Doc generation is pending'|trans }}
+ {% elseif document.storedObject.isFailure %} +
{{ 'docgen.Doc generation failed'|trans }}
+ {% endif %} +
+ {{ document.storedObject.title }} +
+
+ {{ 'chill_calendar.Document'|trans }} +
+ {% if document.storedObject.hasTemplate %} +
+

{{ document.storedObject.template.name|localize_translatable_string }}

+
+ {% endif %} +
+ +
+
+
+ {{ document.storedObject.createdAt|format_date('short') }} +
+
+
+
+ +
+
+

+ {% if c.endDate.diff(c.startDate).days >= 1 %} + {{ c.startDate|format_datetime('short', 'short') }} + - {{ c.endDate|format_datetime('short', 'short') }} + {% else %} + {{ c.startDate|format_datetime('short', 'short') }} + - {{ c.endDate|format_datetime('none', 'short') }} + {% endif %} +

+
+
+ +
+
+ {{ mmm.createdBy(document) }} +
+
    +
  • + {{ chill_entity_workflow_list('Chill\\PersonBundle\\Entity\\AccompanyingPeriod\\AccompanyingPeriodWorkEvaluationDocument', document.id) }} +
  • + {% if is_granted('CHILL_CALENDAR_DOC_SEE', document) %} +
  • + {{ document.storedObject|chill_document_button_group(document.storedObject.title, is_granted('CHILL_CALENDAR_CALENDAR_EDIT', c)) }} +
  • + {% endif %} + {% if is_granted('CHILL_CALENDAR_CALENDAR_EDIT', c) %} +
  • + +
  • + {% endif %} +
+ +
+
diff --git a/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php new file mode 100644 index 000000000..ff2cdbcf5 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php @@ -0,0 +1,101 @@ +security = $security; + $this->em = $entityManager; + } + + public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?\DateTimeImmutable $startDate = null, ?\DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface + { + $classMetadata = $this->em->getClassMetadata(CalendarDoc::class); + $storedObjectMetadata = $this->em->getClassMetadata(StoredObject::class); + $calendarMetadata = $this->em->getClassMetadata(Calendar::class); + + $query = new FetchQuery( + self::KEY, + sprintf("jsonb_build_object('id', cd.%s)", $classMetadata->getColumnName('id')), + 'cd.'.$storedObjectMetadata->getColumnName('createdAt'), + $classMetadata->getSchemaName().'.'.$classMetadata->getTableName().' AS cd' + ); + $query->addJoinClause( + 'JOIN chill_doc.stored_object doc_store ON doc_store.id = cd.storedobject_id' + ); + + $query->addJoinClause( + 'JOIN chill_calendar.calendar calendar ON calendar.id = cd.calendar_id' + ); + + $query->addWhereClause( + 'calendar.accompanyingperiod_id = ?', + [$accompanyingPeriod->getId()], + [Types::INTEGER] + ); + + 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( + 'doc_store.title ilike ?', + ['%' . $content . '%'], + [Types::STRING] + ); + } + + return $query; + } + + public function isAllowedForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod): bool + { + return $this->security->isGranted(CalendarVoter::SEE, $accompanyingPeriod); + } + + +} diff --git a/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Renderers/AccompanyingPeriodCalendarGenericDocRenderer.php b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Renderers/AccompanyingPeriodCalendarGenericDocRenderer.php new file mode 100644 index 000000000..0f680797c --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Renderers/AccompanyingPeriodCalendarGenericDocRenderer.php @@ -0,0 +1,44 @@ +repository = $calendarDocRepository; + } + + public function supports(GenericDocDTO $genericDocDTO, $options = []): bool + { + return $genericDocDTO->key === AccompanyingPeriodCalendarGenericDocProvider::KEY; + } + + public function getTemplate(GenericDocDTO $genericDocDTO, $options = []): string + { + return '@ChillCalendar/GenericDoc/calendar_document.html.twig'; + } + + public function getTemplateData(GenericDocDTO $genericDocDTO, $options = []): array + { + return [ + 'document' => $this->repository->find($genericDocDTO->identifiers['id']) + ]; + } +} diff --git a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml index eb02be280..5e1fc971a 100644 --- a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml @@ -43,6 +43,7 @@ crud: title_edit: Modifier le motif d'annulation chill_calendar: + Document: Document d'un rendez-vous form: The main user is mandatory. He will organize the appointment.: L'utilisateur principal est obligatoire. Il est l'organisateur de l'événement. Create for referrer: Créer pour le référent @@ -65,6 +66,7 @@ chill_calendar: Document outdated: La date et l'heure du rendez-vous ont été modifiés après la création du document + remote_ms_graph: freebusy_statuses: busy: Occupé diff --git a/src/Bundle/ChillDocStoreBundle/translations/messages.fr.yml b/src/Bundle/ChillDocStoreBundle/translations/messages.fr.yml index 1dde57eee..4fa41f180 100644 --- a/src/Bundle/ChillDocStoreBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillDocStoreBundle/translations/messages.fr.yml @@ -26,6 +26,7 @@ generic_doc: filter: keys: accompanying_course_document: Document du parcours + accompanying_period_calendar_document: Document des rendez-vous date-range: Date du document # delete From 9eb9a9a214d9801fa5fa87ae10449b1068a16576 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 30 May 2023 16:59:16 +0200 Subject: [PATCH 08/18] WIP [genericDoc][activity] implementing generic doc for activities --- ...anyingPeriodActivityGenericDocProvider.php | 110 ++++++++++++++++++ ...anyingPeriodActivityGenericDocRenderer.php | 45 +++++++ 2 files changed, 155 insertions(+) create mode 100644 src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php create mode 100644 src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php diff --git a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php new file mode 100644 index 000000000..fc7484edf --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php @@ -0,0 +1,110 @@ +em = $entityManager; + $this->security = $security; + } + + /** + * @param AccompanyingPeriod $accompanyingPeriod + * @param DateTimeImmutable|null $startDate + * @param DateTimeImmutable|null $endDate + * @param string|null $content + * @param string|null $origin + * @return FetchQueryInterface + * @throws MappingException + */ + public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?DateTimeImmutable $startDate = null, ?DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface + { + $storedObjectMetadata = $this->em->getClassMetadata(StoredObject::class); +// $activityMetadata = $this->em->getClassMetadata(Activity::class); + + $query = new FetchQuery( + self::KEY, + "jsonb_build_object('id', doc_obj.id)", + 'doc_obj.'.$storedObjectMetadata->getColumnName('createdAt'), + $storedObjectMetadata->getSchemaName().'.'.$storedObjectMetadata->getTableName().' AS doc_obj' + ); + + $query->addJoinClause( + 'JOIN public.activity_storedobject activity_doc ON activity_doc.storedobject_id = doc_obj.id' + ); + + $query->addJoinClause( + 'JOIN public.activity activity ON activity.id = activity_doc.activity_id' + ); + + $query->addWhereClause( + 'activity.accompanyingperiod_id = ?', + [$accompanyingPeriod->getId()], + [Types::INTEGER] + ); + + if (null !== $startDate) { + $query->addWhereClause( + sprintf('doc_obj.%s >= ?', $storedObjectMetadata->getColumnName('createdAt')), + [$startDate], + [Types::DATE_IMMUTABLE] + ); + } + + if (null !== $endDate) { + $query->addWhereClause( + sprintf('doc_obj.%s < ?', $storedObjectMetadata->getColumnName('createdAt')), + [$endDate], + [Types::DATE_IMMUTABLE] + ); + } + + if (null !== $content) { + $query->addWhereClause( + 'doc_obj.title ilike ?', + ['%' . $content . '%'], + [Types::STRING] + ); + } + + return $query; + } + + /** + * @param AccompanyingPeriod $accompanyingPeriod + * @return bool + */ + public function isAllowedForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod): bool + { + return $this->security->isGranted(ActivityVoter::SEE, $accompanyingPeriod); + } +} diff --git a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php new file mode 100644 index 000000000..eddcc6828 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php @@ -0,0 +1,45 @@ +repository = $storedObjectRepository; + } + + public function supports(GenericDocDTO $genericDocDTO, $options = []): bool + { + return $genericDocDTO->key === AccompanyingPeriodActivityGenericDocProvider::KEY; + } + + public function getTemplate(GenericDocDTO $genericDocDTO, $options = []): string + { + return '@ChillCalendar/GenericDoc/activity_document.html.twig'; + } + + public function getTemplateData(GenericDocDTO $genericDocDTO, $options = []): array + { + return [ + 'document' => $this->repository->find($genericDocDTO->identifiers['id']) + ]; + } +} + From 4155af6686cd173c8689b5d9bff52b3996963644 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 30 May 2023 17:50:32 +0200 Subject: [PATCH 09/18] FEATURE [genericDoc][calendar] use metadatas --- ...anyingPeriodCalendarGenericDocProvider.php | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php index ff2cdbcf5..e653cfc25 100644 --- a/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php +++ b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php @@ -21,6 +21,7 @@ use Chill\DocStoreBundle\GenericDoc\GenericDocForAccompanyingPeriodProviderInter use Chill\PersonBundle\Entity\AccompanyingPeriod; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Mapping\MappingException; use Symfony\Component\Security\Core\Security; final class AccompanyingPeriodCalendarGenericDocProvider implements GenericDocForAccompanyingPeriodProviderInterface @@ -39,6 +40,9 @@ final class AccompanyingPeriodCalendarGenericDocProvider implements GenericDocFo $this->em = $entityManager; } + /** + * @throws MappingException + */ public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?\DateTimeImmutable $startDate = null, ?\DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface { $classMetadata = $this->em->getClassMetadata(CalendarDoc::class); @@ -52,15 +56,23 @@ final class AccompanyingPeriodCalendarGenericDocProvider implements GenericDocFo $classMetadata->getSchemaName().'.'.$classMetadata->getTableName().' AS cd' ); $query->addJoinClause( - 'JOIN chill_doc.stored_object doc_store ON doc_store.id = cd.storedobject_id' - ); + sprintf('JOIN %s doc_store ON doc_store.%s = cd.%s', + $storedObjectMetadata->getSchemaName().'.'.$storedObjectMetadata->getTableName(), + $storedObjectMetadata->getColumnName('id'), + $classMetadata->getSingleAssociationJoinColumnName('storedObject') + )); $query->addJoinClause( - 'JOIN chill_calendar.calendar calendar ON calendar.id = cd.calendar_id' + sprintf('JOIN %s calendar ON calendar.%s = cd.%s', + $calendarMetadata->getSchemaName().'.'.$calendarMetadata->getTableName(), + $calendarMetadata->getColumnName('id'), + $classMetadata->getSingleAssociationJoinColumnName('calendar') + ) ); $query->addWhereClause( - 'calendar.accompanyingperiod_id = ?', + sprintf('calendar.%s = ?', + $calendarMetadata->getAssociationMapping('accompanyingPeriod')['joinColumns'][0]['name']), [$accompanyingPeriod->getId()], [Types::INTEGER] ); @@ -83,7 +95,7 @@ final class AccompanyingPeriodCalendarGenericDocProvider implements GenericDocFo if (null !== $content) { $query->addWhereClause( - 'doc_store.title ilike ?', + sprintf('doc_store.%s ilike ?', $storedObjectMetadata->getColumnName('title')), ['%' . $content . '%'], [Types::STRING] ); From c07e26785e5b73e810b50bb41be02d2ad424e01c Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 30 May 2023 18:14:32 +0200 Subject: [PATCH 10/18] WIP [genericDoc][activity] add repository method to get activity linked to storedObject --- .../Repository/ActivityRepository.php | 12 ++++ .../GenericDoc/activity_document.html.twig | 72 +++++++++++++++++++ ...anyingPeriodActivityGenericDocProvider.php | 3 +- ...anyingPeriodActivityGenericDocRenderer.php | 13 ++-- 4 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 src/Bundle/ChillActivityBundle/Resources/views/GenericDoc/activity_document.html.twig diff --git a/src/Bundle/ChillActivityBundle/Repository/ActivityRepository.php b/src/Bundle/ChillActivityBundle/Repository/ActivityRepository.php index 5a6e16cd5..02658b03d 100644 --- a/src/Bundle/ChillActivityBundle/Repository/ActivityRepository.php +++ b/src/Bundle/ChillActivityBundle/Repository/ActivityRepository.php @@ -15,6 +15,7 @@ use Chill\ActivityBundle\Entity\Activity; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Person; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\ORM\Query\Expr; use Doctrine\Persistence\ManagerRegistry; /** @@ -97,4 +98,15 @@ class ActivityRepository extends ServiceEntityRepository return $qb->getQuery()->getResult(); } + + public function findOneByDocument(int $documentId): Activity + { + $qb = $this->createQueryBuilder('a'); + $qb->select('a'); + + $qb->innerJoin('a.documents', 'd', Expr\Join::WITH, 'd.storedobject_id = :documentId'); + $qb->setParameter('documentId', $documentId); + + return $qb->getQuery()->getResult(); + } } diff --git a/src/Bundle/ChillActivityBundle/Resources/views/GenericDoc/activity_document.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/GenericDoc/activity_document.html.twig new file mode 100644 index 000000000..aeaea0872 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Resources/views/GenericDoc/activity_document.html.twig @@ -0,0 +1,72 @@ +{% import "@ChillDocStore/Macro/macro.html.twig" as m %} +{% import "@ChillDocStore/Macro/macro_mimeicon.html.twig" as mm %} +{% import '@ChillPerson/Macro/updatedBy.html.twig' as mmm %} + +{% set a = document.calendar %} + +
+
+
+ {% if document.storedObject.isPending %} +
{{ 'docgen.Doc generation is pending'|trans }}
+ {% elseif document.storedObject.isFailure %} +
{{ 'docgen.Doc generation failed'|trans }}
+ {% endif %} +
+ {{ document.storedObject.title }} +
+
+ {{ 'chill_calendar.Document'|trans }} +
+ {% if document.storedObject.hasTemplate %} +
+

{{ document.storedObject.template.name|localize_translatable_string }}

+
+ {% endif %} +
+ +
+
+
+ {{ document.storedObject.createdAt|format_date('short') }} +
+
+
+
+ +
+
+

+ {% if c.endDate.diff(c.startDate).days >= 1 %} + {{ c.startDate|format_datetime('short', 'short') }} + - {{ c.endDate|format_datetime('short', 'short') }} + {% else %} + {{ c.startDate|format_datetime('short', 'short') }} + - {{ c.endDate|format_datetime('none', 'short') }} + {% endif %} +

+
+
+ +
+
+ {{ mmm.createdBy(document) }} +
+
    +
  • + {{ chill_entity_workflow_list('Chill\\PersonBundle\\Entity\\AccompanyingPeriod\\AccompanyingPeriodWorkEvaluationDocument', document.id) }} +
  • + {% if is_granted('CHILL_CALENDAR_DOC_SEE', document) %} +
  • + {{ document.storedObject|chill_document_button_group(document.storedObject.title, is_granted('CHILL_CALENDAR_CALENDAR_EDIT', c)) }} +
  • + {% endif %} + {% if is_granted('CHILL_CALENDAR_CALENDAR_EDIT', c) %} +
  • + +
  • + {% endif %} +
+ +
+
diff --git a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php index fc7484edf..bf7a022f1 100644 --- a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php +++ b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php @@ -27,7 +27,7 @@ final class AccompanyingPeriodActivityGenericDocProvider implements GenericDocFo { public const KEY = 'accompanying_period_activity_document'; - private EntityManagerInterface $em; + private EntityManagerInterface $em; private Security $security; @@ -49,7 +49,6 @@ final class AccompanyingPeriodActivityGenericDocProvider implements GenericDocFo public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?DateTimeImmutable $startDate = null, ?DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface { $storedObjectMetadata = $this->em->getClassMetadata(StoredObject::class); -// $activityMetadata = $this->em->getClassMetadata(Activity::class); $query = new FetchQuery( self::KEY, diff --git a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php index eddcc6828..f243fb941 100644 --- a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php +++ b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\ActivityBundle\Service\GenericDoc\Renderers; +use Chill\ActivityBundle\Repository\ActivityRepository; use Chill\ActivityBundle\Service\GenericDoc\Providers\AccompanyingPeriodActivityGenericDocProvider; use Chill\DocStoreBundle\GenericDoc\GenericDocDTO; use Chill\DocStoreBundle\GenericDoc\Twig\GenericDocRendererInterface; @@ -18,11 +19,14 @@ use Chill\DocStoreBundle\Repository\StoredObjectRepository; final class AccompanyingPeriodActivityGenericDocRenderer implements GenericDocRendererInterface { - private StoredObjectRepository $repository; + private StoredObjectRepository $objectRepository; - public function __construct(StoredObjectRepository $storedObjectRepository) + private ActivityRepository $activityRepository; + + public function __construct(StoredObjectRepository $storedObjectRepository, ActivityRepository $activityRepository) { - $this->repository = $storedObjectRepository; + $this->objectRepository = $storedObjectRepository; + $this->activityRepository = $activityRepository; } public function supports(GenericDocDTO $genericDocDTO, $options = []): bool @@ -38,7 +42,8 @@ final class AccompanyingPeriodActivityGenericDocRenderer implements GenericDocRe public function getTemplateData(GenericDocDTO $genericDocDTO, $options = []): array { return [ - 'document' => $this->repository->find($genericDocDTO->identifiers['id']) + 'activity' => $this->activityRepository->findOneByDocument($genericDocDTO->identifiers['id']), + 'document' => $this->objectRepository->find($genericDocDTO->identifiers['id']) ]; } } From ba55fa349baa108487af2b5eef9737196aa6c022 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 31 May 2023 16:53:38 +0200 Subject: [PATCH 11/18] FEATURE [genericDoc][activity] finalize implementation --- .../Repository/ActivityRepository.php | 11 ---- .../GenericDoc/activity_document.html.twig | 63 ++++++++++--------- ...anyingPeriodActivityGenericDocProvider.php | 23 ++----- ...anyingPeriodActivityGenericDocRenderer.php | 4 +- .../ChillActivityBundle/config/services.yaml | 3 + 5 files changed, 45 insertions(+), 59 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Repository/ActivityRepository.php b/src/Bundle/ChillActivityBundle/Repository/ActivityRepository.php index 02658b03d..a3bfb5942 100644 --- a/src/Bundle/ChillActivityBundle/Repository/ActivityRepository.php +++ b/src/Bundle/ChillActivityBundle/Repository/ActivityRepository.php @@ -98,15 +98,4 @@ class ActivityRepository extends ServiceEntityRepository return $qb->getQuery()->getResult(); } - - public function findOneByDocument(int $documentId): Activity - { - $qb = $this->createQueryBuilder('a'); - $qb->select('a'); - - $qb->innerJoin('a.documents', 'd', Expr\Join::WITH, 'd.storedobject_id = :documentId'); - $qb->setParameter('documentId', $documentId); - - return $qb->getQuery()->getResult(); - } } diff --git a/src/Bundle/ChillActivityBundle/Resources/views/GenericDoc/activity_document.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/GenericDoc/activity_document.html.twig index aeaea0872..11aeeeca1 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/GenericDoc/activity_document.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/GenericDoc/activity_document.html.twig @@ -2,25 +2,30 @@ {% import "@ChillDocStore/Macro/macro_mimeicon.html.twig" as mm %} {% import '@ChillPerson/Macro/updatedBy.html.twig' as mmm %} -{% set a = document.calendar %} +{% set person_id = null %} +{% if activity.person %} + {% set person_id = activity.person.id %} +{% endif %} -
+{% set accompanying_course_id = null %} +{% if activity.accompanyingPeriod %} + {% set accompanying_course_id = activity.accompanyingPeriod.id %} +{% endif %} + +
- {% if document.storedObject.isPending %} -
{{ 'docgen.Doc generation is pending'|trans }}
- {% elseif document.storedObject.isFailure %} + {% if document.isPending %} +
{{ 'docgen.Doc generation is pending'|trans }}
+ {% elseif document.isFailure %}
{{ 'docgen.Doc generation failed'|trans }}
{% endif %}
- {{ document.storedObject.title }} + {{ document.title }}
-
- {{ 'chill_calendar.Document'|trans }} -
- {% if document.storedObject.hasTemplate %} + {% if document.hasTemplate %}
-

{{ document.storedObject.template.name|localize_translatable_string }}

+

{{ document.template.name|localize_translatable_string }}

{% endif %}
@@ -28,7 +33,7 @@
- {{ document.storedObject.createdAt|format_date('short') }} + {{ document.createdAt|format_date('short') }}
@@ -36,15 +41,15 @@
-

- {% if c.endDate.diff(c.startDate).days >= 1 %} - {{ c.startDate|format_datetime('short', 'short') }} - - {{ c.endDate|format_datetime('short', 'short') }} - {% else %} - {{ c.startDate|format_datetime('short', 'short') }} - - {{ c.endDate|format_datetime('none', 'short') }} - {% endif %} -

+

+ + + {{ activity.type.name | localize_translatable_string }} + {% if activity.emergency %} + {{ 'Emergency'|trans|upper }} + {% endif %} + +

@@ -53,17 +58,19 @@ {{ mmm.createdBy(document) }}
    -
  • - {{ chill_entity_workflow_list('Chill\\PersonBundle\\Entity\\AccompanyingPeriod\\AccompanyingPeriodWorkEvaluationDocument', document.id) }} -
  • - {% if is_granted('CHILL_CALENDAR_DOC_SEE', document) %} + {% if is_granted('CHILL_ACTIVITY_SEE_DETAILS', activity) %}
  • - {{ document.storedObject|chill_document_button_group(document.storedObject.title, is_granted('CHILL_CALENDAR_CALENDAR_EDIT', c)) }} + {{ document|chill_document_button_group(document.title, is_granted('CHILL_ACTIVITY_UPDATE', activity), {small: false}) }}
  • {% endif %} - {% if is_granted('CHILL_CALENDAR_CALENDAR_EDIT', c) %} + {% if is_granted('CHILL_ACTIVITY_SEE', activity)%}
  • - + +
  • + {% endif %} + {% if is_granted('CHILL_ACTIVITY_UPDATE', activity) %} +
  • +
  • {% endif %}
diff --git a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php index bf7a022f1..8c787fd3a 100644 --- a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php +++ b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php @@ -27,32 +27,19 @@ final class AccompanyingPeriodActivityGenericDocProvider implements GenericDocFo { public const KEY = 'accompanying_period_activity_document'; - private EntityManagerInterface $em; - - private Security $security; - - public function __construct(Security $security, EntityManagerInterface $entityManager) - { - $this->em = $entityManager; - $this->security = $security; + public function __construct( + private EntityManagerInterface $em, + private Security $security + ){ } - /** - * @param AccompanyingPeriod $accompanyingPeriod - * @param DateTimeImmutable|null $startDate - * @param DateTimeImmutable|null $endDate - * @param string|null $content - * @param string|null $origin - * @return FetchQueryInterface - * @throws MappingException - */ public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?DateTimeImmutable $startDate = null, ?DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface { $storedObjectMetadata = $this->em->getClassMetadata(StoredObject::class); $query = new FetchQuery( self::KEY, - "jsonb_build_object('id', doc_obj.id)", + "jsonb_build_object('id', doc_obj.id, 'activity_id', activity.id)", 'doc_obj.'.$storedObjectMetadata->getColumnName('createdAt'), $storedObjectMetadata->getSchemaName().'.'.$storedObjectMetadata->getTableName().' AS doc_obj' ); diff --git a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php index f243fb941..f3b70dac2 100644 --- a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php +++ b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php @@ -36,13 +36,13 @@ final class AccompanyingPeriodActivityGenericDocRenderer implements GenericDocRe public function getTemplate(GenericDocDTO $genericDocDTO, $options = []): string { - return '@ChillCalendar/GenericDoc/activity_document.html.twig'; + return '@ChillActivity/GenericDoc/activity_document.html.twig'; } public function getTemplateData(GenericDocDTO $genericDocDTO, $options = []): array { return [ - 'activity' => $this->activityRepository->findOneByDocument($genericDocDTO->identifiers['id']), + 'activity' => $this->activityRepository->find($genericDocDTO->identifiers['activity_id']), 'document' => $this->objectRepository->find($genericDocDTO->identifiers['id']) ]; } diff --git a/src/Bundle/ChillActivityBundle/config/services.yaml b/src/Bundle/ChillActivityBundle/config/services.yaml index d55f86d4f..18be76ec9 100644 --- a/src/Bundle/ChillActivityBundle/config/services.yaml +++ b/src/Bundle/ChillActivityBundle/config/services.yaml @@ -38,3 +38,6 @@ services: Chill\ActivityBundle\Service\EntityInfo\: resource: '../Service/EntityInfo/' + + Chill\ActivityBundle\Service\GenericDoc\: + resource: '../Service/GenericDoc/' From ef04a0405645fc5a38396e8f88486928a40be697 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 31 May 2023 16:54:21 +0200 Subject: [PATCH 12/18] FEATURE [genericDoc][calendar] minor changes to template and provider --- .../views/GenericDoc/calendar_document.html.twig | 3 --- .../AccompanyingPeriodCalendarGenericDocProvider.php | 10 ++-------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/GenericDoc/calendar_document.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/GenericDoc/calendar_document.html.twig index 712b362f5..4cd369366 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/GenericDoc/calendar_document.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/GenericDoc/calendar_document.html.twig @@ -53,9 +53,6 @@ {{ mmm.createdBy(document) }}
    -
  • - {{ chill_entity_workflow_list('Chill\\PersonBundle\\Entity\\AccompanyingPeriod\\AccompanyingPeriodWorkEvaluationDocument', document.id) }} -
  • {% if is_granted('CHILL_CALENDAR_DOC_SEE', document) %}
  • {{ document.storedObject|chill_document_button_group(document.storedObject.title, is_granted('CHILL_CALENDAR_CALENDAR_EDIT', c)) }} diff --git a/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php index e653cfc25..7efc1589d 100644 --- a/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php +++ b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/AccompanyingPeriodCalendarGenericDocProvider.php @@ -28,16 +28,10 @@ final class AccompanyingPeriodCalendarGenericDocProvider implements GenericDocFo { public const KEY = 'accompanying_period_calendar_document'; - private EntityManagerInterface $em; - - private Security $security; - public function __construct( - Security $security, - EntityManagerInterface $entityManager + private Security $security, + private EntityManagerInterface $em ) { - $this->security = $security; - $this->em = $entityManager; } /** From 9a3fcf081ecb5d3d7449878c7562d4528df167b6 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 31 May 2023 17:10:38 +0200 Subject: [PATCH 13/18] FEATURE [personCalendar][genericDoc] implement genericDoc for calendar objects linked to a person --- .../PersonCalendarGenericDocProvider.php | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/PersonCalendarGenericDocProvider.php diff --git a/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/PersonCalendarGenericDocProvider.php b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/PersonCalendarGenericDocProvider.php new file mode 100644 index 000000000..12235f10a --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/PersonCalendarGenericDocProvider.php @@ -0,0 +1,112 @@ +em->getClassMetadata(CalendarDoc::class); + $storedObjectMetadata = $this->em->getClassMetadata(StoredObject::class); + $calendarMetadata = $this->em->getClassMetadata(Calendar::class); + + $query = new FetchQuery( + self::KEY, + sprintf("jsonb_build_object('id', cd.%s)", $classMetadata->getColumnName('id')), + 'cd.'.$storedObjectMetadata->getColumnName('createdAt'), + $classMetadata->getSchemaName().'.'.$classMetadata->getTableName().' AS cd' + ); + $query->addJoinClause( + 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', + $calendarMetadata->getSchemaName().'.'.$calendarMetadata->getTableName(), + $calendarMetadata->getColumnName('id'), + $classMetadata->getSingleAssociationJoinColumnName('calendar') + ) + ); + + $query->addWhereClause( + sprintf('calendar.%s = ?', + $calendarMetadata->getAssociationMapping('person')['joinColumns'][0]['name']), + [$person->getId()], + [Types::INTEGER] + ); + + 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] + ); + } + + dump($query); + + return $query; + } + + /** + * @param Person $person + * @return bool + */ + public function isAllowedForPerson(Person $person): bool + { + return $this->security->isGranted(CalendarVoter::SEE, $person); + } +} From 5196d26a3ea7ccac135fdda0f4f5fc93a2d70bf3 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 1 Jun 2023 10:44:14 +0200 Subject: [PATCH 14/18] FEATURE [translations] add translations --- src/Bundle/ChillCalendarBundle/translations/messages.fr.yml | 6 ++++++ src/Bundle/ChillDocStoreBundle/translations/messages.fr.yml | 1 - src/Bundle/ChillPersonBundle/translations/messages.fr.yml | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml index 5e1fc971a..99aae1082 100644 --- a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml @@ -147,3 +147,9 @@ CHILL_CALENDAR_CALENDAR_EDIT: Modifier les rendez-vous CHILL_CALENDAR_CALENDAR_DELETE: Supprimer les rendez-vous CHILL_CALENDAR_CALENDAR_SEE: Voir les rendez-vous + +generic_doc: + filter: + keys: + accompanying_period_calendar_document: Document des rendez-vous + person_calendar_document: Document des rendez-vous de la personne diff --git a/src/Bundle/ChillDocStoreBundle/translations/messages.fr.yml b/src/Bundle/ChillDocStoreBundle/translations/messages.fr.yml index 4fa41f180..1dde57eee 100644 --- a/src/Bundle/ChillDocStoreBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillDocStoreBundle/translations/messages.fr.yml @@ -26,7 +26,6 @@ generic_doc: filter: keys: accompanying_course_document: Document du parcours - accompanying_period_calendar_document: Document des rendez-vous date-range: Date du document # delete diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index a344ac50d..9b30e3a0b 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -1236,3 +1236,4 @@ generic_doc: filter: keys: accompanying_period_work_evaluation_document: Document des actions d'accompagnement + person_document: Documents de la personne From 59e1e02b92b3bc66a0dfb607c9455284138541f3 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 1 Jun 2023 10:45:55 +0200 Subject: [PATCH 15/18] FEATURE [calendar][docs] try to implement showing calendar docs from parcours context in person context --- .../PersonCalendarGenericDocProvider.php | 76 ++++++++++++++----- ...anyingPeriodCalendarGenericDocRenderer.php | 3 +- 2 files changed, 58 insertions(+), 21 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/PersonCalendarGenericDocProvider.php b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/PersonCalendarGenericDocProvider.php index 12235f10a..bed04414c 100644 --- a/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/PersonCalendarGenericDocProvider.php +++ b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/PersonCalendarGenericDocProvider.php @@ -19,6 +19,7 @@ use Chill\DocStoreBundle\GenericDoc\FetchQuery; use Chill\DocStoreBundle\GenericDoc\FetchQueryInterface; use Chill\DocStoreBundle\GenericDoc\GenericDocForPersonProviderInterface; use Chill\PersonBundle\Entity\Person; +use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkVoter; use DateTimeImmutable; use Doctrine\DBAL\Types\Types; 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 */ @@ -72,33 +105,36 @@ final class PersonCalendarGenericDocProvider implements GenericDocForPersonProvi [Types::INTEGER] ); - if (null !== $startDate) { - $query->addWhereClause( - sprintf('doc_store.%s >= ?', $storedObjectMetadata->getColumnName('createdAt')), - [$startDate], - [Types::DATE_IMMUTABLE] + // 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 (null !== $endDate) { - $query->addWhereClause( - sprintf('doc_store.%s < ?', $storedObjectMetadata->getColumnName('createdAt')), - [$endDate], - [Types::DATE_IMMUTABLE] - ); + if ([] === $or) { + $query->addWhereClause('TRUE = FALSE'); + + return $query; } - if (null !== $content) { - $query->addWhereClause( - sprintf('doc_store.%s ilike ?', $storedObjectMetadata->getColumnName('title')), - ['%' . $content . '%'], - [Types::STRING] - ); - } +// $query->addWhereClause(sprintf('(%s)', implode(' OR ', $or)), $orParams, $orTypes); - dump($query); + return $this->addWhereClausesToQuery($query, $startDate, $endDate, $content); - return $query; } /** diff --git a/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Renderers/AccompanyingPeriodCalendarGenericDocRenderer.php b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Renderers/AccompanyingPeriodCalendarGenericDocRenderer.php index 0f680797c..d9636d99d 100644 --- a/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Renderers/AccompanyingPeriodCalendarGenericDocRenderer.php +++ b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Renderers/AccompanyingPeriodCalendarGenericDocRenderer.php @@ -13,6 +13,7 @@ namespace Chill\CalendarBundle\Service\GenericDoc\Renderers; use Chill\CalendarBundle\Repository\CalendarDocRepository; use Chill\CalendarBundle\Service\GenericDoc\Providers\AccompanyingPeriodCalendarGenericDocProvider; +use Chill\CalendarBundle\Service\GenericDoc\Providers\PersonCalendarGenericDocProvider; use Chill\DocStoreBundle\GenericDoc\GenericDocDTO; use Chill\DocStoreBundle\GenericDoc\Twig\GenericDocRendererInterface; @@ -27,7 +28,7 @@ final class AccompanyingPeriodCalendarGenericDocRenderer implements GenericDocRe 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 From 5dc1cbce487fc0ea1ef96365271c89e11c383a60 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 1 Jun 2023 11:01:29 +0200 Subject: [PATCH 16/18] FEATURE [activity][docs] generic doc for activity documents in person context --- ...rsonActivityDocumentACLAwareRepository.php | 197 ++++++++++++++++++ .../PersonActivityGenericDocProvider.php | 57 +++++ 2 files changed, 254 insertions(+) create mode 100644 src/Bundle/ChillActivityBundle/Repository/PersonActivityDocumentACLAwareRepository.php create mode 100644 src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/PersonActivityGenericDocProvider.php diff --git a/src/Bundle/ChillActivityBundle/Repository/PersonActivityDocumentACLAwareRepository.php b/src/Bundle/ChillActivityBundle/Repository/PersonActivityDocumentACLAwareRepository.php new file mode 100644 index 000000000..862deb1ab --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Repository/PersonActivityDocumentACLAwareRepository.php @@ -0,0 +1,197 @@ +em = $em; + $this->centerResolverManager = $centerResolverManager; + $this->authorizationHelperForCurrentUser = $authorizationHelperForCurrentUser; + } + + public function buildQueryByPerson(Person $person): QueryBuilder + { + $qb = $this->em->getRepository(PersonDocument::class)->createQueryBuilder('d'); + + $qb + ->where($qb->expr()->eq('d.person', ':person')) + ->setParameter('person', $person); + + return $qb; + } + + + public function buildFetchQueryForPerson(Person $person, ?DateTimeImmutable $startDate = null, ?DateTimeImmutable $endDate = null, ?string $content = null): FetchQueryInterface + { + $query = $this->buildBaseFetchQueryForPerson($person, $startDate, $endDate, $content); + + return $this->addFetchQueryByPersonACL($query, $person); + } + + public function buildBaseFetchQueryForPerson(Person $person, ?DateTimeImmutable $startDate = null, ?DateTimeImmutable $endDate = null, ?string $content = null): FetchQuery + { + $storedObjectMetadata = $this->em->getClassMetadata(StoredObject::class); + + $query = new FetchQuery( + PersonDocumentGenericDocProvider::KEY, + sprintf('jsonb_build_object(\'id\', stored_obj.%s)', $storedObjectMetadata->getSingleIdentifierColumnName()), + sprintf('stored_obj.%s', $storedObjectMetadata->getColumnName('createdAt')), + sprintf('%s AS stored_obj', $storedObjectMetadata->getSchemaName().'.'.$storedObjectMetadata->getTableName()) + ); + + $query->addJoinClause( + 'JOIN public.activity_storedobject activity_doc ON activity_doc.storedobject_id = stored_obj.id' + ); + + $query->addJoinClause( + 'JOIN public.activity activity ON activity.id = activity_doc.activity_id' + ); + + $query->addWhereClause( + 'activity.person_id = ?', + [$person->getId()], + [Types::INTEGER] + ); + + if (null !== $startDate) { + $query->addWhereClause( + sprintf('stored_obj.%s >= ?', $storedObjectMetadata->getColumnName('createdAt')), + [$startDate], + [Types::DATE_IMMUTABLE] + ); + } + + if (null !== $endDate) { + $query->addWhereClause( + sprintf('stored_obj.%s < ?', $storedObjectMetadata->getColumnName('createdAt')), + [$endDate], + [Types::DATE_IMMUTABLE] + ); + } + + if (null !== $content) { + $query->addWhereClause( + 'stored_obj.title ilike ?', + ['%' . $content . '%'], + [Types::STRING] + ); + } + + return $query; + } + + public function countByPerson(Person $person): int + { + $qb = $this->buildQueryByPerson($person)->select('COUNT(d)'); + + $this->addACL($qb, $person); + + return $qb->getQuery()->getSingleScalarResult(); + } + + public function findByPerson(Person $person, array $orderBy = [], int $limit = 20, int $offset = 0): array + { + $qb = $this->buildQueryByPerson($person)->select('d'); + + $this->addACL($qb, $person); + + foreach ($orderBy as $field => $order) { + $qb->addOrderBy('d.' . $field, $order); + } + + $qb->setFirstResult($offset)->setMaxResults($limit); + + return $qb->getQuery()->getResult(); + } + + private function addACL(QueryBuilder $qb, Person $person): void + { + $reachableScopes = []; + + foreach ($this->centerResolverManager->resolveCenters($person) as $center) { + $reachableScopes = [ + ...$reachableScopes, + ...$this->authorizationHelperForCurrentUser + ->getReachableScopes( + PersonDocumentVoter::SEE, + $center + ) + ]; + } + + if ([] === $reachableScopes) { + $qb->andWhere("'FALSE' = 'TRUE'"); + + return; + } + + $qb->andWhere($qb->expr()->in('d.scope', ':scopes')) + ->setParameter('scopes', $reachableScopes); + } + + private function addFetchQueryByPersonACL(FetchQuery $fetchQuery, Person $person): FetchQuery + { + $personDocMetadata = $this->em->getClassMetadata(PersonDocument::class); + + $reachableScopes = []; + + foreach ($this->centerResolverManager->resolveCenters($person) as $center) { + $reachableScopes = [ + ...$reachableScopes, + ...$this->authorizationHelperForCurrentUser->getReachableScopes(PersonDocumentVoter::SEE, $center) + ]; + } + + if ([] === $reachableScopes) { + $fetchQuery->addWhereClause('FALSE = TRUE'); + + return $fetchQuery; + } + + $fetchQuery->addWhereClause( + sprintf( + 'person_document.%s IN (%s)', + $personDocMetadata->getSingleAssociationJoinColumnName('scope'), + implode(', ', array_fill(0, count($reachableScopes), '?')) + ), + array_map(static fn (Scope $s) => $s->getId(), $reachableScopes), + array_fill(0, count($reachableScopes), Types::INTEGER) + ); + + return $fetchQuery; + } +} diff --git a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/PersonActivityGenericDocProvider.php b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/PersonActivityGenericDocProvider.php new file mode 100644 index 000000000..d00a23e79 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/PersonActivityGenericDocProvider.php @@ -0,0 +1,57 @@ +security = $security; + $this->personActivityDocumentACLAwareRepository = $personActivityDocumentACLAwareRepository; + } + + public function buildFetchQueryForPerson(Person $person, ?DateTimeImmutable $startDate = null, ?DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface + { + return $this->personActivityDocumentACLAwareRepository->buildFetchQueryForPerson( + $person, + $startDate, + $endDate, + $content + ); + } + + /** + * @param Person $person + * @return bool + */ + public function isAllowedForPerson(Person $person): bool + { + return $this->security->isGranted(ActivityVoter::SEE, $person); + } +} From 7eb4fb4e563d618b562786e9d36c1c6aa820ea58 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 1 Jun 2023 13:09:51 +0200 Subject: [PATCH 17/18] FEATURE [calendar][docs] fix query to display rendez-vous documents from person and parcours contexts --- .../Providers/PersonCalendarGenericDocProvider.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/PersonCalendarGenericDocProvider.php b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/PersonCalendarGenericDocProvider.php index bed04414c..640f0d197 100644 --- a/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/PersonCalendarGenericDocProvider.php +++ b/src/Bundle/ChillCalendarBundle/Service/GenericDoc/Providers/PersonCalendarGenericDocProvider.php @@ -98,13 +98,6 @@ final class PersonCalendarGenericDocProvider implements GenericDocForPersonProvi ) ); - $query->addWhereClause( - sprintf('calendar.%s = ?', - $calendarMetadata->getAssociationMapping('person')['joinColumns'][0]['name']), - [$person->getId()], - [Types::INTEGER] - ); - // get the documents associated with accompanying periods in which person participates $or = []; $orParams = []; From 2aeb72811a68f51dfc2c1ff300c34c7aa28a62ae Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 1 Jun 2023 13:31:35 +0200 Subject: [PATCH 18/18] [activity][docs] attempt to implement generic doc for activity documents in person context --- ...rsonActivityDocumentACLAwareRepository.php | 64 +++++++++++++------ ...anyingPeriodActivityGenericDocProvider.php | 4 +- ...anyingPeriodActivityGenericDocRenderer.php | 3 +- 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Repository/PersonActivityDocumentACLAwareRepository.php b/src/Bundle/ChillActivityBundle/Repository/PersonActivityDocumentACLAwareRepository.php index 862deb1ab..84bb08fb4 100644 --- a/src/Bundle/ChillActivityBundle/Repository/PersonActivityDocumentACLAwareRepository.php +++ b/src/Bundle/ChillActivityBundle/Repository/PersonActivityDocumentACLAwareRepository.php @@ -11,6 +11,8 @@ declare(strict_types=1); namespace Chill\ActivityBundle\Repository; +use Chill\ActivityBundle\Entity\Activity; +use Chill\ActivityBundle\Security\Authorization\ActivityVoter; use Chill\DocStoreBundle\Entity\PersonDocument; use Chill\DocStoreBundle\Entity\StoredObject; use Chill\DocStoreBundle\GenericDoc\FetchQuery; @@ -22,25 +24,22 @@ use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Security\Authorization\AuthorizationHelperForCurrentUserInterface; use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface; use Chill\PersonBundle\Entity\Person; +use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodWorkVoter; use DateTimeImmutable; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\QueryBuilder; use Symfony\Component\HttpKernel\HttpCache\Store; +use Symfony\Component\Security\Core\Security; class PersonActivityDocumentACLAwareRepository implements PersonDocumentACLAwareRepositoryInterface { - private AuthorizationHelperForCurrentUserInterface $authorizationHelperForCurrentUser; - - private CenterResolverManagerInterface $centerResolverManager; - - private EntityManagerInterface $em; - - public function __construct(EntityManagerInterface $em, CenterResolverManagerInterface $centerResolverManager, AuthorizationHelperForCurrentUserInterface $authorizationHelperForCurrentUser) + public function __construct( + private EntityManagerInterface $em, + private CenterResolverManagerInterface $centerResolverManager, + private AuthorizationHelperForCurrentUserInterface $authorizationHelperForCurrentUser, + private Security $security) { - $this->em = $em; - $this->centerResolverManager = $centerResolverManager; - $this->authorizationHelperForCurrentUser = $authorizationHelperForCurrentUser; } public function buildQueryByPerson(Person $person): QueryBuilder @@ -65,10 +64,11 @@ class PersonActivityDocumentACLAwareRepository implements PersonDocumentACLAware public function buildBaseFetchQueryForPerson(Person $person, ?DateTimeImmutable $startDate = null, ?DateTimeImmutable $endDate = null, ?string $content = null): FetchQuery { $storedObjectMetadata = $this->em->getClassMetadata(StoredObject::class); + $activityMetadata = $this->em->getClassMetadata(Activity::class); $query = new FetchQuery( PersonDocumentGenericDocProvider::KEY, - sprintf('jsonb_build_object(\'id\', stored_obj.%s)', $storedObjectMetadata->getSingleIdentifierColumnName()), + sprintf('jsonb_build_object(\'id\', stored_obj.%s, \'activity_id\', activity.%s)', $storedObjectMetadata->getSingleIdentifierColumnName(), $activityMetadata->getSingleIdentifierColumnName()), sprintf('stored_obj.%s', $storedObjectMetadata->getColumnName('createdAt')), sprintf('%s AS stored_obj', $storedObjectMetadata->getSchemaName().'.'.$storedObjectMetadata->getTableName()) ); @@ -81,11 +81,39 @@ class PersonActivityDocumentACLAwareRepository implements PersonDocumentACLAware 'JOIN public.activity activity ON activity.id = activity_doc.activity_id' ); - $query->addWhereClause( + // add documents of activities from parcours context + $or = []; + $orParams = []; + $orTypes = []; + foreach ($person->getAccompanyingPeriodParticipations() as $participation) { + if (!$this->security->isGranted(ActivityVoter::SEE, $participation->getAccompanyingPeriod())) { + continue; + } + + $or[] = sprintf( + '(activity.%s = ? AND stored_obj.%s BETWEEN ?::date AND COALESCE(?::date, \'infinity\'::date))', + $activityMetadata->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( 'activity.person_id = ?', [$person->getId()], [Types::INTEGER] - ); + );*/ if (null !== $startDate) { $query->addWhereClause( @@ -147,7 +175,7 @@ class PersonActivityDocumentACLAwareRepository implements PersonDocumentACLAware ...$reachableScopes, ...$this->authorizationHelperForCurrentUser ->getReachableScopes( - PersonDocumentVoter::SEE, + ActivityVoter::SEE, $center ) ]; @@ -165,14 +193,14 @@ class PersonActivityDocumentACLAwareRepository implements PersonDocumentACLAware private function addFetchQueryByPersonACL(FetchQuery $fetchQuery, Person $person): FetchQuery { - $personDocMetadata = $this->em->getClassMetadata(PersonDocument::class); + $activityMetadata = $this->em->getClassMetadata(Activity::class); $reachableScopes = []; foreach ($this->centerResolverManager->resolveCenters($person) as $center) { $reachableScopes = [ ...$reachableScopes, - ...$this->authorizationHelperForCurrentUser->getReachableScopes(PersonDocumentVoter::SEE, $center) + ...$this->authorizationHelperForCurrentUser->getReachableScopes(ActivityVoter::SEE, $center) ]; } @@ -184,8 +212,8 @@ class PersonActivityDocumentACLAwareRepository implements PersonDocumentACLAware $fetchQuery->addWhereClause( sprintf( - 'person_document.%s IN (%s)', - $personDocMetadata->getSingleAssociationJoinColumnName('scope'), + 'activity.%s IN (%s)', + $activityMetadata->getSingleAssociationJoinColumnName('scope'), implode(', ', array_fill(0, count($reachableScopes), '?')) ), array_map(static fn (Scope $s) => $s->getId(), $reachableScopes), diff --git a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php index 8c787fd3a..284182cfb 100644 --- a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php +++ b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Providers/AccompanyingPeriodActivityGenericDocProvider.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\ActivityBundle\Service\GenericDoc\Providers; +use Chill\ActivityBundle\Entity\Activity; use Chill\ActivityBundle\Security\Authorization\ActivityVoter; use Chill\DocStoreBundle\Entity\StoredObject; use Chill\DocStoreBundle\GenericDoc\FetchQuery; @@ -36,10 +37,11 @@ final class AccompanyingPeriodActivityGenericDocProvider implements GenericDocFo public function buildFetchQueryForAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod, ?DateTimeImmutable $startDate = null, ?DateTimeImmutable $endDate = null, ?string $content = null, ?string $origin = null): FetchQueryInterface { $storedObjectMetadata = $this->em->getClassMetadata(StoredObject::class); + $activityMetadata = $this->em->getClassMetadata(Activity::class); $query = new FetchQuery( self::KEY, - "jsonb_build_object('id', doc_obj.id, 'activity_id', activity.id)", + sprintf("jsonb_build_object('id', doc_obj.%s, 'activity_id', activity.%s)", $storedObjectMetadata->getSingleIdentifierColumnName(), $activityMetadata->getSingleIdentifierColumnName()), 'doc_obj.'.$storedObjectMetadata->getColumnName('createdAt'), $storedObjectMetadata->getSchemaName().'.'.$storedObjectMetadata->getTableName().' AS doc_obj' ); diff --git a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php index f3b70dac2..9f9a4bec8 100644 --- a/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php +++ b/src/Bundle/ChillActivityBundle/Service/GenericDoc/Renderers/AccompanyingPeriodActivityGenericDocRenderer.php @@ -13,6 +13,7 @@ namespace Chill\ActivityBundle\Service\GenericDoc\Renderers; use Chill\ActivityBundle\Repository\ActivityRepository; use Chill\ActivityBundle\Service\GenericDoc\Providers\AccompanyingPeriodActivityGenericDocProvider; +use Chill\ActivityBundle\Service\GenericDoc\Providers\PersonActivityGenericDocProvider; use Chill\DocStoreBundle\GenericDoc\GenericDocDTO; use Chill\DocStoreBundle\GenericDoc\Twig\GenericDocRendererInterface; use Chill\DocStoreBundle\Repository\StoredObjectRepository; @@ -31,7 +32,7 @@ final class AccompanyingPeriodActivityGenericDocRenderer implements GenericDocRe public function supports(GenericDocDTO $genericDocDTO, $options = []): bool { - return $genericDocDTO->key === AccompanyingPeriodActivityGenericDocProvider::KEY; + return $genericDocDTO->key === AccompanyingPeriodActivityGenericDocProvider::KEY || $genericDocDTO->key === PersonActivityGenericDocProvider::KEY; } public function getTemplate(GenericDocDTO $genericDocDTO, $options = []): string