mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 22:04:23 +00:00
add center filter to calendar exports linked to acp
This commit is contained in:
parent
96a9be39c3
commit
c3ced7fb6e
@ -28,9 +28,14 @@ use Symfony\Component\Validator\Exception\LogicException;
|
|||||||
|
|
||||||
class CountCalendars implements ExportInterface, GroupedExportInterface
|
class CountCalendars implements ExportInterface, GroupedExportInterface
|
||||||
{
|
{
|
||||||
|
private readonly bool $filterStatsByCenters;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly CalendarRepository $calendarRepository,
|
private readonly CalendarRepository $calendarRepository,
|
||||||
) {}
|
ParameterBagInterface $parameterBag,
|
||||||
|
) {
|
||||||
|
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
|
||||||
|
}
|
||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder)
|
public function buildForm(FormBuilderInterface $builder)
|
||||||
{
|
{
|
||||||
@ -101,6 +106,19 @@ class CountCalendars implements ExportInterface, GroupedExportInterface
|
|||||||
$qb->select('COUNT(cal.id) AS export_result');
|
$qb->select('COUNT(cal.id) AS export_result');
|
||||||
$qb->leftJoin('cal.accompanyingPeriod', 'acp');
|
$qb->leftJoin('cal.accompanyingPeriod', 'acp');
|
||||||
|
|
||||||
|
if ($this->filterStatsByCenters) {
|
||||||
|
$qb
|
||||||
|
->andWhere(
|
||||||
|
$qb->expr()->exists(
|
||||||
|
'SELECT 1 FROM '.AccompanyingPeriodParticipation::class.' acl_count_part
|
||||||
|
JOIN '.PersonCenterHistory::class.' acl_count_person_history WITH IDENTITY(acl_count_person_history.person) = IDENTITY(acl_count_part.person)
|
||||||
|
WHERE acl_count_part.accompanyingPeriod = acp.id AND acl_count_person_history.center IN (:authorized_centers)
|
||||||
|
'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
->setParameter('authorized_centers', $centers);
|
||||||
|
}
|
||||||
|
|
||||||
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);
|
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);
|
||||||
|
|
||||||
return $qb;
|
return $qb;
|
||||||
|
@ -17,14 +17,25 @@ use Chill\MainBundle\Export\AccompanyingCourseExportHelper;
|
|||||||
use Chill\MainBundle\Export\ExportInterface;
|
use Chill\MainBundle\Export\ExportInterface;
|
||||||
use Chill\MainBundle\Export\FormatterInterface;
|
use Chill\MainBundle\Export\FormatterInterface;
|
||||||
use Chill\MainBundle\Export\GroupedExportInterface;
|
use Chill\MainBundle\Export\GroupedExportInterface;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||||
|
use Chill\PersonBundle\Entity\Person\PersonCenterHistory;
|
||||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||||
use Doctrine\ORM\Query;
|
use Doctrine\ORM\Query;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
|
||||||
class StatCalendarAvgDuration implements ExportInterface, GroupedExportInterface
|
class StatCalendarAvgDuration implements ExportInterface, GroupedExportInterface
|
||||||
{
|
{
|
||||||
public function __construct(private readonly CalendarRepository $calendarRepository) {}
|
private readonly bool $filterStatsByCenters;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly CalendarRepository $calendarRepository,
|
||||||
|
ParameterBagInterface $parameterBag,
|
||||||
|
|
||||||
|
) {
|
||||||
|
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
|
||||||
|
}
|
||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder): void
|
public function buildForm(FormBuilderInterface $builder): void
|
||||||
{
|
{
|
||||||
@ -85,11 +96,26 @@ class StatCalendarAvgDuration implements ExportInterface, GroupedExportInterface
|
|||||||
|
|
||||||
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder
|
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder
|
||||||
{
|
{
|
||||||
|
$centers = array_map(static fn ($el) => $el['center'], $acl);
|
||||||
|
|
||||||
$qb = $this->calendarRepository->createQueryBuilder('cal');
|
$qb = $this->calendarRepository->createQueryBuilder('cal');
|
||||||
|
|
||||||
$qb->select('AVG(cal.endDate - cal.startDate) AS export_result');
|
$qb->select('AVG(cal.endDate - cal.startDate) AS export_result');
|
||||||
$qb->join('cal.accompanyingPeriod', 'acp');
|
$qb->join('cal.accompanyingPeriod', 'acp');
|
||||||
|
|
||||||
|
if ($this->filterStatsByCenters) {
|
||||||
|
$qb
|
||||||
|
->andWhere(
|
||||||
|
$qb->expr()->exists(
|
||||||
|
'SELECT 1 FROM '.AccompanyingPeriodParticipation::class.' acl_count_part
|
||||||
|
JOIN '.PersonCenterHistory::class.' acl_count_person_history WITH IDENTITY(acl_count_person_history.person) = IDENTITY(acl_count_part.person)
|
||||||
|
WHERE acl_count_part.accompanyingPeriod = acp.id AND acl_count_person_history.center IN (:authorized_centers)
|
||||||
|
'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
->setParameter('authorized_centers', $centers);
|
||||||
|
}
|
||||||
|
|
||||||
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);
|
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);
|
||||||
|
|
||||||
return $qb;
|
return $qb;
|
||||||
|
@ -17,14 +17,24 @@ use Chill\MainBundle\Export\AccompanyingCourseExportHelper;
|
|||||||
use Chill\MainBundle\Export\ExportInterface;
|
use Chill\MainBundle\Export\ExportInterface;
|
||||||
use Chill\MainBundle\Export\FormatterInterface;
|
use Chill\MainBundle\Export\FormatterInterface;
|
||||||
use Chill\MainBundle\Export\GroupedExportInterface;
|
use Chill\MainBundle\Export\GroupedExportInterface;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||||
|
use Chill\PersonBundle\Entity\Person\PersonCenterHistory;
|
||||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||||
use Doctrine\ORM\Query;
|
use Doctrine\ORM\Query;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
|
||||||
class StatCalendarSumDuration implements ExportInterface, GroupedExportInterface
|
class StatCalendarSumDuration implements ExportInterface, GroupedExportInterface
|
||||||
{
|
{
|
||||||
public function __construct(private readonly CalendarRepository $calendarRepository) {}
|
private readonly bool $filterStatsByCenters;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private readonly CalendarRepository $calendarRepository,
|
||||||
|
ParameterBagInterface $parameterBag,
|
||||||
|
) {
|
||||||
|
$this->filterStatsByCenters = $parameterBag->get('chill_main')['acl']['filter_stats_by_center'];
|
||||||
|
}
|
||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder): void
|
public function buildForm(FormBuilderInterface $builder): void
|
||||||
{
|
{
|
||||||
@ -85,11 +95,26 @@ class StatCalendarSumDuration implements ExportInterface, GroupedExportInterface
|
|||||||
|
|
||||||
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder
|
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder
|
||||||
{
|
{
|
||||||
|
$centers = array_map(static fn ($el) => $el['center'], $acl);
|
||||||
|
|
||||||
$qb = $this->calendarRepository->createQueryBuilder('cal');
|
$qb = $this->calendarRepository->createQueryBuilder('cal');
|
||||||
|
|
||||||
$qb->select('SUM(cal.endDate - cal.startDate) AS export_result');
|
$qb->select('SUM(cal.endDate - cal.startDate) AS export_result');
|
||||||
$qb->join('cal.accompanyingPeriod', 'acp');
|
$qb->join('cal.accompanyingPeriod', 'acp');
|
||||||
|
|
||||||
|
if ($this->filterStatsByCenters) {
|
||||||
|
$qb
|
||||||
|
->andWhere(
|
||||||
|
$qb->expr()->exists(
|
||||||
|
'SELECT 1 FROM '.AccompanyingPeriodParticipation::class.' acl_count_part
|
||||||
|
JOIN '.PersonCenterHistory::class.' acl_count_person_history WITH IDENTITY(acl_count_person_history.person) = IDENTITY(acl_count_part.person)
|
||||||
|
WHERE acl_count_part.accompanyingPeriod = acp.id AND acl_count_person_history.center IN (:authorized_centers)
|
||||||
|
'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
->setParameter('authorized_centers', $centers);
|
||||||
|
}
|
||||||
|
|
||||||
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);
|
AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb);
|
||||||
|
|
||||||
return $qb;
|
return $qb;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user