mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-29 05:26:13 +00:00
[export] fix acpw socialWork agent ScopeAggregator query + unit test
This commit is contained in:
parent
7c25ca8dd4
commit
0953faedc4
@ -11,17 +11,28 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators;
|
namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\User\UserScopeHistory;
|
||||||
use Chill\MainBundle\Export\AggregatorInterface;
|
use Chill\MainBundle\Export\AggregatorInterface;
|
||||||
|
use Chill\MainBundle\Form\Type\PickRollingDateType;
|
||||||
use Chill\MainBundle\Repository\ScopeRepository;
|
use Chill\MainBundle\Repository\ScopeRepository;
|
||||||
|
use Chill\MainBundle\Service\RollingDate\RollingDate;
|
||||||
|
use Chill\MainBundle\Service\RollingDate\RollingDateConverter;
|
||||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||||
use Chill\PersonBundle\Export\Declarations;
|
use Chill\PersonBundle\Export\Declarations;
|
||||||
|
use Doctrine\ORM\Query\Expr;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use function in_array;
|
use function in_array;
|
||||||
|
|
||||||
final readonly class ScopeAggregator implements AggregatorInterface
|
final readonly class ScopeAggregator implements AggregatorInterface
|
||||||
{
|
{
|
||||||
public function __construct(private ScopeRepository $scopeRepository, private TranslatableStringHelper $translatableStringHelper) {}
|
private const PREFIX = 'acp_work_action_agg_user_scope';
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private RollingDateConverter $rollingDateConverter,
|
||||||
|
private ScopeRepository $scopeRepository,
|
||||||
|
private TranslatableStringHelper $translatableStringHelper
|
||||||
|
) {}
|
||||||
|
|
||||||
public function addRole(): ?string
|
public function addRole(): ?string
|
||||||
{
|
{
|
||||||
@ -30,12 +41,31 @@ final readonly class ScopeAggregator implements AggregatorInterface
|
|||||||
|
|
||||||
public function alterQuery(QueryBuilder $qb, $data)
|
public function alterQuery(QueryBuilder $qb, $data)
|
||||||
{
|
{
|
||||||
if (!in_array('acpwuser', $qb->getAllAliases(), true)) {
|
$p = self::PREFIX;
|
||||||
$qb->leftJoin('acpw.referrers', 'acpwuser');
|
|
||||||
}
|
|
||||||
|
|
||||||
$qb->addSelect('IDENTITY(acpwuser.mainScope) as scope_aggregator');
|
$qb
|
||||||
$qb->addGroupBy('scope_aggregator');
|
->leftJoin("acpw.referrers", "{$p}_user")
|
||||||
|
->leftJoin(
|
||||||
|
UserScopeHistory::class,
|
||||||
|
"{$p}_history",
|
||||||
|
Expr\Join::WITH,
|
||||||
|
$qb->expr()->eq("{$p}_history.user", "{$p}_user")
|
||||||
|
)
|
||||||
|
->andWhere(
|
||||||
|
$qb->expr()->andX(
|
||||||
|
$qb->expr()->lte("{$p}_history.startDate", ":{$p}_at"),
|
||||||
|
$qb->expr()->orX(
|
||||||
|
$qb->expr()->isNull("{$p}_history.endDate"),
|
||||||
|
$qb->expr()->gt("{$p}_history.endDate", ":{$p}_at")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
->addSelect("IDENTITY({$p}_history.scope) as {$p}_select")
|
||||||
|
->setParameter(
|
||||||
|
"{$p}_at",
|
||||||
|
$this->rollingDateConverter->convert($data['scope_at'])
|
||||||
|
)
|
||||||
|
->addGroupBy("{$p}_select");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applyOn(): string
|
public function applyOn(): string
|
||||||
@ -45,11 +75,14 @@ final readonly class ScopeAggregator implements AggregatorInterface
|
|||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder)
|
public function buildForm(FormBuilderInterface $builder)
|
||||||
{
|
{
|
||||||
// no form
|
$builder->add('scope_at', PickRollingDateType::class, [
|
||||||
|
'label' => 'export.acpw.agent_scope.Calc date',
|
||||||
|
'required' => true,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
public function getFormDefaultData(): array
|
public function getFormDefaultData(): array
|
||||||
{
|
{
|
||||||
return [];
|
return ['scope_at' => new RollingDate(RollingDate::T_TODAY)];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLabels($key, array $values, $data)
|
public function getLabels($key, array $values, $data)
|
||||||
@ -63,7 +96,9 @@ final readonly class ScopeAggregator implements AggregatorInterface
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$s = $this->scopeRepository->find($value);
|
if (null === $s = $this->scopeRepository->find($value)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
return $this->translatableStringHelper->localize(
|
return $this->translatableStringHelper->localize(
|
||||||
$s->getName()
|
$s->getName()
|
||||||
@ -73,11 +108,11 @@ final readonly class ScopeAggregator implements AggregatorInterface
|
|||||||
|
|
||||||
public function getQueryKeys($data): array
|
public function getQueryKeys($data): array
|
||||||
{
|
{
|
||||||
return ['scope_aggregator'];
|
return [self::PREFIX . '_select'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTitle(): string
|
public function getTitle(): string
|
||||||
{
|
{
|
||||||
return 'Group by treating agent scope';
|
return 'export.acpw.agent_scope.Group by treating agent scope';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Tests\Export\Aggregator\SocialWorkAggregators;
|
namespace Chill\PersonBundle\Tests\Export\Aggregator\SocialWorkAggregators;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Service\RollingDate\RollingDate;
|
||||||
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
|
use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||||
use Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\ScopeAggregator;
|
use Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\ScopeAggregator;
|
||||||
@ -39,7 +40,9 @@ final class ScopeAggregatorTest extends AbstractAggregatorTest
|
|||||||
public function getFormData(): array
|
public function getFormData(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[],
|
[
|
||||||
|
'scope_at' => new RollingDate(RollingDate::T_FIXED_DATE, \DateTimeImmutable::createFromFormat('Y-m-d', '2020-01-01')),
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,7 +598,6 @@ Filter by current evaluations: Filtrer les évaluations en cours
|
|||||||
## social actions filters/aggr
|
## social actions filters/aggr
|
||||||
Filter by treating agent scope: Filtrer les actions par service de l'agent traitant
|
Filter by treating agent scope: Filtrer les actions par service de l'agent traitant
|
||||||
"Filtered by treating agent scope: only %scopes%": "Filtré par service de l'agent traitant: uniquement %scopes%"
|
"Filtered by treating agent scope: only %scopes%": "Filtré par service de l'agent traitant: uniquement %scopes%"
|
||||||
Group by treating agent scope: Grouper les actions par service de l'agent traitant
|
|
||||||
|
|
||||||
Filter by scope: Filtrer par service
|
Filter by scope: Filtrer par service
|
||||||
|
|
||||||
@ -1007,6 +1006,9 @@ export:
|
|||||||
agent_job:
|
agent_job:
|
||||||
Group by treating agent job: Grouper les actions par métier de l'agent traitant
|
Group by treating agent job: Grouper les actions par métier de l'agent traitant
|
||||||
Calc date: Date de calcul du métier de l'agent traitant
|
Calc date: Date de calcul du métier de l'agent traitant
|
||||||
|
agent_scope:
|
||||||
|
Group by treating agent scope: Grouper les actions par service de l'agent traitant
|
||||||
|
Calc date: Date de calcul du service de l'agent traitant
|
||||||
export:
|
export:
|
||||||
acp_stats:
|
acp_stats:
|
||||||
avg_duration: Moyenne de la durée de participation de chaque usager concerné
|
avg_duration: Moyenne de la durée de participation de chaque usager concerné
|
||||||
|
Loading…
x
Reference in New Issue
Block a user