mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
fix: Let Symfony inject dependencies automatically.
This commit is contained in:
@@ -1,51 +1,26 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2019 Champs Libres Cooperative <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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 Doctrine\ORM\Query\Expr\Join;
|
||||
use Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class ActivityUserAggregator implements AggregatorInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
protected $em;
|
||||
|
||||
const KEY = 'activity_user_id';
|
||||
|
||||
function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
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);
|
||||
@@ -53,9 +28,9 @@ class ActivityUserAggregator implements AggregatorInterface
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
// add select element
|
||||
// add select element
|
||||
$qb->addSelect(sprintf('IDENTITY(activity.user) AS %s', self::KEY));
|
||||
|
||||
|
||||
// add the "group by" part
|
||||
$qb->addGroupBy(self::KEY);
|
||||
}
|
||||
@@ -73,17 +48,14 @@ class ActivityUserAggregator implements AggregatorInterface
|
||||
public function getLabels($key, $values, $data): \Closure
|
||||
{
|
||||
// preload users at once
|
||||
$this->em->getRepository(User::class)
|
||||
->findBy(['id' => $values]);
|
||||
|
||||
$this->userRepository->findBy(['id' => $values]);
|
||||
|
||||
return function($value) {
|
||||
switch ($value) {
|
||||
case '_header':
|
||||
return 'activity user';
|
||||
default:
|
||||
return $this->em->getRepository(User::class)->find($value)
|
||||
->getUsername();
|
||||
if ($value === '_header') {
|
||||
return 'activity user';
|
||||
}
|
||||
|
||||
return $this->userRepository->find($value)->getUsername();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -94,6 +66,6 @@ class ActivityUserAggregator implements AggregatorInterface
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return "Aggregate by activity user";
|
||||
return 'Aggregate by activity user';
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user