Export: add grouping "group activity by person" (activites saved in person context)

This commit is contained in:
Julien Fastré 2023-11-10 14:41:58 +01:00
parent 27012d842d
commit cbc83c0e63
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
5 changed files with 136 additions and 0 deletions

View File

@ -0,0 +1,6 @@
kind: Feature
body: 'Export: add an aggregator "group activities by person" (only for the activities
saved in a person context)'
time: 2023-11-10T14:40:56.93459414+01:00
custom:
Issue: "199"

View File

@ -0,0 +1,65 @@
<?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\ActivityBundle\Export\Aggregator\PersonAggregators;
use Chill\ActivityBundle\Export\Declarations;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\PersonBundle\Export\Helper\LabelPersonHelper;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
final readonly class PersonAggregator implements AggregatorInterface
{
public function __construct(private LabelPersonHelper $labelPersonHelper) {}
public function buildForm(FormBuilderInterface $builder)
{
// nothing to add here
}
public function getFormDefaultData(): array
{
return [];
}
public function getLabels($key, array $values, mixed $data)
{
return $this->labelPersonHelper->getLabel($key, $values, 'export.aggregator.person.by_person.person');
}
public function getQueryKeys($data)
{
return ['activity_by_person_agg'];
}
public function getTitle()
{
return 'export.aggregator.person.by_person.title';
}
public function addRole(): ?string
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$qb
->addSelect('IDENTITY(activity.person) AS activity_by_person_agg')
->addGroupBy('activity_by_person_agg');
}
public function applyOn()
{
return Declarations::ACTIVITY_PERSON;
}
}

View File

@ -0,0 +1,57 @@
<?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\ActivityBundle\Tests\Export\Aggregator\PersonAggregators;
use Chill\ActivityBundle\Entity\Activity;
use Chill\ActivityBundle\Export\Aggregator\PersonAggregators\PersonAggregator;
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
use Chill\PersonBundle\Export\Helper\LabelPersonHelper;
use Doctrine\ORM\EntityManagerInterface;
/**
* @internal
*
* @coversNothing
*/
class PersonAggregatorTest extends AbstractAggregatorTest
{
private LabelPersonHelper $labelPersonHelper;
protected function setUp(): void
{
self::bootKernel();
$this->labelPersonHelper = self::$container->get(LabelPersonHelper::class);
}
public function getAggregator()
{
return new PersonAggregator($this->labelPersonHelper);
}
public function getFormData()
{
return [[]];
}
public function getQueryBuilders()
{
self::bootKernel();
$em = self::$container->get(EntityManagerInterface::class);
return [
$em->createQueryBuilder()
->select('count(activity.id)')
->from(Activity::class, 'activity'),
];
}
}

View File

@ -227,3 +227,7 @@ services:
Chill\ActivityBundle\Export\Aggregator\ActivityPresenceAggregator: Chill\ActivityBundle\Export\Aggregator\ActivityPresenceAggregator:
tags: tags:
- { name: chill.export_aggregator, alias: activity_presence_agg } - { name: chill.export_aggregator, alias: activity_presence_agg }
Chill\ActivityBundle\Export\Aggregator\PersonAggregators\PersonAggregator:
tags:
- { name: chill.export_aggregator, alias: activity_person_agg }

View File

@ -395,6 +395,10 @@ export:
'Filtered by activity presence: only %presences%': 'Filtré par présence de l''usager: seulement %presences%' 'Filtered by activity presence: only %presences%': 'Filtré par présence de l''usager: seulement %presences%'
aggregator: aggregator:
person:
by_person:
title: Grouper les échanges par usager (dossier d'usager dans lequel l'échange est enregistré)
person: Usager
acp: acp:
by_activity_type: by_activity_type:
title: Grouper les parcours par type d'échange title: Grouper les parcours par type d'échange