Add a mention on next calendars on search results

This commit is contained in:
2022-07-01 18:01:42 +02:00
parent 3dcec5d44a
commit 8bbd3b01d9
7 changed files with 79 additions and 6 deletions

View File

@@ -129,6 +129,11 @@ class AccompanyingPeriod implements
*/
private ?Location $administrativeLocation = null;
/**
* @ORM\OneToMany(targetEntity="Chill\CalendarBundle\Entity\Calendar", mappedBy="accompanyingPeriod")
*/
private Collection $calendars;
/**
* @var DateTime
*
@@ -389,6 +394,7 @@ class AccompanyingPeriod implements
public function __construct(?DateTime $dateOpening = null)
{
$this->setOpeningDate($dateOpening ?? new DateTime('now'));
$this->calendars = new ArrayCollection();
$this->participations = new ArrayCollection();
$this->scopes = new ArrayCollection();
$this->socialIssues = new ArrayCollection();
@@ -612,6 +618,11 @@ class AccompanyingPeriod implements
);
}
public function getCalendars(): Collection
{
return $this->calendars;
}
public function getCenter(): ?Center
{
if ($this->getPersons()->count() === 0) {
@@ -765,6 +776,24 @@ class AccompanyingPeriod implements
return 'none';
}
public function getNextCalendarsForPerson(Person $person, $limit = 5): Collection
{
$today = new DateTimeImmutable('today');
$criteria = Criteria::create()
->where(Criteria::expr()->gte('startDate', $today))
//->andWhere(Criteria::expr()->memberOf('persons', $person))
->orderBy(['startDate' => 'DESC'])
->setMaxResults($limit * 2);
return $this->calendars->matching($criteria)
->matching(
// due to a bug, filter two times
Criteria::create()
->where(Criteria::expr()->memberOf('persons', $person))
->setMaxResults($limit)
);
}
/**
* Get openingDate.
*

View File

@@ -176,6 +176,14 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
*/
private Collection $budgetResources;
/**
* @ORM\ManyToMany(
* targetEntity="Chill\CalendarBundle\Entity\Calendar",
* mappedBy="persons"
* )
*/
private Collection $calendars;
/**
* The person's center.
*