mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-01-15 05:41:25 +00:00
Improve the display of upcoming calendar items within the person render box
This commit is contained in:
@@ -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<int, Calendar>&Selectable<int, Calendar>
|
||||
*/
|
||||
#[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<Calendar>
|
||||
*/
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user