update normalizers to take into account referrerHistory logic for accompanying period work

This commit is contained in:
2024-01-24 19:30:09 +01:00
parent d91b1a70bf
commit bc683b28d6
5 changed files with 68 additions and 30 deletions

View File

@@ -14,6 +14,7 @@ namespace Chill\MainBundle\Templating\Entity;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Monolog\DateTimeImmutable;
use Symfony\Component\Clock\ClockInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
@@ -25,18 +26,29 @@ class UserRender implements ChillEntityRenderInterface
'main_scope' => true,
'user_job' => true,
'absence' => true,
'at_date' => null,
'at_date' => null, // instanceof DateTimeInterface
];
public function __construct(private readonly TranslatableStringHelper $translatableStringHelper, private readonly \Twig\Environment $engine, private readonly TranslatorInterface $translator)
{
}
public function __construct(
private readonly TranslatableStringHelper $translatableStringHelper,
private readonly \Twig\Environment $engine, private readonly TranslatorInterface $translator,
private readonly ClockInterface $clock,
) {}
/**
* @param $entity
* @param array{main_scope?: bool, user_job?: bool, absence?: bool, at_date?: null|DateTimeImmutable|DateTimeMutable} $options
* @return string
*/
public function renderBox($entity, array $options): string
{
$opts = \array_merge(self::DEFAULT_OPTIONS, $options);
$opts['at_date'] = $opts['at_date'] instanceOf \DateTime ? DateTimeImmutable::createFromMutable($opts['at_date']) : $opts['at_date'];
if (null === $opts['at_date']) {
$opts['at_date'] = $this->clock->now();
} elseif ($opts['at_date'] instanceof \DateTime) {
$opts['at_date'] = DateTimeImmutable::createFromMutable($opts['at_date']);
}
return $this->engine->render('@ChillMain/Entity/user.html.twig', [
'user' => $entity,
@@ -44,6 +56,11 @@ class UserRender implements ChillEntityRenderInterface
]);
}
/**
* @param $entity
* @param array{main_scope?: bool, user_job?: bool, absence?: bool, at_date?: null|DateTimeImmutable|DateTimeMutable} $options
* @return string
*/
public function renderString($entity, array $options): string
{
$opts = \array_merge(self::DEFAULT_OPTIONS, $options);