mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
[person bloc] handle null values in date + improve layout on dead person
and age
This commit is contained in:
parent
bfed062910
commit
7d6def733c
@ -737,10 +737,21 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
|||||||
return $this->birthdate;
|
return $this->birthdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAge(): ?int
|
/**
|
||||||
|
* Return the age of a person, calculated at the date 'now'.
|
||||||
|
*
|
||||||
|
* If the person has a deathdate, calculate the age at the deathdate.
|
||||||
|
*
|
||||||
|
* @param string $at a valid string to create a DateTime
|
||||||
|
* @return int|null
|
||||||
|
*/
|
||||||
|
public function getAge($at = 'now'): ?int
|
||||||
{
|
{
|
||||||
if ($this->birthdate instanceof \DateTimeInterface) {
|
if ($this->birthdate instanceof \DateTimeInterface) {
|
||||||
return date_diff($this->birthdate, date_create('now'))->format("%y");
|
if ($this->deathdate instanceof \DateTimeInterface) {
|
||||||
|
return date_diff($this->birthdate, $this->deathdate)->format("%y");
|
||||||
|
}
|
||||||
|
return date_diff($this->birthdate, date_create($at))->format("%y");
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -60,23 +60,32 @@
|
|||||||
<i class="fa fa-fw {{ gender }}" title="{{ genderTitle|trans }}"></i>
|
<i class="fa fa-fw {{ gender }}" title="{{ genderTitle|trans }}"></i>
|
||||||
|
|
||||||
{%- if person.deathdate is not null -%}
|
{%- if person.deathdate is not null -%}
|
||||||
|
{%- if person.birthdate is not null -%}
|
||||||
|
<time datetime="{{ person.birthdate|date('Y-m-d') }}" title="{{ 'birthdate'|trans|e('html_attr') }}">
|
||||||
|
{{ person.birthdate|format_date("medium") }}
|
||||||
|
</time>
|
||||||
|
-
|
||||||
|
{%- else -%}
|
||||||
|
{{ 'Date of death'|trans }}:
|
||||||
|
{%- endif -%}
|
||||||
<time datetime="{{ person.deathdate|date('Y-m-d') }}" title="{{ 'Deathdate'|trans }}">
|
<time datetime="{{ person.deathdate|date('Y-m-d') }}" title="{{ 'Deathdate'|trans }}">
|
||||||
{{ 'Date of death'|trans({'deathdate': person.deathdate|format_date("medium") }) }}
|
{{ person.deathdate|format_date("medium") }}
|
||||||
</time>
|
</time>
|
||||||
|
{% if options['addAge'] %}
|
||||||
|
<span class="age">
|
||||||
{%- else -%}
|
({{ 'years_old'|trans({ 'age': person.age }) }})
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
|
{%- elseif person.birthdate is not null -%}
|
||||||
<time datetime="{{ person.birthdate|date('Y-m-d') }}" title="{{ 'Birthdate'|trans }}">
|
<time datetime="{{ person.birthdate|date('Y-m-d') }}" title="{{ 'Birthdate'|trans }}">
|
||||||
{{ 'Born the date'|trans({'gender': person.gender,
|
{{ 'Born the date'|trans({'gender': person.gender,
|
||||||
'birthdate': person.birthdate|format_date("medium") }) }}
|
'birthdate': person.birthdate|format_date("medium") }) }}
|
||||||
</time>
|
</time>
|
||||||
{%- if options['addAge'] -%}
|
{%- if options['addAge'] -%}
|
||||||
<span class="age">
|
<span class="age">
|
||||||
{{ 'years_old'|trans({ 'age': person.age }) }}
|
({{ 'years_old'|trans({ 'age': person.age }) }})
|
||||||
</span>
|
</span>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
</p>
|
</p>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
@ -141,7 +150,7 @@
|
|||||||
{{ options['customButtons']['replace'] }}
|
{{ options['customButtons']['replace'] }}
|
||||||
{%- elseif is_granted('CHILL_PERSON_SEE', person) -%}
|
{%- elseif is_granted('CHILL_PERSON_SEE', person) -%}
|
||||||
<li>
|
<li>
|
||||||
<a class="btn btn-sm btn-show" target="_blank" title="{{ 'Show person'|trans }}"
|
<a class="btn btn-sm btn-show" title="{{ 'Show person'|trans }}"
|
||||||
href="{{ path('chill_person_view', { person_id: person.id }) }}"></a>
|
href="{{ path('chill_person_view', { person_id: person.id }) }}"></a>
|
||||||
</li>
|
</li>
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
|
@ -52,6 +52,7 @@
|
|||||||
'render': 'bloc',
|
'render': 'bloc',
|
||||||
'addLink': true,
|
'addLink': true,
|
||||||
'addInfo': true,
|
'addInfo': true,
|
||||||
|
'addAge': true,
|
||||||
'addAltNames': false,
|
'addAltNames': false,
|
||||||
'addCenter': true,
|
'addCenter': true,
|
||||||
'address_multiline': false,
|
'address_multiline': false,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user