Merge remote-tracking branch 'origin/rector/rules-symfony' into rector/rules-symfony

This commit is contained in:
2023-10-16 18:07:42 +02:00
116 changed files with 3454 additions and 1032 deletions

View File

@@ -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';
}
}

View File

@@ -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';
}
}

View File

@@ -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';
}
}

View File

@@ -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';
}
}