FEATURE [absence][render] add absence tag to renderbox and renderstring

This commit is contained in:
Julie Lenaerts 2023-01-12 13:30:28 +01:00
parent 2c5c815f68
commit 5bbe5af124
3 changed files with 20 additions and 2 deletions

View File

@ -6,4 +6,9 @@
{%- if opts['main_scope'] and user.mainScope is not null %}
<span class="main-scope">({{ user.mainScope.name|localize_translatable_string }})</span>
{%- endif -%}
{%- if opts['absence'] and user.absenceStart is not null %}
{%- if date(user.absenceStart) < date() %}
<span class="user-absence">({{ 'absence.Absent'|trans }})</span>
{%- endif %}
{%- endif -%}
</span>

View File

@ -13,8 +13,10 @@ namespace Chill\MainBundle\Templating\Entity;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Component\Templating\EngineInterface;
use DateTimeImmutable;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use function array_merge;
class UserRender implements ChillEntityRenderInterface
@ -22,16 +24,20 @@ class UserRender implements ChillEntityRenderInterface
public const DEFAULT_OPTIONS = [
'main_scope' => true,
'user_job' => true,
'absence' => true,
];
private EngineInterface $engine;
private TranslatableStringHelper $translatableStringHelper;
public function __construct(TranslatableStringHelper $translatableStringHelper, EngineInterface $engine)
private TranslatorInterface $translator;
public function __construct(TranslatableStringHelper $translatableStringHelper, EngineInterface $engine, TranslatorInterface $translator)
{
$this->translatableStringHelper = $translatableStringHelper;
$this->engine = $engine;
$this->translator = $translator;
}
public function renderBox($entity, array $options): string
@ -63,6 +69,12 @@ class UserRender implements ChillEntityRenderInterface
->localize($entity->getMainScope()->getName()) . ')';
}
$current_date = new DateTimeImmutable();
if (null !== $entity->getAbsenceStart() && $entity->getAbsenceStart() < $current_date && $opts['main_scope']) {
$str .= ' (' . $this->translator->trans('absence.Absent') . ')';
}
return $str;
}

View File

@ -580,3 +580,4 @@ absence:
Unset absence: Supprimer la date d'absence
Set absence date: Indiquer date d'absence
Absence start: Absence à partir de
Absent: Absent