diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index aa78774b6..2cdb99c54 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -43,6 +43,7 @@ use DateTime; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Criteria; +use Doctrine\Common\Collections\Order; use Doctrine\Common\Collections\ReadableCollection; use Doctrine\Common\Collections\Selectable; use Doctrine\ORM\Mapping as ORM; @@ -139,6 +140,12 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI #[ORM\ManyToMany(targetEntity: Calendar::class, mappedBy: 'persons')] private Collection $calendars; + /** + * @var Collection&Selectable + */ + #[ORM\OneToMany(mappedBy: 'person', targetEntity: Calendar::class)] + private Collection $directCalendars; + /** * The person's center. * @@ -406,6 +413,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI public function __construct() { $this->calendars = new ArrayCollection(); + $this->directCalendars = new ArrayCollection(); $this->accompanyingPeriodParticipations = new ArrayCollection(); $this->spokenLanguages = new ArrayCollection(); $this->addresses = new ArrayCollection(); @@ -866,6 +874,30 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI return $this->calendars; } + /** + * Get next calendars for this person (calendars with start date after today). + * Only returns calendars that are directly linked to this person via the person property, + * not those linked through AccompanyingPeriods. + * + * @param int|null $limit Optional limit for the number of results + * + * @return array + */ + public function getNextCalendarsForPerson(?int $limit = null): array + { + $today = new \DateTimeImmutable('today'); + + $criteria = Criteria::create() + ->where(Criteria::expr()->gte('startDate', $today)) + ->orderBy(['startDate' => Order::Ascending]); + + if (null !== $limit) { + $criteria->setMaxResults($limit); + } + + return $this->directCalendars->matching($criteria)->toArray(); + } + public function getCenter(): ?Center { if (null !== $this->centerCurrent) { @@ -1119,7 +1151,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI ->where( $expr->eq('shareHousehold', false) ) - ->orderBy(['startDate' => \Doctrine\Common\Collections\Order::Descending]); + ->orderBy(['startDate' => Order::Descending]); return $this->getHouseholdParticipations() ->matching($criteria); @@ -1141,7 +1173,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI ->where( $expr->eq('shareHousehold', true) ) - ->orderBy(['startDate' => \Doctrine\Common\Collections\Order::Descending, 'id' => \Doctrine\Common\Collections\Order::Descending]); + ->orderBy(['startDate' => Order::Descending, 'id' => Order::Descending]); return $this->getHouseholdParticipations() ->matching($criteria); diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig index 5572bd7b1..c373fd58b 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig @@ -212,4 +212,3 @@ {%- endif -%} - diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig index 0840cecb6..cf7fb1466 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/list_with_period.html.twig @@ -301,6 +301,47 @@ 'customButtons': { 'after': _self.button_person_after(person), 'before': _self.button_person_before((person)) } }) }} + {% 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 %} + {#- 'acps' is for AcCompanyingPeriodS #} {%- set acps = [] %} {%- set acpsClosed = [] %}