mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Implement clockInterface in renderString method
This commit is contained in:
parent
8d58805abd
commit
b46883fe36
@ -13,9 +13,13 @@ namespace Chill\MainBundle\Templating\Entity;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use DateTime;
|
||||
use Monolog\DateTimeImmutable;
|
||||
use Symfony\Component\Clock\ClockInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Error\RuntimeError;
|
||||
use Twig\Error\SyntaxError;
|
||||
|
||||
/**
|
||||
* @implements ChillEntityRenderInterface<User>
|
||||
@ -37,8 +41,11 @@ class UserRender implements ChillEntityRenderInterface
|
||||
|
||||
/**
|
||||
* @param $entity
|
||||
* @param array{main_scope?: bool, user_job?: bool, absence?: bool, at_date?: null|DateTimeImmutable|DateTimeMutable} $options
|
||||
* @param array{main_scope?: bool, user_job?: bool, absence?: bool, at_date?: null|DateTimeImmutable|DateTime} $options
|
||||
* @return string
|
||||
* @throws LoaderError
|
||||
* @throws RuntimeError
|
||||
* @throws SyntaxError
|
||||
*/
|
||||
public function renderBox($entity, array $options): string
|
||||
{
|
||||
@ -46,7 +53,7 @@ class UserRender implements ChillEntityRenderInterface
|
||||
|
||||
if (null === $opts['at_date']) {
|
||||
$opts['at_date'] = $this->clock->now();
|
||||
} elseif ($opts['at_date'] instanceof \DateTime) {
|
||||
} elseif ($opts['at_date'] instanceof DateTime) {
|
||||
$opts['at_date'] = DateTimeImmutable::createFromMutable($opts['at_date']);
|
||||
}
|
||||
|
||||
@ -65,18 +72,24 @@ class UserRender implements ChillEntityRenderInterface
|
||||
{
|
||||
$opts = \array_merge(self::DEFAULT_OPTIONS, $options);
|
||||
|
||||
$immutableAtDate = $opts['at_date'] instanceOf \DateTime ? DateTimeImmutable::createFromMutable($opts['at_date']) : $opts['at_date'];
|
||||
// $immutableAtDate = $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']);
|
||||
}
|
||||
|
||||
$str = $entity->getLabel();
|
||||
|
||||
if (null !== $entity->getUserJob($immutableAtDate) && $opts['user_job']) {
|
||||
if (null !== $entity->getUserJob($opts['at_date']) && $opts['user_job']) {
|
||||
$str .= ' ('.$this->translatableStringHelper
|
||||
->localize($entity->getUserJob($immutableAtDate)->getLabel()).')';
|
||||
->localize($entity->getUserJob($opts['at_date'])->getLabel()).')';
|
||||
}
|
||||
|
||||
if (null !== $entity->getMainScope($immutableAtDate) && $opts['main_scope']) {
|
||||
if (null !== $entity->getMainScope($opts['at_date']) && $opts['main_scope']) {
|
||||
$str .= ' ('.$this->translatableStringHelper
|
||||
->localize($entity->getMainScope($immutableAtDate)->getName()).')';
|
||||
->localize($entity->getMainScope($opts['at_date'])->getName()).')';
|
||||
}
|
||||
|
||||
if ($entity->isAbsent() && $opts['absence']) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user