mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-01-14 05:11:23 +00:00
Display calendar items linked to person within search results
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user