mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 18:43:49 +00:00
Merge remote-tracking branch 'origin/rector/rules-symfony' into rector/rules-symfony
This commit is contained in:
@@ -12,17 +12,23 @@ declare(strict_types=1);
|
||||
namespace Chill\CalendarBundle\Export\Aggregator;
|
||||
|
||||
use Chill\CalendarBundle\Export\Declarations;
|
||||
use Chill\MainBundle\Entity\User\UserJobHistory;
|
||||
use Chill\MainBundle\Export\AggregatorInterface;
|
||||
use Chill\MainBundle\Repository\UserJobRepository;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Closure;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use function in_array;
|
||||
|
||||
final readonly class JobAggregator implements AggregatorInterface
|
||||
{
|
||||
public function __construct(private UserJobRepository $jobRepository, private TranslatableStringHelper $translatableStringHelper) {}
|
||||
private const PREFIX = 'cal_agg_job';
|
||||
|
||||
public function __construct(
|
||||
private UserJobRepository $jobRepository,
|
||||
private TranslatableStringHelper $translatableStringHelper
|
||||
) {}
|
||||
|
||||
public function addRole(): ?string
|
||||
{
|
||||
@@ -31,12 +37,28 @@ final readonly class JobAggregator implements AggregatorInterface
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
if (!in_array('caluser', $qb->getAllAliases(), true)) {
|
||||
$qb->join('cal.mainUser', 'caluser');
|
||||
}
|
||||
$p = self::PREFIX;
|
||||
|
||||
$qb->addSelect('IDENTITY(caluser.userJob) as job_aggregator');
|
||||
$qb->addGroupBy('job_aggregator');
|
||||
$qb
|
||||
->leftJoin('cal.mainUser', "{$p}_user")
|
||||
->leftJoin(
|
||||
UserJobHistory::class,
|
||||
"{$p}_history",
|
||||
Join::WITH,
|
||||
$qb->expr()->eq("{$p}_history.user", "{$p}_user")
|
||||
)
|
||||
// job_at based on cal.startDate
|
||||
->andWhere(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->lte("{$p}_history.startDate", "cal.startDate"),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull("{$p}_history.endDate"),
|
||||
$qb->expr()->gt("{$p}_history.endDate", "cal.startDate")
|
||||
)
|
||||
)
|
||||
)
|
||||
->addSelect("IDENTITY({$p}_history.job) AS {$p}_select")
|
||||
->addGroupBy("{$p}_select");
|
||||
}
|
||||
|
||||
public function applyOn(): string
|
||||
@@ -44,10 +66,8 @@ final readonly class JobAggregator implements AggregatorInterface
|
||||
return Declarations::CALENDAR_TYPE;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
// no form
|
||||
}
|
||||
public function buildForm(FormBuilderInterface $builder) {}
|
||||
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
@@ -64,7 +84,9 @@ final readonly class JobAggregator implements AggregatorInterface
|
||||
return '';
|
||||
}
|
||||
|
||||
$j = $this->jobRepository->find($value);
|
||||
if (null === $j = $this->jobRepository->find($value)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->translatableStringHelper->localize(
|
||||
$j->getLabel()
|
||||
@@ -74,11 +96,11 @@ final readonly class JobAggregator implements AggregatorInterface
|
||||
|
||||
public function getQueryKeys($data): array
|
||||
{
|
||||
return ['job_aggregator'];
|
||||
return [self::PREFIX . '_select'];
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Group calendars by agent job';
|
||||
return 'export.aggregator.calendar.agent_job.Group calendars by agent job';
|
||||
}
|
||||
}
|
||||
|
@@ -12,16 +12,19 @@ declare(strict_types=1);
|
||||
namespace Chill\CalendarBundle\Export\Aggregator;
|
||||
|
||||
use Chill\CalendarBundle\Export\Declarations;
|
||||
use Chill\MainBundle\Entity\User\UserScopeHistory;
|
||||
use Chill\MainBundle\Export\AggregatorInterface;
|
||||
use Chill\MainBundle\Repository\ScopeRepository;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Closure;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use function in_array;
|
||||
|
||||
final readonly class ScopeAggregator implements AggregatorInterface
|
||||
{
|
||||
private const PREFIX = "cal_agg_scope";
|
||||
|
||||
public function __construct(
|
||||
private ScopeRepository $scopeRepository,
|
||||
private TranslatableStringHelper $translatableStringHelper
|
||||
@@ -34,12 +37,28 @@ final readonly class ScopeAggregator implements AggregatorInterface
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
if (!in_array('caluser', $qb->getAllAliases(), true)) {
|
||||
$qb->join('cal.mainUser', 'caluser');
|
||||
}
|
||||
$p = self::PREFIX;
|
||||
|
||||
$qb->addSelect('IDENTITY(caluser.mainScope) as scope_aggregator');
|
||||
$qb->addGroupBy('scope_aggregator');
|
||||
$qb
|
||||
->leftJoin("cal.mainUser", "{$p}_user")
|
||||
->leftJoin(
|
||||
UserScopeHistory::class,
|
||||
"{$p}_history",
|
||||
Join::WITH,
|
||||
$qb->expr()->eq("{$p}_history.user", "{$p}_user")
|
||||
)
|
||||
// scope_at based on cal.startDate
|
||||
->andWhere(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->lte("{$p}_history.startDate", "cal.startDate"),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull("{$p}_history.endDate"),
|
||||
$qb->expr()->gt("{$p}_history.endDate", "cal.startDate")
|
||||
)
|
||||
)
|
||||
)
|
||||
->addSelect("IDENTITY({$p}_history.scope) AS {$p}_select")
|
||||
->addGroupBy("{$p}_select");
|
||||
}
|
||||
|
||||
public function applyOn(): string
|
||||
@@ -47,10 +66,8 @@ final readonly class ScopeAggregator implements AggregatorInterface
|
||||
return Declarations::CALENDAR_TYPE;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
// no form
|
||||
}
|
||||
public function buildForm(FormBuilderInterface $builder) {}
|
||||
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
@@ -67,7 +84,9 @@ final readonly class ScopeAggregator implements AggregatorInterface
|
||||
return '';
|
||||
}
|
||||
|
||||
$s = $this->scopeRepository->find($value);
|
||||
if (null === $s = $this->scopeRepository->find($value)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->translatableStringHelper->localize(
|
||||
$s->getName()
|
||||
@@ -77,11 +96,11 @@ final readonly class ScopeAggregator implements AggregatorInterface
|
||||
|
||||
public function getQueryKeys($data): array
|
||||
{
|
||||
return ['scope_aggregator'];
|
||||
return [self::PREFIX . '_select'];
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Group calendars by agent scope';
|
||||
return 'export.aggregator.calendar.agent_scope.Group calendars by agent scope';
|
||||
}
|
||||
}
|
||||
|
@@ -12,19 +12,23 @@ declare(strict_types=1);
|
||||
namespace Chill\CalendarBundle\Export\Filter;
|
||||
|
||||
use Chill\CalendarBundle\Export\Declarations;
|
||||
use Chill\MainBundle\Entity\User\UserJobHistory;
|
||||
use Chill\MainBundle\Entity\UserJob;
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Doctrine\ORM\Query\Expr\Andx;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use function in_array;
|
||||
|
||||
class JobFilter implements FilterInterface
|
||||
final readonly class JobFilter implements FilterInterface
|
||||
{
|
||||
public function __construct(protected TranslatorInterface $translator, private readonly TranslatableStringHelper $translatableStringHelper) {}
|
||||
private const PREFIX = 'cal_filter_job';
|
||||
|
||||
public function __construct(
|
||||
private TranslatableStringHelper $translatableStringHelper
|
||||
) {}
|
||||
|
||||
public function addRole(): ?string
|
||||
{
|
||||
@@ -33,21 +37,32 @@ class JobFilter implements FilterInterface
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
if (!in_array('caluser', $qb->getAllAliases(), true)) {
|
||||
$qb->join('cal.mainUser', 'caluser');
|
||||
}
|
||||
$p = self::PREFIX;
|
||||
|
||||
$where = $qb->getDQLPart('where');
|
||||
$clause = $qb->expr()->in('caluser.userJob', ':job');
|
||||
$qb
|
||||
->leftJoin("cal.mainUser", "{$p}_user")
|
||||
->leftJoin(
|
||||
UserJobHistory::class,
|
||||
"{$p}_history",
|
||||
Join::WITH,
|
||||
$qb->expr()->eq("{$p}_history.user", "{$p}_user")
|
||||
)
|
||||
// job_at based on cal.startDate
|
||||
->andWhere(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->lte("{$p}_history.startDate", "cal.startDate"),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull("{$p}_history.endDate"),
|
||||
$qb->expr()->gt("{$p}_history.endDate", "cal.startDate")
|
||||
)
|
||||
)
|
||||
)
|
||||
->andWhere($qb->expr()->in("{$p}_history.job", ":{$p}_job"))
|
||||
->setParameter(
|
||||
"{$p}_job",
|
||||
$data["job"]
|
||||
);
|
||||
|
||||
if ($where instanceof Andx) {
|
||||
$where->add($clause);
|
||||
} else {
|
||||
$where = $qb->expr()->andX($clause);
|
||||
}
|
||||
|
||||
$qb->add('where', $where);
|
||||
$qb->setParameter('job', $data['job']);
|
||||
}
|
||||
|
||||
public function applyOn(): string
|
||||
@@ -57,18 +72,15 @@ class JobFilter implements FilterInterface
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('job', EntityType::class, [
|
||||
'class' => UserJob::class,
|
||||
'choice_label' => fn (UserJob $j) => $this->translatableStringHelper->localize(
|
||||
$j->getLabel()
|
||||
),
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
$builder
|
||||
->add('job', EntityType::class, [
|
||||
'class' => UserJob::class,
|
||||
'choice_label' => fn (UserJob $j) => $this->translatableStringHelper->localize(
|
||||
$j->getLabel()
|
||||
),
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
@@ -81,13 +93,20 @@ class JobFilter implements FilterInterface
|
||||
);
|
||||
}
|
||||
|
||||
return ['Filtered by agent job: only %jobs%', [
|
||||
return ['export.filter.calendar.agent_job.Filtered by agent job: only %jobs%', [
|
||||
'%jobs%' => implode(', ', $userJobs),
|
||||
]];
|
||||
}
|
||||
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [
|
||||
'job' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Filter calendars by agent job';
|
||||
return 'export.filter.calendar.agent_job.Filter calendars by agent job';
|
||||
}
|
||||
}
|
||||
|
@@ -13,18 +13,23 @@ namespace Chill\CalendarBundle\Export\Filter;
|
||||
|
||||
use Chill\CalendarBundle\Export\Declarations;
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Entity\User\UserScopeHistory;
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Doctrine\ORM\Query\Expr\Andx;
|
||||
use Doctrine\ORM\Query\Expr\Join;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use function in_array;
|
||||
|
||||
class ScopeFilter implements FilterInterface
|
||||
{
|
||||
public function __construct(protected TranslatorInterface $translator, private readonly TranslatableStringHelper $translatableStringHelper) {}
|
||||
private const PREFIX = 'cal_filter_scope';
|
||||
|
||||
public function __construct(
|
||||
protected TranslatorInterface $translator,
|
||||
private readonly TranslatableStringHelper $translatableStringHelper
|
||||
) {}
|
||||
|
||||
public function addRole(): ?string
|
||||
{
|
||||
@@ -33,45 +38,52 @@ class ScopeFilter implements FilterInterface
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
if (!in_array('caluser', $qb->getAllAliases(), true)) {
|
||||
$qb->join('cal.mainUser', 'caluser');
|
||||
}
|
||||
$p = self::PREFIX;
|
||||
|
||||
$where = $qb->getDQLPart('where');
|
||||
$clause = $qb->expr()->in('caluser.mainScope', ':scope');
|
||||
|
||||
if ($where instanceof Andx) {
|
||||
$where->add($clause);
|
||||
} else {
|
||||
$where = $qb->expr()->andX($clause);
|
||||
}
|
||||
|
||||
$qb->add('where', $where);
|
||||
$qb->setParameter('scope', $data['scope']);
|
||||
$qb
|
||||
->leftJoin("cal.mainUser", "{$p}_user")
|
||||
->leftJoin(
|
||||
UserScopeHistory::class,
|
||||
"{$p}_history",
|
||||
Join::WITH,
|
||||
$qb->expr()->eq("{$p}_history.user", "{$p}_user")
|
||||
)
|
||||
// scope_at based on cal.startDate
|
||||
->andWhere(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->lte("{$p}_history.startDate", "cal.startDate"),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull("{$p}_history.endDate"),
|
||||
$qb->expr()->gt("{$p}_history.endDate", "cal.startDate")
|
||||
)
|
||||
)
|
||||
)
|
||||
->andWhere($qb->expr()->in("{$p}_history.scope", ":{$p}_scope"))
|
||||
->setParameter(
|
||||
"{$p}_scope",
|
||||
$data["scope"]
|
||||
);
|
||||
}
|
||||
|
||||
public function applyOn()
|
||||
public function applyOn(): string
|
||||
{
|
||||
return Declarations::CALENDAR_TYPE;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('scope', EntityType::class, [
|
||||
'class' => Scope::class,
|
||||
'choice_label' => fn (Scope $s) => $this->translatableStringHelper->localize(
|
||||
$s->getName()
|
||||
),
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return [];
|
||||
$builder
|
||||
->add('scope', EntityType::class, [
|
||||
'class' => Scope::class,
|
||||
'choice_label' => fn (Scope $s) => $this->translatableStringHelper->localize(
|
||||
$s->getName()
|
||||
),
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string')
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
$scopes = [];
|
||||
|
||||
@@ -81,13 +93,20 @@ class ScopeFilter implements FilterInterface
|
||||
);
|
||||
}
|
||||
|
||||
return ['Filtered by agent scope: only %scopes%', [
|
||||
return ['export.filter.calendar.agent_scope.Filtered by agent scope: only %scopes%', [
|
||||
'%scopes%' => implode(', ', $scopes),
|
||||
]];
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return 'Filter calendars by agent scope';
|
||||
return [
|
||||
'scope' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'export.filter.calendar.agent_scope.Filter calendars by agent scope';
|
||||
}
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ final class JobAggregatorTest extends AbstractAggregatorTest
|
||||
public function getFormData(): array
|
||||
{
|
||||
return [
|
||||
[],
|
||||
[]
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -22,6 +22,7 @@ use Chill\CalendarBundle\Entity\Calendar;
|
||||
use Chill\CalendarBundle\Export\Filter\JobFilter;
|
||||
use Chill\MainBundle\Entity\UserJob;
|
||||
use Chill\MainBundle\Test\Export\AbstractFilterTest;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
@@ -62,7 +63,11 @@ final class JobFilterTest extends AbstractFilterTest
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
|
||||
yield ['job' => $array];
|
||||
return [
|
||||
[
|
||||
'job' => new ArrayCollection($array)
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getQueryBuilders(): array
|
||||
|
@@ -22,6 +22,7 @@ use Chill\CalendarBundle\Entity\Calendar;
|
||||
use Chill\CalendarBundle\Export\Filter\ScopeFilter;
|
||||
use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Test\Export\AbstractFilterTest;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
/**
|
||||
@@ -62,15 +63,11 @@ final class ScopeFilterTest extends AbstractFilterTest
|
||||
->setMaxResults(1)
|
||||
->getResult();
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($array as $a) {
|
||||
$data[] = [
|
||||
'scope' => $a,
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
return [
|
||||
[
|
||||
'scope' => new ArrayCollection($array)
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getQueryBuilders(): array
|
||||
|
@@ -99,24 +99,32 @@ Get the sum of appointment durations according to various filters: Calcule la so
|
||||
|
||||
'Filtered by agent: only %agents%': "Filtré par agents: uniquement %agents%"
|
||||
Filter calendars by agent: Filtrer les rendez-vous par agents
|
||||
Filter calendars by agent job: Filtrer les rendez-vous par métiers des agents
|
||||
'Filtered by agent job: only %jobs%': 'Filtré par métiers des agents: uniquement les %jobs%'
|
||||
Filter calendars by agent scope: Filtrer les rendez-vous par services des agents
|
||||
'Filtered by agent scope: only %scopes%': 'Filtré par services des agents: uniquement les services %scopes%'
|
||||
Filter calendars between certain dates: Filtrer les rendez-vous par date du rendez-vous
|
||||
'Filtered by calendars between %dateFrom% and %dateTo%': 'Filtré par rendez-vous entre %dateFrom% et %dateTo%'
|
||||
'Filtered by calendar range: only %calendarRange%': 'Filtré par rendez-vous par plage de disponibilité: uniquement les %calendarRange%'
|
||||
Filter by calendar range: Filtrer par rendez-vous dans une plage de disponibilité ou non
|
||||
|
||||
Group calendars by agent: Grouper les rendez-vous par agent
|
||||
Group calendars by agent job: Grouper les rendez-vous par métier de l'agent
|
||||
Group calendars by agent scope: Grouper les rendez-vous par service de l'agent
|
||||
Group calendars by location type: Grouper les rendez-vous par type de localisation
|
||||
Group calendars by location: Grouper les rendez-vous par lieu de rendez-vous
|
||||
Group calendars by cancel reason: Grouper les rendez-vous par motif d'annulation
|
||||
Group calendars by month and year: Grouper les rendez-vous par mois et année
|
||||
Group calendars by urgency: Grouper les rendez-vous par urgent ou non
|
||||
|
||||
export:
|
||||
aggregator.calendar:
|
||||
agent_job:
|
||||
Group calendars by agent job: Grouper les rendez-vous par métier de l'agent
|
||||
agent_scope:
|
||||
Group calendars by agent scope: Grouper les rendez-vous par service de l'agent
|
||||
filter.calendar:
|
||||
agent_job:
|
||||
Filter calendars by agent job: Filtrer les rendez-vous par métiers des agents (utilisateurs principaux)
|
||||
'Filtered by agent job: only %jobs%': 'Filtré par métiers des agents (utilisateurs principaux): uniquement les %jobs%'
|
||||
agent_scope:
|
||||
Filter calendars by agent scope: Filtrer les rendez-vous par services des agents (utilisateurs principaux)
|
||||
'Filtered by agent scope: only %scopes%': 'Filtré par services des agents (utilisateurs principaux): uniquement les services %scopes%'
|
||||
|
||||
Scope: Service
|
||||
Job: Métier
|
||||
Location type: Type de localisation
|
||||
|
Reference in New Issue
Block a user