From 6f28d154c8f01b669c8a345320d07afdb9dacd54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 16 Sep 2024 15:25:25 +0200 Subject: [PATCH] Fix referrers display to show only current referrers. Updated the view to loop through current referrers in the accompanying period. Added new method `getReferrersHistoryCurrent` to the entity to filter and return only active referrers, ensuring correct display in the UI. Also included documentation for better code clarity. --- .../unreleased/Fixed-20240916-151843.yaml | 6 ++++++ .../AccompanyingPeriodWork.php | 20 ++++++++++++++++++- .../AccompanyingCourseWork/_item.html.twig | 4 ++-- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 .changes/unreleased/Fixed-20240916-151843.yaml diff --git a/.changes/unreleased/Fixed-20240916-151843.yaml b/.changes/unreleased/Fixed-20240916-151843.yaml new file mode 100644 index 000000000..ba89d3a70 --- /dev/null +++ b/.changes/unreleased/Fixed-20240916-151843.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: Show only the current referrer in the page "show" for an accompanying period + workf +time: 2024-09-16T15:18:43.017401122+02:00 +custom: + Issue: "308" diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php index 755f499d5..fbd1a54a3 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php @@ -394,7 +394,13 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues } /** - * @return ReadableCollection + * Retrieves a collection of current referrers. + * + * This method filters the referrer history to get only those entries + * where the end date is null, maps them to their associated users, + * and returns them as a new ReadableCollection. + * + * @return ReadableCollection collection of active referrers * * @Serializer\Groups({"accompanying_period_work:edit"}) */ @@ -408,6 +414,18 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues return new ArrayCollection(array_values($users)); } + /** + * @return ReadableCollection + */ + public function getReferrersHistoryCurrent(): ReadableCollection + { + return new ArrayCollection( + $this->getReferrersHistory() + ->filter(fn (AccompanyingPeriodWorkReferrerHistory $h) => null === $h->getEndDate()) + ->getValues() + ); + } + /** * @return Collection */ diff --git a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourseWork/_item.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourseWork/_item.html.twig index 6477f4a95..737a8af24 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourseWork/_item.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/AccompanyingCourseWork/_item.html.twig @@ -83,10 +83,10 @@
{%- if w.referrers|length > 0 -%} - {% for r in w.referrersHistory %} + {% for r in w.referrersHistoryCurrent %} {{ r.user|chill_entity_render_box({'at_date': r.startDate}) }} - {% if not loop.last %}, {% endif %} + {%- if not loop.last %}, {% endif %} {% endfor %} {% else %}