Display calendar items linked to person within search results

This commit is contained in:
2025-11-12 13:00:52 +01:00
parent 0a58e05230
commit f7ea7e4dbf
4 changed files with 74 additions and 9 deletions

View File

@@ -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<int, Calendar>
*/
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) {