renaming of export to avoid confusion + start of agent traitant filter

This commit is contained in:
2022-07-26 14:43:21 +02:00
parent b12e5e78b6
commit d5d38053cd
6 changed files with 112 additions and 22 deletions

View File

@@ -22,5 +22,5 @@ abstract class Declarations
public const ACP_TYPE = 'accompanying_period';
public const SOCIAL_ACTION_TYPE = 'social_actions';
public const SOCIAL_WORK_ACTION_TYPE = 'social_actions';
}

View File

@@ -15,7 +15,7 @@ use Chill\MainBundle\Export\ExportInterface;
use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Export\GroupedExportInterface;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\SocialWork\SocialActionRepository;
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
@@ -23,23 +23,23 @@ use Symfony\Component\Form\FormBuilderInterface;
use LogicException;
use Symfony\Component\Security\Core\Role\Role;
class CountSocialActions implements ExportInterface, GroupedExportInterface
class CountSocialWorkActions implements ExportInterface, GroupedExportInterface
{
protected SocialActionRepository $socialActionRepository;
protected AccompanyingPeriodWorkRepository $socialActionRepository;
public function __construct(SocialActionRepository $socialActionRepository)
public function __construct(AccompanyingPeriodWorkRepository $socialActionRepository)
{
$this->socialActionRepository = $socialActionRepository;
}
public function buildForm(FormBuilderInterface $builder): void
{
// TODO: Implement buildForm() method.
// No form necessary?
}
public function getTitle(): string
{
return 'Count social actions';
return 'Count social work actions';
}
public function getAllowedFormattersTypes(): array
@@ -49,12 +49,12 @@ class CountSocialActions implements ExportInterface, GroupedExportInterface
public function getDescription(): string
{
return 'Count social actions by various parameters';
return 'Count social work actions by various parameters';
}
public function getLabels($key, array $values, $data)
{
if ('export_count_social_actions' !== $key) {
if ('export_count_social_work_actions' !== $key) {
throw new LogicException("the key {$key} is not used by this export");
}
@@ -68,7 +68,7 @@ class CountSocialActions implements ExportInterface, GroupedExportInterface
public function getQueryKeys($data): array
{
return ['export_count_social_actions'];
return ['export_count_social_work_actions'];
}
public function getResult($qb, $data)
@@ -78,32 +78,32 @@ class CountSocialActions implements ExportInterface, GroupedExportInterface
public function getType(): string
{
return Declarations::SOCIAL_ACTION_TYPE;
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []): QueryBuilder
{
$qb = $this
->socialActionRepository
->createQueryBuilder('sa')
->select('COUNT(sa.id) as export_count_social_actions');
->createQueryBuilder('acpw')
->select('COUNT(acpw.id) as export_count_social_work_actions');
return $qb;
}
public function requiredRole(): Role
{
//TODO change to string, but changes needed also in exportManager and possibly other locations.
//TODO change to string, but changes needed also in ExportManager and possibly other locations.
return new Role(AccompanyingPeriodVoter::STATS);
}
public function supportsModifiers(): array
{
return [Declarations::SOCIAL_ACTION_TYPE];
return [Declarations::SOCIAL_WORK_ACTION_TYPE];
}
public function getGroup(): string
{
return 'Exports of social actions';
return 'Exports of social work actions';
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace Chill\PersonBundle\Export\Filter;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Export\FilterInterface;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface;
use Chill\MainBundle\Templating\Entity\UserRender;
class ReferrerFilter implements FilterInterface
{
private UserRender $userRender;
public function __construct(UserRender $userRender)
{
$this->userRender = $userRender;
}
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('users', EntityType::class, [
'class' => User::class,
'choice_label' => function (User $u) {
$this->userRender->renderString($u, []);
},
'multiple' => true,
'expanded' => true
]);
}
public function getTitle(): string
{
return 'Filter by referrers';
}
public function describeAction($data, $format = 'string'): array
{
$users = [];
foreach ($data['users'] as $u) {
$users[] = $u->getUsername();
}
return ['Filtered by users: only %users%', [
'%user%' => implode(', ou ', $users)
]];
}
public function addRole()
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->in('acpw.referrers', ':users');
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter('users', $data['users']);
}
public function applyOn(): string
{
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
}