From f7ea7e4dbf03cd091bd281c869042da9d5e1e5be Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 12 Nov 2025 13:00:52 +0100 Subject: [PATCH] Display calendar items linked to person within search results --- .../unreleased/Feature-20251112-130016.yaml | 6 ++++ .../public/chill/scss/calendar-list.scss | 18 +++++----- .../ChillPersonBundle/Entity/Person.php | 23 ++++++++++++ .../Resources/views/Entity/person.html.twig | 36 +++++++++++++++++++ 4 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 .changes/unreleased/Feature-20251112-130016.yaml diff --git a/.changes/unreleased/Feature-20251112-130016.yaml b/.changes/unreleased/Feature-20251112-130016.yaml new file mode 100644 index 000000000..d7a576dde --- /dev/null +++ b/.changes/unreleased/Feature-20251112-130016.yaml @@ -0,0 +1,6 @@ +kind: Feature +body: Display appointments (calendar items) linked to a person within the search results, like it was done for accompanying periods +time: 2025-11-12T13:00:16.844313583+01:00 +custom: + Issue: "462" + SchemaChange: No schema change diff --git a/src/Bundle/ChillCalendarBundle/Resources/public/chill/scss/calendar-list.scss b/src/Bundle/ChillCalendarBundle/Resources/public/chill/scss/calendar-list.scss index 6fa84f15a..654d8c8c5 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/public/chill/scss/calendar-list.scss +++ b/src/Bundle/ChillCalendarBundle/Resources/public/chill/scss/calendar-list.scss @@ -14,13 +14,13 @@ div.calendar-list { ul.calendar-list { display: inline-block; } - - & > a.calendar-list__global { - display: inline-block; - padding: 0.2rem; - min-width: 2rem; - border: 1px solid var(--bs-chill-blue); - border-radius: 0.25rem; - text-align: center; - } +} + +.calendar-list__global { + display: inline-block; + padding: 0.2rem; + min-width: 2rem; + border: 1px solid var(--bs-chill-blue); + border-radius: 0.25rem; + text-align: center; } diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index aa78774b6..d75a0d9df 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -866,6 +866,29 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this->calendars; } + /** + * Get next calendars for this person. + * Only returns calendars where this person is in the persons collection and the person property is not null. + * + * @param int $limit Maximum number of calendars to return + * + * @return ReadableCollection + */ + public function getNextCalendarsForPerson(int $limit = 5): ReadableCollection + { + $today = new \DateTimeImmutable('today'); + + $filtered = $this->calendars->filter( + fn (Calendar $calendar) => $calendar->getStartDate() >= $today + && $calendar->getPerson() === $this + ); + + $sorted = $filtered->toArray(); + usort($sorted, fn ($a, $b) => $a->getStartDate() <=> $b->getStartDate()); + + return new ArrayCollection(array_slice($sorted, 0, $limit)); + } + public function getCenter(): ?Center { if (null !== $this->centerCurrent) { diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig index d8a930b40..417ff4e7b 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig @@ -189,7 +189,43 @@ {% endfor %} {% endif %} + + {% set calendars = [] %} + {% for c in person.getNextCalendarsForPerson(10) %} + {% if is_granted('CHILL_CALENDAR_CALENDAR_SEE', c) %} + {% set calendars = calendars|merge([c]) %} + {% endif %} + {% endfor %} + + {% if calendars|length > 0 %} +
+
{{ 'chill_calendar.Next calendars'|trans }}
+ + + {% if is_granted('CHILL_CALENDAR_CALENDAR_SEE', person) %} + + {% endif %} +
+ {% endif %} + +
    {% if options['customButtons']['before'] is defined %} {{ options['customButtons']['before'] }}