From dd056efa0d2e2ef72995827cbddceac28eec2bd2 Mon Sep 17 00:00:00 2001 From: LenaertsJ Date: Thu, 14 Mar 2024 21:35:00 +0000 Subject: [PATCH] In the accompanying period list, add person's centers and duration --- .../unreleased/Feature-20240314-222634.yaml | 6 +++ .../Helper/ListAccompanyingPeriodHelper.php | 37 +++++++++++++++++++ .../translations/messages.fr.yml | 2 + 3 files changed, 45 insertions(+) create mode 100644 .changes/unreleased/Feature-20240314-222634.yaml diff --git a/.changes/unreleased/Feature-20240314-222634.yaml b/.changes/unreleased/Feature-20240314-222634.yaml new file mode 100644 index 000000000..3a484a474 --- /dev/null +++ b/.changes/unreleased/Feature-20240314-222634.yaml @@ -0,0 +1,6 @@ +kind: Feature +body: In the list of accompangying period, add the list of person's centers and the + duration of the course +time: 2024-03-14T22:26:34.103648729+01:00 +custom: + Issue: "258" diff --git a/src/Bundle/ChillPersonBundle/Export/Helper/ListAccompanyingPeriodHelper.php b/src/Bundle/ChillPersonBundle/Export/Helper/ListAccompanyingPeriodHelper.php index 2c2bc1d02..ba14d4e2c 100644 --- a/src/Bundle/ChillPersonBundle/Export/Helper/ListAccompanyingPeriodHelper.php +++ b/src/Bundle/ChillPersonBundle/Export/Helper/ListAccompanyingPeriodHelper.php @@ -16,10 +16,12 @@ use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Export\Helper\DateTimeHelper; use Chill\MainBundle\Export\Helper\ExportAddressHelper; use Chill\MainBundle\Export\Helper\UserHelper; +use Chill\MainBundle\Repository\CenterRepository; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation; use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress; +use Chill\PersonBundle\Entity\Person\PersonCenterHistory; use Chill\PersonBundle\Entity\SocialWork\SocialIssue; use Chill\PersonBundle\Repository\PersonRepository; use Chill\PersonBundle\Repository\SocialWork\SocialIssueRepository; @@ -39,6 +41,8 @@ final readonly class ListAccompanyingPeriodHelper 'stepSince', 'openingDate', 'closingDate', + 'duration', + 'centers', 'referrer', 'referrerSince', 'acpParticipantPersons', @@ -83,6 +87,7 @@ final readonly class ListAccompanyingPeriodHelper private TranslatorInterface $translator, private UserHelper $userHelper, private LabelPersonHelper $labelPersonHelper, + private CenterRepository $centerRepository ) { } @@ -202,6 +207,25 @@ final readonly class ListAccompanyingPeriodHelper AccompanyingPeriod::INTENSITY_REGULAR => $this->translator->trans('regular'), default => $value, }, + 'centers' => function ($value) use ($key) { + if ('_header' === $value) { + return 'export.list.acp.'.$key; + } + + if (null === $value || '' === $value || !json_validate((string) $value)) { + return ''; + } + + return implode( + '|', + array_map( + fn ($cid) => $this->centerRepository->find($cid)->getName(), + array_unique( + json_decode((string) $value, true, 512, JSON_THROW_ON_ERROR) + ) + ) + ); + }, default => static function ($value) use ($key) { if ('_header' === $value) { return 'export.list.acp.'.$key; @@ -315,6 +339,19 @@ final readonly class ListAccompanyingPeriodHelper // social issues ->addSelect('(SELECT AGGREGATE(socialIssue.id) FROM '.SocialIssue::class.' socialIssue WHERE socialIssue MEMBER OF acp.socialIssues) AS socialIssues'); + // duration + $qb->addSelect('DATE_DIFF(COALESCE(acp.closingDate, :calcDate), acp.openingDate) AS duration'); + + // centers + $qb->addSelect( + '(SELECT AGGREGATE(IDENTITY(cppch.center)) + FROM '.AccompanyingPeriodParticipation::class.' part + JOIN '.PersonCenterHistory::class." cppch + WITH IDENTITY(cppch.person) = IDENTITY(part.person) + AND OVERLAPSI (cppch.startDate, cppch.endDate), (part.startDate, part.endDate) = 'TRUE' + WHERE part.accompanyingPeriod = acp + ) AS centers" + ); // add parameter $qb->setParameter('calcDate', $calcDate); } diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 812c6eb89..013298ba5 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -1346,6 +1346,8 @@ export: requestorThirdParty: Demandeur (tiers) acpParticipantPersons: Usagers concernés acpParticipantPersonsIds: Usagers concernés (identifiants) + duration: Durée du parcours (en jours) + centers: Centres des usagers eval: List of evaluations: Liste des évaluations