Features: apply all the filters and aggregators concerning person on accompanying courses

This commit is contained in:
2022-11-09 16:20:24 +01:00
parent c1df8084a6
commit 826a975fbe
3 changed files with 51 additions and 23 deletions

View File

@@ -101,7 +101,7 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface
->andWhere('acp.step != :count_acp_step')
->leftJoin('acp.participations', 'acppart')
->leftJoin('acppart.person', 'person')
->andWhere('acppart.startDate != acppart.endDate')
->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL')
->andWhere(
$qb->expr()->exists(
'SELECT 1 FROM ' . PersonCenterHistory::class . ' acl_count_person_history WHERE acl_count_person_history.person = person

View File

@@ -16,7 +16,6 @@ use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
use Chill\PersonBundle\Entity\Person\PersonCenterHistory;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
@@ -53,7 +52,7 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn
public function getDescription(): string
{
return 'Create an average of accompanying courses duration according to various filters';
return 'Create an average of accompanying courses duration of each person participation to accompanying course, according to filters on persons, accompanying course';
}
public function getGroup(): string
@@ -63,21 +62,37 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn
public function getLabels($key, array $values, $data)
{
if ('export_result' !== $key) {
throw new LogicException("the key {$key} is not used by this export");
}
return static function ($value) use ($key) {
if ('_header' === $value) {
switch ($key) {
case 'avg_export_result':
return 'export.export.acp_stats.avg_duration';
$labels = array_combine($values, $values);
$labels['_header'] = $this->getTitle();
case 'count_acppart_export_result':
return 'export.export.acp_stats.count_participations';
return static function ($value) use ($labels) {
return $labels[$value];
case 'count_acp_export_result':
return 'export.export.acp_stats.count_acps';
case 'count_pers_export_result':
return 'export.export.acp_stats.count_persons';
default:
throw new LogicException('key not supported: ' . $key);
}
}
if (null === $value) {
return '';
}
return $value;
};
}
public function getQueryKeys($data): array
{
return ['export_result'];
return ['avg_export_result', 'count_acp_export_result', 'count_acppart_export_result', 'count_pers_export_result'];
}
public function getResult($query, $data)
@@ -87,7 +102,7 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn
public function getTitle(): string
{
return 'Accompanying courses duration';
return 'Accompanying courses participation duration and number of participations';
}
public function getType(): string
@@ -104,22 +119,28 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn
$qb = $this->repository->createQueryBuilder('acp');
$qb
->select('AVG(
LEAST(acppart.endDate, COALESCE(acp.closingDate, :force_closingDate))
- GREATEST(acppart.startDate, COALESCE(acp.openingDate, :force_closingDate))
) AS avg_export_result')
->addSelect('COUNT(DISTINCT acppart.id) AS count_acppart_export_result')
->addSelect('COUNT(DISTINCT person.id) AS count_pers_export_result')
->addSelect('COUNT(DISTINCT acp.id) AS count_acp_export_result')
->setParameter('force_closingDate', $data['closingdate'])
->leftJoin('acp.participations', 'acppart')
->leftJoin('acppart.person', 'person')
->andWhere('acp.step != :count_acp_step')
->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL')
->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)
'SELECT 1 FROM ' . PersonCenterHistory::class . ' acl_count_person_history WHERE acl_count_person_history.person = person
AND acl_count_person_history.center IN (:authorized_centers)
'
)
)
->setParameter('count_acp_step', AccompanyingPeriod::STEP_DRAFT)
->setParameter('authorized_centers', $centers);
$qb
->select('AVG(
COALESCE(acp.closingDate, :force_closingDate) - acp.openingDate
) AS export_result')
->setParameter('force_closingDate', $data['closingdate']);
return $qb;
}
@@ -132,6 +153,7 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn
{
return [
Declarations::ACP_TYPE,
Declarations::PERSON_TYPE,
];
}
}