Fix return type in user getters for mainScope and userJob

This commit is contained in:
Mathieu Jaumotte 2023-09-20 14:34:42 +02:00
parent 8a6f29ef79
commit d2feb0f0b4
5 changed files with 24 additions and 52 deletions

View File

@ -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;

View File

@ -11,32 +11,16 @@
{% endblock %}
{% block table_entities_tbody %}
{{ dump(entities) }}
{#
#}
{% for entity in entities %}
<tr>
<td>{{ entity.startDate|format_datetime('medium') }}</td>
<td>
{# {{ dump(entity.id) }} #}
{{ entity.startDate|format_datetime('medium') }}
</td>
<td>{{ entity.endDate|format_datetime('medium') }}</td>
<td>
{% for scope in entity.scope %}
{#
#}
{{ dump(scope) }}
{{ scope.label|localize_translatable_string }}
{% endfor %}
</td>
<td>
{% 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') }}
</td>
<td>{{ entity.user.usernameCanonical }}</td>
<td>{{ entity.scope.name|localize_translatable_string }}</td>
</tr>
{% endfor %}
{% endblock %}

View File

@ -56,7 +56,9 @@
</li>
<li>
<span class="dt">métier:</span>
{% if entity.userJob %}{{ entity.userJob.label|localize_translatable_string }}{% endif %}
{% if entity.userJob %}
{{ entity.userJob.label|localize_translatable_string }}
{% endif %}
</li>
<li>
<span class="dt">cercle/centre:</span>

View File

@ -11,32 +11,16 @@
{% endblock %}
{% block table_entities_tbody %}
{{ dump(entities) }}
{#
#}
{% for entity in entities %}
<tr>
<td>{{ entity.startDate|format_datetime('medium') }}</td>
<td>
{# {{ dump(entity.id) }} #}
{{ entity.startDate|format_datetime('medium') }}
</td>
<td>{{ entity.endDate|format_datetime('medium') }}</td>
<td>
{% for job in entity.job %}
{#
#}
{{ dump(job) }}
{{ job.label|localize_translatable_string }}
{% endfor %}
</td>
<td>
{% 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') }}
</td>
<td>{{ entity.user.usernameCanonical }}</td>
<td>{{ entity.job.label|localize_translatable_string }}</td>
</tr>
{% endfor %}
{% endblock %}

View File

@ -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