From d0ec6f981913f431f0cacddd8f13d349c48ea78e Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 8 Jan 2024 11:25:13 +0100 Subject: [PATCH] Improve naming for 'at date' in user render component --- src/Bundle/ChillMainBundle/Entity/User.php | 16 ++++++++-------- .../Resources/views/Entity/user.html.twig | 8 ++++---- .../Templating/Entity/UserRender.php | 10 +++++----- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Entity/User.php b/src/Bundle/ChillMainBundle/Entity/User.php index 05112430c..c95ccbf33 100644 --- a/src/Bundle/ChillMainBundle/Entity/User.php +++ b/src/Bundle/ChillMainBundle/Entity/User.php @@ -274,13 +274,13 @@ class User implements UserInterface, \Stringable return $this->mainLocation; } - public function getMainScope(?\DateTimeImmutable $at = null): ?Scope + public function getMainScope(\DateTime $atDate = null): ?Scope { - $at ??= new \DateTimeImmutable('now'); + $atDate ??= new \DateTimeImmutable('now'); foreach ($this->scopeHistories as $scopeHistory) { - if ($at >= $scopeHistory->getStartDate() && ( - null === $scopeHistory->getEndDate() || $at < $scopeHistory->getEndDate() + if ($atDate >= $scopeHistory->getStartDate() && ( + null === $scopeHistory->getEndDate() || $atDate < $scopeHistory->getEndDate() )) { return $scopeHistory->getScope(); } @@ -326,13 +326,13 @@ class User implements UserInterface, \Stringable return $this->salt; } - public function getUserJob(?\DateTimeImmutable $at = null): ?UserJob + public function getUserJob(\DateTime $atDate = null): ?UserJob { - $at ??= new \DateTimeImmutable('now'); + $atDate ??= new \DateTimeImmutable('now'); foreach ($this->jobHistories as $jobHistory) { - if ($at >= $jobHistory->getStartDate() && ( - null === $jobHistory->getEndDate() || $at < $jobHistory->getEndDate() + if ($atDate >= $jobHistory->getStartDate() && ( + null === $jobHistory->getEndDate() || $atDate < $jobHistory->getEndDate() )) { return $jobHistory->getJob(); } diff --git a/src/Bundle/ChillMainBundle/Resources/views/Entity/user.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Entity/user.html.twig index c95308610..84973a096 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Entity/user.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Entity/user.html.twig @@ -1,10 +1,10 @@ {{- user.label }} - {%- if opts['user_job'] and user.userJob(opts['at']) is not null %} - ({{ user.userJob(opts['at']).label|localize_translatable_string }}) + {%- if opts['user_job'] and user.userJob(opts['at_date']) is not null %} + ({{ user.userJob(opts['at_date']).label|localize_translatable_string }}) {%- endif -%} - {%- if opts['main_scope'] and user.mainScope(opts['at']) is not null %} - ({{ user.mainScope(opts['at']).name|localize_translatable_string }}) + {%- if opts['main_scope'] and user.mainScope(opts['at_date']) is not null %} + ({{ user.mainScope(opts['at_date']).name|localize_translatable_string }}) {%- endif -%} {%- if opts['absence'] and user.isAbsent %} {{ 'absence.A'|trans }} diff --git a/src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php b/src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php index f246b0185..376b3b454 100644 --- a/src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php +++ b/src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php @@ -24,7 +24,7 @@ class UserRender implements ChillEntityRenderInterface 'main_scope' => true, 'user_job' => true, 'absence' => true, - 'at' => null, + 'at_date' => null, ]; public function __construct(private readonly TranslatableStringHelper $translatableStringHelper, private readonly \Twig\Environment $engine, private readonly TranslatorInterface $translator) @@ -47,14 +47,14 @@ class UserRender implements ChillEntityRenderInterface $str = $entity->getLabel(); - if (null !== $entity->getUserJob($opts['at']) && $opts['user_job']) { + if (null !== $entity->getUserJob($opts['at_date']) && $opts['user_job']) { $str .= ' ('.$this->translatableStringHelper - ->localize($entity->getUserJob($opts['at'])->getLabel()).')'; + ->localize($entity->getUserJob($opts['at_date'])->getLabel()).')'; } - if (null !== $entity->getMainScope($opts['at']) && $opts['main_scope']) { + if (null !== $entity->getMainScope($opts['at_date']) && $opts['main_scope']) { $str .= ' ('.$this->translatableStringHelper - ->localize($entity->getMainScope($opts['at'])->getName()).')'; + ->localize($entity->getMainScope($opts['at_date'])->getName()).')'; } if ($entity->isAbsent() && $opts['absence']) {