mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Feature: [calendar] show the number of calendars ignored by the date filter, in the list
This commit is contained in:
@@ -64,31 +64,38 @@ class CalendarACLAwareRepository implements CalendarACLAwareRepositoryInterface
|
||||
return $qb;
|
||||
}
|
||||
|
||||
public function buildQueryByAccompanyingPeriodIgnoredByDates(AccompanyingPeriod $period, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): QueryBuilder
|
||||
{
|
||||
$qb = $this->em->createQueryBuilder();
|
||||
$qb->from(Calendar::class, 'c');
|
||||
|
||||
$andX = $qb->expr()->andX($qb->expr()->eq('c.accompanyingPeriod', ':period'));
|
||||
$qb->setParameter('period', $period);
|
||||
|
||||
if (null !== $startDate) {
|
||||
$andX->add($qb->expr()->lt('c.startDate', ':startDate'));
|
||||
$qb->setParameter('startDate', $startDate);
|
||||
}
|
||||
|
||||
if (null !== $endDate) {
|
||||
$andX->add($qb->expr()->gt('c.endDate', ':endDate'));
|
||||
$qb->setParameter('endDate', $endDate);
|
||||
}
|
||||
|
||||
$qb->where($andX);
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Base implementation. The list of allowed accompanying period is retrieved "manually" from @see{AccompanyingPeriodACLAwareRepository}.
|
||||
*/
|
||||
public function buildQueryByPerson(Person $person, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): QueryBuilder
|
||||
{
|
||||
// find the reachable accompanying periods for person
|
||||
$periods = $this->accompanyingPeriodACLAwareRepository->findByPerson($person, AccompanyingPeriodVoter::SEE);
|
||||
|
||||
$qb = $this->em->createQueryBuilder()
|
||||
->from(Calendar::class, 'c');
|
||||
|
||||
$qb
|
||||
->where(
|
||||
$qb->expr()->orX(
|
||||
// the calendar where the person is the main person:
|
||||
$qb->expr()->eq('c.person', ':person'),
|
||||
// when the calendar is in a reachable period, and contains person
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->in('c.accompanyingPeriod', ':periods'),
|
||||
$qb->expr()->isMemberOf(':person', 'c.persons')
|
||||
)
|
||||
)
|
||||
)
|
||||
->setParameter('person', $person)
|
||||
->setParameter('periods', $periods);
|
||||
$this->addQueryByPersonWithoutDate($qb, $person);
|
||||
|
||||
// filter by date
|
||||
if (null !== $startDate) {
|
||||
@@ -104,6 +111,30 @@ class CalendarACLAwareRepository implements CalendarACLAwareRepositoryInterface
|
||||
return $qb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Base implementation. The list of allowed accompanying period is retrieved "manually" from @see{AccompanyingPeriodACLAwareRepository}.
|
||||
*/
|
||||
public function buildQueryByPersonIgnoredByDates(Person $person, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): QueryBuilder
|
||||
{
|
||||
$qb = $this->em->createQueryBuilder()
|
||||
->from(Calendar::class, 'c');
|
||||
|
||||
$this->addQueryByPersonWithoutDate($qb, $person);
|
||||
|
||||
// filter by date
|
||||
if (null !== $startDate) {
|
||||
$qb->andWhere($qb->expr()->lt('c.startDate', ':startDate'))
|
||||
->setParameter('startDate', $startDate);
|
||||
}
|
||||
|
||||
if (null !== $endDate) {
|
||||
$qb->andWhere($qb->expr()->gt('c.endDate', ':endDate'))
|
||||
->setParameter('endDate', $endDate);
|
||||
}
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
public function countByAccompanyingPeriod(AccompanyingPeriod $period, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): int
|
||||
{
|
||||
$qb = $this->buildQueryByAccompanyingPeriod($period, $startDate, $endDate)->select('count(c)');
|
||||
@@ -119,6 +150,21 @@ class CalendarACLAwareRepository implements CalendarACLAwareRepositoryInterface
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
|
||||
public function countIgnoredByAccompanyingPeriod(AccompanyingPeriod $period, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): int
|
||||
{
|
||||
$qb = $this->buildQueryByAccompanyingPeriodIgnoredByDates($period, $startDate, $endDate)->select('count(c)');
|
||||
|
||||
return $qb->getQuery()->getSingleScalarResult();
|
||||
}
|
||||
|
||||
public function countIgnoredByPerson(Person $person, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): int
|
||||
{
|
||||
return $this->buildQueryByPersonIgnoredByDates($person, $startDate, $endDate)
|
||||
->select('COUNT(c)')
|
||||
->getQuery()
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|Calendar[]
|
||||
*/
|
||||
@@ -160,4 +206,25 @@ class CalendarACLAwareRepository implements CalendarACLAwareRepositoryInterface
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
private function addQueryByPersonWithoutDate(QueryBuilder $qb, Person $person): void
|
||||
{
|
||||
// find the reachable accompanying periods for person
|
||||
$periods = $this->accompanyingPeriodACLAwareRepository->findByPerson($person, AccompanyingPeriodVoter::SEE);
|
||||
|
||||
$qb
|
||||
->where(
|
||||
$qb->expr()->orX(
|
||||
// the calendar where the person is the main person:
|
||||
$qb->expr()->eq('c.person', ':person'),
|
||||
// when the calendar is in a reachable period, and contains person
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->in('c.accompanyingPeriod', ':periods'),
|
||||
$qb->expr()->isMemberOf(':person', 'c.persons')
|
||||
)
|
||||
)
|
||||
)
|
||||
->setParameter('person', $person)
|
||||
->setParameter('periods', $periods);
|
||||
}
|
||||
}
|
||||
|
@@ -32,6 +32,18 @@ interface CalendarACLAwareRepositoryInterface
|
||||
*/
|
||||
public function countByPerson(Person $person, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): int;
|
||||
|
||||
/**
|
||||
* Return the number or calendars associated with an accompanyign period which **does not** match the date conditions.
|
||||
*/
|
||||
public function countIgnoredByAccompanyingPeriod(AccompanyingPeriod $period, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): int;
|
||||
|
||||
/**
|
||||
* Return the number or calendars associated with a person which **does not** match the date conditions.
|
||||
*
|
||||
* See condition on @see{self::findByPerson}.
|
||||
*/
|
||||
public function countIgnoredByPerson(Person $person, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): int;
|
||||
|
||||
/**
|
||||
* @return array|Calendar[]
|
||||
*/
|
||||
|
Reference in New Issue
Block a user