Feature: [export][work] Group by current action

This commit is contained in:
2022-11-02 14:55:12 +01:00
parent cda25d3459
commit 63d38e35f7
3 changed files with 26 additions and 11 deletions

View File

@@ -16,19 +16,27 @@ use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\QueryBuilder;
use LogicException;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class CurrentActionAggregator implements AggregatorInterface
{
private TranslatorInterface $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
public function addRole(): ?string
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
public function alterQuery(QueryBuilder $qb, $data): void
{
$qb
->addSelect('
(CASE true WHEN acpw.startDate IS NULL ELSE false END)
(CASE WHEN acpw.endDate IS NULL THEN true ELSE false END)
AS acpw_current_action_aggregator
')
->addGroupBy('acpw_current_action_aggregator');
@@ -39,24 +47,24 @@ class CurrentActionAggregator implements AggregatorInterface
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
public function buildForm(FormBuilderInterface $builder): void
{
// No form needed
}
public function getLabels($key, array $values, $data)
{
return static function ($value): string {
return function ($value): string {
if ('_header' === $value) {
return '';
return 'export.aggregator.course_work.by_current_action.Current action ?';
}
switch ($value) {
case true:
return 'Current action';
return $this->translator->trans('export.aggregator.course_work.by_current_action.Current action');
case false:
return 'Not current action';
return $this->translator->trans('export.aggregator.course_work.by_current_action.Not current action');
default:
throw new LogicException(sprintf('The value %s is not valid', $value));
@@ -71,6 +79,6 @@ class CurrentActionAggregator implements AggregatorInterface
public function getTitle(): string
{
return 'Group by current actions';
return 'export.aggregator.course_work.by_current_action.Group by current actions';
}
}