mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 15:43:51 +00:00
Feature: [export][activity] Add an aggregator to group by sent / received
This commit is contained in:
@@ -16,15 +16,27 @@ use Chill\MainBundle\Export\AggregatorInterface;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use LogicException;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class SentReceivedAggregator implements AggregatorInterface
|
||||
{
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
/**
|
||||
* @param 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('activity.sentReceived AS activity_sentreceived_aggregator')
|
||||
->addGroupBy('activity_sentreceived_aggregator');
|
||||
@@ -35,16 +47,16 @@ class SentReceivedAggregator implements AggregatorInterface
|
||||
return Declarations::ACTIVITY;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
public function buildForm(FormBuilderInterface $builder): void
|
||||
{
|
||||
// No form needed
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data)
|
||||
public function getLabels($key, array $values, $data): callable
|
||||
{
|
||||
return static function ($value): string {
|
||||
return function (?string $value): string {
|
||||
if ('_header' === $value) {
|
||||
return '';
|
||||
return 'export.aggregator.activity.by_sent_received.Sent or received';
|
||||
}
|
||||
|
||||
switch ($value) {
|
||||
@@ -52,10 +64,10 @@ class SentReceivedAggregator implements AggregatorInterface
|
||||
return '';
|
||||
|
||||
case 'sent':
|
||||
return 'is sent';
|
||||
return $this->translator->trans('export.aggregator.activity.by_sent_received.is sent');
|
||||
|
||||
case 'received':
|
||||
return 'is received';
|
||||
return $this->translator->trans('export.aggregator.activity.by_sent_received.is received');
|
||||
|
||||
default:
|
||||
throw new LogicException(sprintf('The value %s is not valid', $value));
|
||||
@@ -70,6 +82,6 @@ class SentReceivedAggregator implements AggregatorInterface
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Group activity by sentreceived';
|
||||
return 'export.aggregator.activity.by_sent_received.Group activity by sentreceived';
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user