mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Add ByDateAggregator to AccompanyingPeriodStepHistoryAggregators
Implemented a new ByDateAggregator in the AccompanyingPeriodStepHistoryAggregators for grouping status changes by date. A corresponding test suite has been included to verify its function. Necessary translations have also been updated.
This commit is contained in:
parent
01785ed494
commit
bf97b2a50c
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingPeriodStepHistoryAggregators;
|
||||
|
||||
use Chill\MainBundle\Export\AggregatorInterface;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Chill\PersonBundle\Export\Enum\DateGroupingChoiceEnum;
|
||||
use Chill\PersonBundle\Tests\Export\Aggregator\AccompanyingPeriodStepHistoryAggregators\ByDateAggregatorTest;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
* @see ByDateAggregatorTest
|
||||
*/
|
||||
final readonly class ByDateAggregator implements AggregatorInterface
|
||||
{
|
||||
private const KEY = 'acpstephistory_by_date_agg';
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('frequency', ChoiceType::class, [
|
||||
'choices' => array_combine(
|
||||
array_map(fn (DateGroupingChoiceEnum $c) => 'export.enum.frequency.'.$c->value, DateGroupingChoiceEnum::cases()),
|
||||
array_map(fn (DateGroupingChoiceEnum $c) => $c->value, DateGroupingChoiceEnum::cases()),
|
||||
),
|
||||
'label' => 'export.aggregator.course.by_opening_date.frequency',
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return ['frequency' => DateGroupingChoiceEnum::YEAR->value];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, mixed $data)
|
||||
{
|
||||
return function (?string $value): string {
|
||||
if ('_header' === $value) {
|
||||
return 'export.aggregator.step_history.by_date.header';
|
||||
}
|
||||
|
||||
if (null === $value || '' === $value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $value;
|
||||
};
|
||||
}
|
||||
|
||||
public function getQueryKeys($data)
|
||||
{
|
||||
return [self::KEY];
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return 'export.aggregator.step_history.by_date.title';
|
||||
}
|
||||
|
||||
public function addRole(): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
$p = self::KEY;
|
||||
|
||||
$qb->addSelect(sprintf("TO_CHAR(acpstephistory.startDate, '%s') AS {$p}", $data['frequency']));
|
||||
$qb->addGroupBy($p);
|
||||
$qb->addOrderBy($p, 'DESC');
|
||||
}
|
||||
|
||||
public function applyOn()
|
||||
{
|
||||
return Declarations::ACP_STEP_HISTORY;
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\Tests\Export\Aggregator\AccompanyingPeriodStepHistoryAggregators;
|
||||
|
||||
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodStepHistory;
|
||||
use Chill\PersonBundle\Export\Enum\DateGroupingChoiceEnum;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Chill\PersonBundle\Export\Aggregator\AccompanyingPeriodStepHistoryAggregators\ByDateAggregator;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @coversNothing
|
||||
*/
|
||||
class ByDateAggregatorTest extends AbstractAggregatorTest
|
||||
{
|
||||
public function getAggregator()
|
||||
{
|
||||
return new ByDateAggregator();
|
||||
}
|
||||
|
||||
public function getFormData()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'frequency' => DateGroupingChoiceEnum::YEAR->value,
|
||||
],
|
||||
[
|
||||
'frequency' => DateGroupingChoiceEnum::WEEK->value,
|
||||
],
|
||||
[
|
||||
'frequency' => DateGroupingChoiceEnum::MONTH->value,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function getQueryBuilders()
|
||||
{
|
||||
self::bootKernel();
|
||||
$em = self::$container->get(EntityManagerInterface::class);
|
||||
|
||||
$qb = $em->createQueryBuilder()
|
||||
->select('COUNT(DISTINCT acpstephistory.id) As export_result')
|
||||
->from(AccompanyingPeriodStepHistory::class, 'acpstephistory')
|
||||
->join('acpstephistory.period', 'acp');
|
||||
|
||||
return [
|
||||
$qb,
|
||||
];
|
||||
}
|
||||
}
|
@ -1046,7 +1046,10 @@ export:
|
||||
by_step:
|
||||
title: Grouper les changements de statut du parcours par étape
|
||||
header: Nouveau statut du parcours
|
||||
|
||||
by_date:
|
||||
title: Grouper les changement de statut du parcours par date
|
||||
header: Date du changement de statut du parcours
|
||||
date_grouping_label: Grouper par
|
||||
course:
|
||||
by-user:
|
||||
title: Grouper les parcours par usager participant
|
||||
|
Loading…
x
Reference in New Issue
Block a user