mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-20 05:35:00 +00:00
80 lines
1.9 KiB
PHP
80 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Chill\CalendarBundle\Export\Aggregator;
|
|
|
|
use Chill\CalendarBundle\Export\Declarations;
|
|
use Chill\MainBundle\Export\AggregatorInterface;
|
|
use Chill\MainBundle\Repository\ScopeRepository;
|
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
|
use Doctrine\ORM\QueryBuilder;
|
|
use Symfony\Component\Form\FormBuilderInterface;
|
|
|
|
final class ScopeAggregator implements AggregatorInterface
|
|
{
|
|
private ScopeRepository $scopeRepository;
|
|
|
|
private TranslatableStringHelper $translatableStringHelper;
|
|
|
|
public function __construct(
|
|
ScopeRepository $scopeRepository,
|
|
TranslatableStringHelper $translatableStringHelper
|
|
) {
|
|
$this->scopeRepository = $scopeRepository;
|
|
$this->translatableStringHelper = $translatableStringHelper;
|
|
}
|
|
|
|
public function getLabels($key, array $values, $data): \Closure
|
|
{
|
|
return function ($value): string {
|
|
if ($value === '_header') {
|
|
return 'Scope';
|
|
}
|
|
|
|
$s = $this->scopeRepository->find($value);
|
|
|
|
return $this->translatableStringHelper->localize(
|
|
$s->getName()
|
|
);
|
|
};
|
|
}
|
|
|
|
public function getQueryKeys($data): array
|
|
{
|
|
return ['scope_aggregator'];
|
|
}
|
|
|
|
public function buildForm(FormBuilderInterface $builder)
|
|
{
|
|
// no form
|
|
}
|
|
|
|
public function getTitle(): string
|
|
{
|
|
return 'Group by agent scope';
|
|
}
|
|
|
|
public function addRole()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public function alterQuery(QueryBuilder $qb, $data)
|
|
{
|
|
$qb->join('cal.user', 'u');
|
|
|
|
$qb->addSelect('IDENTITY(u.mainScope) as scope_aggregator');
|
|
|
|
$groupBy = $qb->getDQLPart('groupBy');
|
|
|
|
if (!empty($groupBy)) {
|
|
$qb->addGroupBy('scope_aggregator');
|
|
} else {
|
|
$qb->groupBy('scope_aggregator');
|
|
}
|
|
}
|
|
|
|
public function applyOn(): string
|
|
{
|
|
return Declarations::CALENDAR_TYPE;
|
|
}
|
|
} |