mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
[export] fix acp UserJobAggregator query + unit test
This commit is contained in:
parent
9db0011b2e
commit
8b7600e09f
@ -77,8 +77,8 @@ readonly class ReferrerScopeAggregator implements AggregatorInterface
|
|||||||
"{$p}_date_calc",
|
"{$p}_date_calc",
|
||||||
$this->rollingDateConverter->convert($data['date_calc'])
|
$this->rollingDateConverter->convert($data['date_calc'])
|
||||||
)
|
)
|
||||||
->addSelect("IDENTITY({$p}_scopeHistory.scope) AS {$p}_scope_name")
|
->addSelect("IDENTITY({$p}_scopeHistory.scope) AS {$p}_select")
|
||||||
->addGroupBy("{$p}_scope_name");
|
->addGroupBy("{$p}_select");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applyOn(): string
|
public function applyOn(): string
|
||||||
@ -123,7 +123,7 @@ readonly class ReferrerScopeAggregator implements AggregatorInterface
|
|||||||
|
|
||||||
public function getQueryKeys($data): array
|
public function getQueryKeys($data): array
|
||||||
{
|
{
|
||||||
return [self::PREFIX . '_scope_name'];
|
return [self::PREFIX . '_select'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTitle(): string
|
public function getTitle(): string
|
||||||
|
@ -11,17 +11,27 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
|
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\User\UserJobHistory;
|
||||||
use Chill\MainBundle\Export\AggregatorInterface;
|
use Chill\MainBundle\Export\AggregatorInterface;
|
||||||
|
use Chill\MainBundle\Form\Type\PickRollingDateType;
|
||||||
use Chill\MainBundle\Repository\UserJobRepository;
|
use Chill\MainBundle\Repository\UserJobRepository;
|
||||||
|
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;
|
|
||||||
|
|
||||||
final readonly class UserJobAggregator implements AggregatorInterface
|
final readonly class UserJobAggregator implements AggregatorInterface
|
||||||
{
|
{
|
||||||
public function __construct(private UserJobRepository $jobRepository, private TranslatableStringHelper $translatableStringHelper) {}
|
private const PREFIX = 'acp_agg_user_job';
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
private RollingDateConverter $rollingDateConverter,
|
||||||
|
private UserJobRepository $jobRepository,
|
||||||
|
private TranslatableStringHelper $translatableStringHelper
|
||||||
|
) {}
|
||||||
|
|
||||||
public function addRole(): ?string
|
public function addRole(): ?string
|
||||||
{
|
{
|
||||||
@ -30,12 +40,31 @@ final readonly class UserJobAggregator implements AggregatorInterface
|
|||||||
|
|
||||||
public function alterQuery(QueryBuilder $qb, $data)
|
public function alterQuery(QueryBuilder $qb, $data)
|
||||||
{
|
{
|
||||||
if (!in_array('acpuser', $qb->getAllAliases(), true)) {
|
$p = self::PREFIX;
|
||||||
$qb->leftJoin('acp.user', 'acpuser');
|
|
||||||
}
|
|
||||||
|
|
||||||
$qb->addSelect('IDENTITY(acpuser.userJob) AS job_aggregator');
|
$qb
|
||||||
$qb->addGroupBy('job_aggregator');
|
->leftJoin("acp.user", "{$p}_user")
|
||||||
|
->leftJoin(
|
||||||
|
UserJobHistory::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.job) AS {$p}_select")
|
||||||
|
->setParameter(
|
||||||
|
"{$p}_at",
|
||||||
|
$this->rollingDateConverter->convert($data['job_at'])
|
||||||
|
)
|
||||||
|
->addGroupBy("{$p}_select");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applyOn(): string
|
public function applyOn(): string
|
||||||
@ -45,11 +74,15 @@ final readonly class UserJobAggregator implements AggregatorInterface
|
|||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder)
|
public function buildForm(FormBuilderInterface $builder)
|
||||||
{
|
{
|
||||||
// no form
|
$builder
|
||||||
|
->add('job_at', PickRollingDateType::class, [
|
||||||
|
'label' => 'export.acp.referrer_job.Calc date',
|
||||||
|
'required' => true
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
public function getFormDefaultData(): array
|
public function getFormDefaultData(): array
|
||||||
{
|
{
|
||||||
return [];
|
return ['job_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 UserJobAggregator implements AggregatorInterface
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$j = $this->jobRepository->find($value);
|
if (null === $j = $this->jobRepository->find($value)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
return $this->translatableStringHelper->localize(
|
return $this->translatableStringHelper->localize(
|
||||||
$j->getLabel()
|
$j->getLabel()
|
||||||
@ -73,11 +108,11 @@ final readonly class UserJobAggregator implements AggregatorInterface
|
|||||||
|
|
||||||
public function getQueryKeys($data): array
|
public function getQueryKeys($data): array
|
||||||
{
|
{
|
||||||
return ['job_aggregator'];
|
return [self::PREFIX . '_select'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTitle(): string
|
public function getTitle(): string
|
||||||
{
|
{
|
||||||
return 'Group by user job';
|
return 'export.acp.referrer_job.Group by user job';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Tests\Export\Aggregator\AccompanyingCourseAggregators;
|
namespace Chill\PersonBundle\Tests\Export\Aggregator\AccompanyingCourseAggregators;
|
||||||
|
|
||||||
|
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\AccompanyingCourseAggregators\UserJobAggregator;
|
use Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\UserJobAggregator;
|
||||||
@ -39,7 +40,9 @@ final class UserJobAggregatorTest extends AbstractAggregatorTest
|
|||||||
public function getFormData(): array
|
public function getFormData(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[],
|
[
|
||||||
|
'job_at' => new RollingDate(RollingDate::T_TODAY)
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -460,12 +460,14 @@ Filtered by person having an activity between %date_from% and %date_to% with rea
|
|||||||
## accompanying course filters/aggr
|
## accompanying course filters/aggr
|
||||||
Filter by user scope: Filtrer les parcours par service du référent
|
Filter by user scope: Filtrer les parcours par service du référent
|
||||||
"Filtered by user main scope: only %scope%": "Filtré par service du référent: uniquement %scope%"
|
"Filtered by user main scope: only %scope%": "Filtré par service du référent: uniquement %scope%"
|
||||||
|
|
||||||
Group course by scope: Grouper les parcours par service
|
Group course by scope: Grouper les parcours par service
|
||||||
|
|
||||||
Filter by user job: Filtrer les parcours par métier du référent
|
Filter by user job: Filtrer les parcours par métier du référent
|
||||||
"Filtered by user job: only %job%": "Filtré par métier du référent: uniquement %job%"
|
"Filtered by user job: only %job%": "Filtré par métier du référent: uniquement %job%"
|
||||||
Group by user job: Grouper les parcours par métier du référent
|
|
||||||
|
export.acp.referrer_job:
|
||||||
|
Group by user job: Grouper les parcours par métier du référent
|
||||||
|
Calc date: Date de calcul du métier du référent
|
||||||
|
|
||||||
Filter by social issue: Filtrer les parcours par problématiques sociales
|
Filter by social issue: Filtrer les parcours par problématiques sociales
|
||||||
Accepted socialissues: Problématiques sociales
|
Accepted socialissues: Problématiques sociales
|
||||||
|
Loading…
x
Reference in New Issue
Block a user