mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
[export] fix acp user Scope Filter query + unit test (partial)
This commit is contained in:
parent
f225a83a3e
commit
9b272e9b9e
@ -12,7 +12,7 @@ declare(strict_types=1);
|
|||||||
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
|
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
|
||||||
|
|
||||||
use Chill\MainBundle\Entity\Scope;
|
use Chill\MainBundle\Entity\Scope;
|
||||||
use Chill\MainBundle\Entity\User;
|
use Chill\MainBundle\Entity\User\UserScopeHistory;
|
||||||
use Chill\MainBundle\Export\FilterInterface;
|
use Chill\MainBundle\Export\FilterInterface;
|
||||||
use Chill\MainBundle\Form\Type\PickRollingDateType;
|
use Chill\MainBundle\Form\Type\PickRollingDateType;
|
||||||
use Chill\MainBundle\Repository\ScopeRepositoryInterface;
|
use Chill\MainBundle\Repository\ScopeRepositoryInterface;
|
||||||
@ -20,22 +20,20 @@ use Chill\MainBundle\Service\RollingDate\RollingDate;
|
|||||||
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
|
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
|
||||||
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\Bridge\Doctrine\Form\Type\EntityType;
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\Security\Core\Security;
|
|
||||||
|
|
||||||
class UserScopeFilter implements FilterInterface
|
class UserScopeFilter implements FilterInterface
|
||||||
{
|
{
|
||||||
private const A = 'acp_uscope_filter_uhistory';
|
private const PREFIX = 'acp_filter_main_scope';
|
||||||
|
|
||||||
private const AU = 'acp_uscope_filter_uhistory_user';
|
public function __construct(
|
||||||
|
private readonly ScopeRepositoryInterface $scopeRepository,
|
||||||
private const P = 'acp_uscope_filter_date';
|
private readonly TranslatableStringHelper $translatableStringHelper,
|
||||||
|
private readonly RollingDateConverterInterface $rollingDateConverter
|
||||||
private const PS = 'acp_uscope_filter_scopes';
|
) {}
|
||||||
|
|
||||||
public function __construct(private readonly ScopeRepositoryInterface $scopeRepository, private readonly Security $security, private readonly TranslatableStringHelper $translatableStringHelper, private readonly RollingDateConverterInterface $rollingDateConverter) {}
|
|
||||||
|
|
||||||
public function addRole(): ?string
|
public function addRole(): ?string
|
||||||
{
|
{
|
||||||
@ -44,29 +42,46 @@ class UserScopeFilter implements FilterInterface
|
|||||||
|
|
||||||
public function alterQuery(QueryBuilder $qb, $data)
|
public function alterQuery(QueryBuilder $qb, $data)
|
||||||
{
|
{
|
||||||
|
$p = self::PREFIX;
|
||||||
|
|
||||||
$qb
|
$qb
|
||||||
->join('acp.userHistories', self::A)
|
->join("acp.userHistories", "{$p}_userHistory")
|
||||||
|
->join("{$p}_userHistory.user", "{$p}_user")
|
||||||
|
->join(
|
||||||
|
UserScopeHistory::class,
|
||||||
|
"{$p}_scopeHistory",
|
||||||
|
Expr\Join::WITH,
|
||||||
|
$qb->expr()->eq("{$p}_scopeHistory", "{$p}_user")
|
||||||
|
)
|
||||||
->andWhere(
|
->andWhere(
|
||||||
$qb->expr()->andX(
|
$qb->expr()->andX(
|
||||||
$qb->expr()->lte(self::A . '.startDate', ':' . self::P),
|
$qb->expr()->lte("{$p}_userHistory.startDate", ":{$p}_date"),
|
||||||
$qb->expr()->orX(
|
$qb->expr()->orX(
|
||||||
$qb->expr()->isNull(self::A . '.endDate'),
|
$qb->expr()->isNull("{$p}_userHistory.endDate"),
|
||||||
$qb->expr()->gt(self::A . '.endDate', ':' . self::P)
|
$qb->expr()->gt("{$p}_userHistory.endDate", ":{$p}_date")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
->setParameter(
|
|
||||||
self::P,
|
|
||||||
$this->rollingDateConverter->convert($data['date_calc'])
|
|
||||||
)
|
|
||||||
->join(self::A . '.user', self::AU)
|
|
||||||
->andWhere(
|
->andWhere(
|
||||||
$qb->expr()->in(self::AU . '.mainScope', ':' . self::PS)
|
$qb->expr()->andX(
|
||||||
|
$qb->expr()->lte("{$p}_scopeHistory.startDate", ":{$p}_date"),
|
||||||
|
$qb->expr()->orX(
|
||||||
|
$qb->expr()->isNull("{$p}_scopeHistory.endDate"),
|
||||||
|
$qb->expr()->gt("{$p}_scopeHistory.endDate", ":{$p}_date")
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
->setParameter(self::PS, $data['scopes']);
|
->andWhere(
|
||||||
|
$qb->expr()->in("{$p}_scopeHistory.scope", ":{$p}_scopes")
|
||||||
|
)
|
||||||
|
->setParameters([
|
||||||
|
["{$p}_scopes", $data["scopes"]],
|
||||||
|
["{$p}_date", $this->rollingDateConverter->convert($data["date_calc"])]
|
||||||
|
])
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applyOn()
|
public function applyOn(): string
|
||||||
{
|
{
|
||||||
return Declarations::ACP_TYPE;
|
return Declarations::ACP_TYPE;
|
||||||
}
|
}
|
||||||
@ -94,7 +109,7 @@ class UserScopeFilter implements FilterInterface
|
|||||||
public function describeAction($data, $format = 'string')
|
public function describeAction($data, $format = 'string')
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'Filtered by user main scope: only %scope%', [
|
'export.filter.course.by_user_scope.Filtered by user main scope: only %scope%', [
|
||||||
'%scope%' => implode(
|
'%scope%' => implode(
|
||||||
', ',
|
', ',
|
||||||
array_map(
|
array_map(
|
||||||
@ -106,16 +121,8 @@ class UserScopeFilter implements FilterInterface
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTitle()
|
public function getTitle():string
|
||||||
{
|
{
|
||||||
return 'Filter by user scope';
|
return 'export.filter.course.by_user_scope.Filter by user scope';
|
||||||
}
|
|
||||||
|
|
||||||
private function getUserMainScope(): Scope
|
|
||||||
{
|
|
||||||
/** @var User $user */
|
|
||||||
$user = $this->security->getUser();
|
|
||||||
|
|
||||||
return $user->getMainScope();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -458,9 +458,6 @@ 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
|
|
||||||
"Filtered by user main scope: only %scope%": "Filtré par service du référent: uniquement %scope%"
|
|
||||||
|
|
||||||
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
|
||||||
"Filtered by socialissues: only %socialissues%": "Filtré par problématique sociale: uniquement %socialissues%"
|
"Filtered by socialissues: only %socialissues%": "Filtré par problématique sociale: uniquement %socialissues%"
|
||||||
@ -1131,6 +1128,8 @@ export:
|
|||||||
'Filtered by steps: only %step% and between %date_from% and %date_to%': 'Filtré par statut: seulement %step%, entre %date_from% et %date_to%'
|
'Filtered by steps: only %step% and between %date_from% and %date_to%': 'Filtré par statut: seulement %step%, entre %date_from% et %date_to%'
|
||||||
by_user_scope:
|
by_user_scope:
|
||||||
Computation date for referrer: Date à laquelle le référent était actif
|
Computation date for referrer: Date à laquelle le référent était actif
|
||||||
|
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%"
|
||||||
by_referrer:
|
by_referrer:
|
||||||
Computation date for referrer: Date à laquelle le référent était actif
|
Computation date for referrer: Date à laquelle le référent était actif
|
||||||
having_temporarily:
|
having_temporarily:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user