mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
72 lines
1.7 KiB
PHP
72 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Chill\ActivityBundle\Export\Aggregator;
|
|
|
|
use Chill\MainBundle\Repository\UserRepository;
|
|
use Symfony\Component\Form\FormBuilderInterface;
|
|
use Doctrine\ORM\QueryBuilder;
|
|
use Chill\MainBundle\Export\AggregatorInterface;
|
|
use Symfony\Component\Security\Core\Role\Role;
|
|
use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter;
|
|
|
|
class ActivityUserAggregator implements AggregatorInterface
|
|
{
|
|
public const KEY = 'activity_user_id';
|
|
|
|
private UserRepository $userRepository;
|
|
|
|
public function __construct(
|
|
UserRepository $userRepository
|
|
) {
|
|
$this->userRepository = $userRepository;
|
|
}
|
|
|
|
public function addRole()
|
|
{
|
|
return new Role(ActivityStatsVoter::STATS);
|
|
}
|
|
|
|
public function alterQuery(QueryBuilder $qb, $data)
|
|
{
|
|
// add select element
|
|
$qb->addSelect(sprintf('IDENTITY(activity.user) AS %s', self::KEY));
|
|
|
|
// add the "group by" part
|
|
$qb->addGroupBy(self::KEY);
|
|
}
|
|
|
|
public function applyOn(): string
|
|
{
|
|
return 'activity';
|
|
}
|
|
|
|
public function buildForm(FormBuilderInterface $builder)
|
|
{
|
|
// nothing to add
|
|
}
|
|
|
|
public function getLabels($key, $values, $data): \Closure
|
|
{
|
|
// preload users at once
|
|
$this->userRepository->findBy(['id' => $values]);
|
|
|
|
return function($value) {
|
|
if ($value === '_header') {
|
|
return 'activity user';
|
|
}
|
|
|
|
return $this->userRepository->find($value)->getUsername();
|
|
};
|
|
}
|
|
|
|
public function getQueryKeys($data)
|
|
{
|
|
return [ self::KEY ];
|
|
}
|
|
|
|
public function getTitle(): string
|
|
{
|
|
return 'Aggregate by activity user';
|
|
}
|
|
}
|