exports: add a new GeographicalUnitStat aggregator

This commit is contained in:
2022-08-08 15:24:22 +02:00
parent eedfa60bea
commit 29cc589bf2
3 changed files with 105 additions and 0 deletions

View File

@@ -0,0 +1,96 @@
<?php
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
final class GeographicalUnitStatAggregator implements AggregatorInterface
{
/*
private EntityRepository $repository;
public function __construct(
EntityManagerInterface $em
) {
$this->repository = $em->getRepository(...::class);
}
*/
/**
* @inheritDoc
*/
public function getLabels($key, array $values, $data)
{
return function ($value): string {
if ('_header' === $value) {
return 'Geographical unit';
}
$g = $this->repository->find($value);
return $g; //...
};
}
/**
* @inheritDoc
*/
public function getQueryKeys($data): array
{
return ['geographicalunitstat_aggregator'];
}
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder)
{
// TODO: Implement buildForm() method.
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return 'Group by geographical unit';
}
/**
* @inheritDoc
*/
public function addRole()
{
return null;
}
/**
* @inheritDoc
*/
public function alterQuery(QueryBuilder $qb, $data)
{
//$qb->addSelect('... AS geographicalunitstat_aggregator');
$groupby = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('geographicalunitstat_aggregator');
} else {
$qb->groupBy('geographicalunitstat_aggregator');
}
}
/**
* @inheritDoc
*/
public function applyOn(): string
{
return Declarations::ACP_TYPE;
}
}