From d2feb0f0b4489d6dca5b2b5c46e6cefb7086e74b Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 20 Sep 2023 14:34:42 +0200 Subject: [PATCH] Fix return type in user getters for mainScope and userJob --- src/Bundle/ChillMainBundle/Entity/User.php | 10 +++---- .../Resources/views/Scope/history.html.twig | 28 ++++--------------- .../Resources/views/User/index.html.twig | 4 ++- .../Resources/views/UserJob/history.html.twig | 28 ++++--------------- .../translations/messages.fr.yml | 6 ++-- 5 files changed, 24 insertions(+), 52 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Entity/User.php b/src/Bundle/ChillMainBundle/Entity/User.php index 9656cb3e6..8eab3bb11 100644 --- a/src/Bundle/ChillMainBundle/Entity/User.php +++ b/src/Bundle/ChillMainBundle/Entity/User.php @@ -262,7 +262,7 @@ class User implements UserInterface, \Stringable return $this->mainLocation; } - public function getMainScope(?DateTimeImmutable $at = null): ?UserScopeHistory + public function getMainScope(?DateTimeImmutable $at = null): ?Scope { $at ??= new DateTimeImmutable('today'); $criteria = new Criteria(); @@ -281,7 +281,7 @@ class User implements UserInterface, \Stringable $scopes = $this->scopeHistories->matching($criteria); if ($scopes->count() > 0) { - return $scopes->first(); + return $scopes->first()->getScope(); } return null; @@ -305,7 +305,7 @@ class User implements UserInterface, \Stringable return $this->salt; } - public function getUserJob(?DateTimeImmutable $at = null): ?UserJobHistory + public function getUserJob(?DateTimeImmutable $at = null): ?UserJob { $at ??= new DateTimeImmutable('today'); $criteria = new Criteria(); @@ -317,13 +317,13 @@ class User implements UserInterface, \Stringable $expr->isNull('endDate'), $expr->gt('endDate', $at) ), - $expr->lte('startDate') + $expr->lte('startDate', $at) ) ); $jobs = $this->jobHistories->matching($criteria); if ($jobs->count() > 0) { - return $jobs->first(); + return $jobs->first()->getJob(); } return null; diff --git a/src/Bundle/ChillMainBundle/Resources/views/Scope/history.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Scope/history.html.twig index 3c08620c7..952aa3a5b 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Scope/history.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Scope/history.html.twig @@ -11,32 +11,16 @@ {% endblock %} {% block table_entities_tbody %} - {{ dump(entities) }} - {# - #} {% for entity in entities %} + {{ entity.startDate|format_datetime('medium') }} - {# {{ dump(entity.id) }} #} - {{ entity.startDate|format_datetime('medium') }} - - {{ entity.endDate|format_datetime('medium') }} - - {% for scope in entity.scope %} - {# - #} - {{ dump(scope) }} - {{ scope.label|localize_translatable_string }} - {% endfor %} - - - {% for user in entity.user %} - {# - #} - {{ dump(user.id) }} - {{ user.usernameCanonical }} - {% endfor %} + {{ (entity.endDate is null) + ? "crud.admin_user_scope_history.index.today"|trans + : entity.endDate|format_datetime('medium') }} + {{ entity.user.usernameCanonical }} + {{ entity.scope.name|localize_translatable_string }} {% endfor %} {% endblock %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/User/index.html.twig b/src/Bundle/ChillMainBundle/Resources/views/User/index.html.twig index c5cd73d18..5393f09c8 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/User/index.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/User/index.html.twig @@ -56,7 +56,9 @@
  • métier: - {% if entity.userJob %}{{ entity.userJob.label|localize_translatable_string }}{% endif %} + {% if entity.userJob %} + {{ entity.userJob.label|localize_translatable_string }} + {% endif %}
  • cercle/centre: diff --git a/src/Bundle/ChillMainBundle/Resources/views/UserJob/history.html.twig b/src/Bundle/ChillMainBundle/Resources/views/UserJob/history.html.twig index c7f3867c9..75ad32058 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/UserJob/history.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/UserJob/history.html.twig @@ -11,32 +11,16 @@ {% endblock %} {% block table_entities_tbody %} - {{ dump(entities) }} - {# - #} {% for entity in entities %} + {{ entity.startDate|format_datetime('medium') }} - {# {{ dump(entity.id) }} #} - {{ entity.startDate|format_datetime('medium') }} - - {{ entity.endDate|format_datetime('medium') }} - - {% for job in entity.job %} - {# - #} - {{ dump(job) }} - {{ job.label|localize_translatable_string }} - {% endfor %} - - - {% for user in entity.user %} - {# - #} - {{ dump(user.id) }} - {{ user.usernameCanonical }} - {% endfor %} + {{ (entity.endDate is null) + ? "crud.admin_user_job_history.index.today"|trans + : entity.endDate|format_datetime('medium') }} + {{ entity.user.usernameCanonical }} + {{ entity.job.label|localize_translatable_string }} {% endfor %} {% endblock %} diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index aa61c3dbf..e4977eb60 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -393,7 +393,8 @@ crud: index: title: Historique des métiers start: Du - end: Au + end: Jusque + today: aujourd'hui user: Utilisateur job: Métier Show job history: Voir l'historique @@ -402,7 +403,8 @@ crud: index: title: Historique des cercles start: Du - end: Au + end: Jusque + today: aujourd'hui user: Utilisateur scope: Cercle Show scope history: Voir l'historique