Fixed: [export][activity] use createdBy property instead of user for

grouping or filtering by creator
This commit is contained in:
2022-10-14 21:43:30 +02:00
parent cd3fc99b9a
commit c07cd2b715
9 changed files with 41 additions and 60 deletions

View File

@@ -13,20 +13,19 @@ namespace Chill\ActivityBundle\Export\Aggregator\ACPAggregators;
use Chill\ActivityBundle\Export\Declarations;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Repository\UserRepository;
use Chill\MainBundle\Repository\UserRepositoryInterface;
use Chill\MainBundle\Templating\Entity\UserRender;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
class ByUserAggregator implements AggregatorInterface
class ByCreatorAggregator implements AggregatorInterface
{
private UserRender $userRender;
private UserRepository $userRepository;
private UserRepositoryInterface $userRepository;
public function __construct(
UserRepository $userRepository,
UserRepositoryInterface $userRepository,
UserRender $userRender
) {
$this->userRepository = $userRepository;
@@ -40,12 +39,8 @@ class ByUserAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('actusers', $qb->getAllAliases(), true)) {
$qb->leftJoin('activity.users', 'actusers');
}
$qb->addSelect('actusers.id AS users_aggregator');
$qb->addGroupBy('users_aggregator');
$qb->addSelect('IDENTITY(activity.createdBy) AS creator_aggregator');
$qb->addGroupBy('creator_aggregator');
}
public function applyOn(): string
@@ -62,7 +57,7 @@ class ByUserAggregator implements AggregatorInterface
{
return function ($value): string {
if ('_header' === $value) {
return 'Accepted users';
return 'Created by';
}
if (null === $value) {
@@ -77,11 +72,11 @@ class ByUserAggregator implements AggregatorInterface
public function getQueryKeys($data): array
{
return ['users_aggregator'];
return ['creator_aggregator'];
}
public function getTitle(): string
{
return 'Group activity by linked users';
return 'Group activity by creator';
}
}

View File

@@ -19,7 +19,7 @@ use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
class UserScopeAggregator implements AggregatorInterface
class CreatorScopeAggregator implements AggregatorInterface
{
private ScopeRepository $scopeRepository;
@@ -40,12 +40,12 @@ class UserScopeAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
if (!in_array('actuser', $qb->getAllAliases(), true)) {
$qb->leftJoin('activity.user', 'actuser');
if (!in_array('actcreator', $qb->getAllAliases(), true)) {
$qb->leftJoin('activity.createdBy', 'actcreator');
}
$qb->addSelect('IDENTITY(actuser.mainScope) AS userscope_aggregator');
$qb->addGroupBy('userscope_aggregator');
$qb->addSelect('IDENTITY(actcreator.mainScope) AS creatorscope_aggregator');
$qb->addGroupBy('creatorscope_aggregator');
}
public function applyOn(): string
@@ -79,11 +79,11 @@ class UserScopeAggregator implements AggregatorInterface
public function getQueryKeys($data): array
{
return ['userscope_aggregator'];
return ['creatorscope_aggregator'];
}
public function getTitle(): string
{
return 'Group activity by userscope';
return 'Group activity by creator scope';
}
}

View File

@@ -15,12 +15,10 @@ use Chill\ActivityBundle\Export\Declarations;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\PickUserDynamicType;
use Chill\MainBundle\Templating\Entity\UserRender;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
class ByUserFilter implements FilterInterface
class ByCreatorFilter implements FilterInterface
{
private UserRender $userRender;
@@ -36,22 +34,11 @@ class ByUserFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$where = $qb->getDQLPart('where');
if (!in_array('actusers', $qb->getAllAliases(), true)) {
$qb->join('activity.users', 'actusers');
}
$clause = $qb->expr()->in('actusers.id', ':users');
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter('users', $data['accepted_users']);
$qb
->andWhere(
$qb->expr()->in('activity.createdBy', ':users')
)
->setParameter('users', $data['accepted_users']);
}
public function applyOn(): string
@@ -74,13 +61,13 @@ class ByUserFilter implements FilterInterface
$users[] = $this->userRender->renderString($u, []);
}
return ['Filtered activity by linked users: only %users%', [
return ['Filtered activity by creator: only %users%', [
'%users%' => implode(', ou ', $users),
]];
}
public function getTitle(): string
{
return 'Filter activity by linked users';
return 'Filter activity by creator';
}
}