Merge branch 'period-in-list-result' into 59_parcours_resu_2

This commit is contained in:
Mathieu Jaumotte 2021-05-25 22:00:58 +02:00
commit 6264171c0c
17 changed files with 521 additions and 9 deletions

View File

@ -9,6 +9,12 @@ div.chill_address {
margin: 0 0 0 1.5em;
text-indent: -1.5em;
}
&.chill_address_address--multiline {
p {
display: block;
}
}
}
}

View File

@ -9,6 +9,11 @@ ul.record_actions li {
ul.record_actions, ul.record_actions_column {
display: flex;
justify-content: flex-end;
&.record_actions--left {
justify-content: flex-start;
}
padding: 0.5em 0;
flex-wrap: wrap-reverse;

View File

@ -0,0 +1,16 @@
<div class="chill_address">
{% if options['has_no_address'] == true and address.isNoAddress == true %}
<div class="chill_address_is_noaddress">{{ 'address.consider homeless'|trans }}</div>
{% endif %}
<div class="chill_address_address {% if options['multiline'] %}chill_address_address--multiline{% endif %}">
{% if address.street is not empty %}<p class="street street1">{{ address.street }}</p>{% endif %}
{% if address.streetNumber is not empty %}<p class="street street2">{{ address.streetNumber }}</p>{% endif %}
{% if address.postCode is not empty %}
<p class="postalCode"><span class="code">{{ address.postCode.code }}</span> <span class="name">{{ address.postCode.name }}</span></p>
<p class="country">{{ address.postCode.country.name|localize_translatable_string }}</p>
{% endif %}
</div>
{%- if options['with_valid_from'] == true -%}
<span class="address_since">{{ 'Since %date%'|trans( { '%date%' : address.validFrom|format_date('long') } ) }}</span>
{%- endif -%}
</div>

View File

@ -0,0 +1,67 @@
<?php
namespace Chill\MainBundle\Templating\Entity;
use Symfony\Component\Templating\EngineInterface;
use Chill\MainBundle\Entity\Address;
class AddressRender implements ChillEntityRenderInterface
{
private EngineInterface $templating;
public const DEFAULT_OPTIONS = [
'with_valid_from' => true,
'has_no_address' => false,
'multiline' => true,
];
public function __construct(EngineInterface $templating)
{
$this->templating = $templating;
}
/**
* {@inheritDoc}
*/
public function supports($entity, array $options): bool
{
return $entity instanceof Address;
}
/**
* @param Address addr
*/
public function renderString($addr, array $options): string
{
$lines = [];
if (!empty($addr->getStreet())) {
$lines[0] = $addr->getStreet();
}
if (!empty($addr->getStreetNumber())) {
$lines[0] .= ", ".$addr->getStreetNumber();
}
if (!empty($addr->getPostcode())) {
$lines[1] = \strtr("{postcode} {label}", [
'{postcode}' => $addr->getPostcode()->getCode(),
'{label}' => $addr->getPostcode()->getName()
]);
}
return implode(" - ", $lines);
}
/**
* {@inheritDoc}
* @param Address addr
*/
public function renderBox($addr, array $options): string
{
$options = \array_merge(self::DEFAULT_OPTIONS, $options);
return $this->templating
->render('@ChillMain/Address/entity_render.html.twig', [
'address' => $addr,
'options' => $options
]);
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace Chill\MainBundle\Tests\Templating\Entity;
use Chill\MainBundle\Entity\Country;
use Chill\MainBundle\Entity\PostalCode;
use Chill\MainBundle\Templating\Entity\AddressRender;
use Chill\MainBundle\Entity\Address;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Templating\EngineInterface;
class AddressRenderTest extends KernelTestCase
{
protected function setUp()
{
self::bootKernel();
}
/**
* @dataProvider addressDataProvider
*/
public function testRenderString(Address $addr, string $expectedString): void
{
$engine = self::$container->get(EngineInterface::class);
$renderer = new AddressRender($engine);
$this->assertEquals($expectedString, $renderer->renderString($addr, []));
return;
$this->assertIsString($renderer->renderBox($addr, []));
}
public function addressDataProvider(): \Iterator
{
$addr = new Address();
$country = (new Country())
->setName([ "fr" => "Pays" ])
->setCountryCode("BE")
;
$postCode = new PostalCode();
$postCode->setName("Locality")
->setCode("012345")
->setCountry($country)
;
$addr->setStreet("Rue ABC")
->setStreetNumber("5")
->setPostcode($postCode)
;
yield[ $addr, "Rue ABC, 5 - 012345 Locality"];
}
}

View File

@ -41,3 +41,10 @@ services:
Chill\MainBundle\Templating\ChillMarkdownRenderExtension:
tags:
- { name: twig.extension }
Chill\MainBundle\Templating\Entity\AddressRender:
arguments:
- '@Symfony\Component\Templating\EngineInterface'
tags:
- { name: 'chill.render_entity' }

View File

@ -421,6 +421,31 @@ class Person implements HasCenterInterface
return $this->accompanyingPeriodParticipations;
}
/**
* Return a collection of participation, where the participation
* is still opened, not a draft, and the period is still opened
*/
public function getOpenedParticipations(): Collection
{
// create a criteria for filtering easily
$criteria = Criteria::create();
$criteria
->andWhere(Criteria::expr()->eq('endDate', NULL))
->orWhere(Criteria::expr()->gt('endDate', new \DateTime('now')))
;
return $this->getAccompanyingPeriodParticipations()
->matching($criteria)
->filter(function (AccompanyingPeriodParticipation $app) {
$period = $app->getAccompanyingPeriod();
return (
NULL === $period->getClosingDate()
|| new \DateTime('now') < $period->getClosingDate()
)
&& AccompanyingPeriod::STEP_DRAFT !== $period->getStep();
});
}
/**
* Get the accompanying periods of a give person with the chronological order.
*/

View File

@ -1 +1,2 @@
require('./sass/person.scss');
require('./sass/person.scss');
require('./sass/person_with_period.scss');

View File

@ -1,5 +1,5 @@
require('./phone-alt-solid.svg');
require('./mobile-alt-solid.svg');
require('./person_by_phonenumber.scss');
require('./person_with_period.scss');

View File

@ -0,0 +1,68 @@
.person-list--with-period {
.person-list--with-period__item {
margin-bottom: 0;
padding: 1em 1em 2em 1em;
&:nth-last-of-type {
padding-bottom: 1em;
}
.chill-entity__person {
.chill-entity__person__first-name,
.chill-entity__person__last-name {
font-size: 1.3em;
font-weight: 700;
}
}
& > div {
display: flex;
}
@media screen and (min-width: 720px) {
& > div {
flex-direction: row;
.person-list--with-period__item__box-where {
align-self: flex-end;
margin-left: auto;
width: 33%;
text-align: right;
}
}
}
@media screen and (max-width: 720px) {
& > div {
flex-direction: column;
}
}
@media screen and (max-width: 460px) {
.person-list--with-period__item__box-where__center {
display: none;
}
.chill_address {
.street {
display: none;
}
.country {
display: none;
}
}
}
ul.person-list--with-period__item__periods {
list-style-type: none;
padding: 0;
margin: 0;
li {
}
}
}
.person-list--with-period__item:hover {
background-color: var(--chill-llight-gray);
}
}

View File

@ -0,0 +1,15 @@
<span class="chill-entity chill-entity__person">
{%- if addLink and is_granted('CHILL_PERSON_SEE', person) -%}
{%- set showLink = true -%}<a href="{{ chill_path_add_return_path('chill_person_view', { 'person_id': person.id }) }}">{%- endif -%}
<span class="chill-entity__person__first-name">{{ person.firstName }}</span>
<span class="chill-entity__person__last-name">{{ person.lastName }}</span>
{%- if addAltNames -%}
{%- for n in person.altNames -%}
{%- if loop.first -%}({% else %} {%- endif -%}
<span class="chill-entity__person__alt-name chill-entity__person__altname--{{ n.key }}">
{{ n.label }}
</span>
{%- if loop.last %}) {% endif -%}
{%- endfor -%}
{%- endif -%}
{%- if showLink is defined -%}</a>{%- endif -%}</span>

View File

@ -0,0 +1,13 @@
{% set reversed_parents = parents|reverse %}
<span class="chill-entity chill-entity__social-issue">
<span class="badge badge-primary">
{%- for p in reversed_parents %}
<span class="chill-entity__social-issue__parent--{{ loop.revindex0 }}">
{{ p.title|localize_translatable_string }}{{ options['default.separator'] }}
</span>
{%- endfor -%}
<span class="chill-entity__social-issue__child">
{{ socialIssue.title|localize_translatable_string }}
</span>
</span>
</span>

View File

@ -0,0 +1,208 @@
<h2>{{ title|default('Person search results')|trans }}</h2>
<p>
{{ '%total% persons matching the search pattern:'|transchoice( total, { '%total%' : total}) }}
<a href="{{ path('chill_main_advanced_search', { "name": search_name, "q": pattern } ) }}" class="sc-button button-small">
<i class="fa fa-search" aria-hidden="true"></i> {{ pattern }}
</a>
</p>
<p>{{ 'Results %start%-%end% of %total%'|trans({ '%start%' : start, '%end%': start + persons|length, '%total%' : total } ) }}</p>
<ul class="record_actions">
{% if is_granted('CHILL_PERSON_CREATE') %}
<li>
<a href="{{ path('chill_person_new') }}" class="sc-button bt-create">
{{ 'Add a person'|trans }}
</a>
</li>
{% endif %}
{% if search_name != "person_similarity" %}
<li>
<a href="{{ path('chill_main_advanced_search', { "name": search_name, "q": pattern } ) }}" class="sc-button bt-action">
<i class="fa fa-search" aria-hidden="true"></i> {{ 'Advanced search'|trans }}
</a>
</li>
{% endif %}
{% if preview == true and persons|length < total %}
<li>
<a href="{{ path('chill_main_search', { "name": search_name|default('abcd'), "q" : pattern }) }}" class="sc-button">
{{ 'See all results'|trans }}
</a>
</li>
{% endif %}
</ul>
{% if persons|length > 0 %}
<div class="person-list--with-period">
{% for person in persons %}
<div class="person-list--with-period__item">
<div>
<div class="person-list--with-period__item__box-person">
<div>
<span>{{ person|chill_entity_render_box({'addLink': true}) }}</span>
<span>{{ 'Born the %date%'|transchoice(person.genderNumeric, { '%date%': person.birthdate|format_date("medium") }) }}</span>
</div>
<div>
<ul class="record_actions record_actions--left">
<li>
<a href="{{ path('chill_person_view', { 'person_id' : person.id }) }}" class="sc-button bt-view" />
{{ 'Open person file'|trans }}
</a>
</li>
<li>
<a href="{{ path('chill_person_accompanying_period_list', { 'person_id' : person.id }) }}" class="sc-button" /><i class="fa fa-random"></i></a>
</li>
</ul>
</div>
</div>
<div class="person-list--with-period__item__box-where">
<span class="person-list--with-period__item__box-where__center">{{ person.center }}</span>
{% if person.getLastAddress is not null %}
<span>{{ person.getLastAddress|chill_entity_render_box({'with_valid_from': false}) }}</span>
{% else %}
<span>{{ 'No address'|trans }}</span>
{% endif %}
{% if person.mobilenumber is not empty %}
<span><i class="fa fa-mobile"></i> <a href="tel:{{ person.mobilenumber }}">{{ person.mobilenumber|chill_format_phonenumber }}</a></span>
{% endif %}
{% if person.phonenumber is not empty %}
<span><i class="fa fa-phone"></i> <a href="tel:{{ person.phonenumber }}">{{ person.phonenumber|chill_format_phonenumber }}</a></span>
{% endif %}
<span>
</div>
</div>
{#- 'apps' is for AccompanyingPeriodParticipationS #}
{#- filter using acl -#}
{%- set apps = [] %}
{%- for app in person.openedParticipations %}
{%- if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_SEE', app.accompanyingPeriod) %}
{%- set apps = apps|merge([app]) %}
{%- endif %}
{%- endfor %}
{% if apps|length > 0 %}
<ul class="person-list--with-period__item__periods">
{% for app in apps %}
<li>
<a href="{{ path('chill_person_accompanying_course_index', { 'accompanying_period_id': app.accompanyingPeriod.id }) }}">
<i class="fa fa-random"></i>
<span>{{ 'Since %date%'|trans({'%date%': app.startDate|format_date('medium') }) }}</span>
{% if app.accompanyingPeriod.user is not null %}
<span>
{{ app.accompanyingPeriod.user|chill_entity_render_box }}
</span>
</a>
{% endif %}
{% for issue in app.accompanyingPeriod.socialIssues|slice(0,2) %}
<span>{{ issue|chill_entity_render_box }}</span>
{% endfor %}
{% if app.accompanyingPeriod.socialIssues|length > 2 %}
<span>{{ 'and %number% other'|transchoice(app.accompanyingPeriod.socialIssues|length-2) }}</span>
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
</div>
{% endfor %}
</div>
{#
<table>
<thead>
<tr>
<th class="chill-red">{% trans %}Name{% endtrans %}</th>
<th class="chill-green">{% trans %}Date of birth{% endtrans %}</th>
<th class="chill-orange">{% trans %}Nationality{% endtrans %}</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
{% for person in persons %}
<tr>
<td>
{% set is_open = person.isOpen() %}
<a href="{{ path('chill_person_view', { person_id : person.getId }) }}" {% if chill_person.fields.accompanying_period == 'visible' %}{% if is_open %} alt="{{ 'An accompanying period is open'|trans|e('html_attr') }}"{% else %} alt="{{ 'Any accompanying periods are open'|trans|e('html_attr') }}" {% endif %}{% endif %}>
{{ person|chill_entity_render_box }}
{% apply spaceless %}
{% if chill_person.fields.accompanying_period == 'visible' %}
{% if is_open == false %}
<i class="fa fa-lock" ></i>
{% else %}
<i class="fa fa-unlock" ></i>
{% endif %}
{% endif %}
{% endapply %}
</a>
</td>
<td>
{% if person.birthdate is not null %}
{{ person.birthdate|format_date('long') }}
{% else %}{{ 'Unknown date of birth'|trans }}{% endif %}
</td>
<td>
{% if person.nationality is not null %}
{{person.nationality.name | localize_translatable_string }}
{% else %}
{{ 'Without nationality'|trans }}
{% endif %}
</td>
<td>
<ul class="record_actions">
<li><a class="sc-button bt-show" href="{{ path('chill_person_view', { person_id : person.getId }) }}"></a></li>
{% if is_granted('CHILL_PERSON_UPDATE', person) %}
<li><a class="sc-button bt-update" href="{{ path('chill_person_general_edit', { person_id : person.getId }) }}"></a></li>
{% endif %}
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
#}
<ul class="record_actions">
{% if is_granted('CHILL_PERSON_CREATE') %}
<li>
<a href="{{ path('chill_person_new') }}" class="sc-button bt-create">
{{ 'Add a person'|trans }}
</a>
</li>
{% endif %}
{% if search_name != "person_similarity" %}
<li>
<a href="{{ path('chill_main_advanced_search', { "name": search_name, "q": pattern } ) }}" class="sc-button bt-action">
<i class="fa fa-search" aria-hidden="true"></i> {{ 'Advanced search'|trans }}
</a>
</li>
{% endif %}
{% if preview == true and persons|length < total %}
<li>
<a href="{{ path('chill_main_search', { "name": search_name|default('abcd'), "q" : pattern }) }}" class="sc-button">
{{ 'See all results'|trans }}
</a>
</li>
{% endif %}
</ul>
{% else %}
<ul class="record_actions">
<li>
<a href="{{ path('chill_main_advanced_search', { "name": search_name, "q": pattern } ) }}" class="sc-button bt-action">
<i class="fa fa-search" aria-hidden="true"></i> {{ 'Advanced search'|trans }}
</a>
</li>
</ul>
{% endif %}
{% if preview == false %}
{{ chill_pagination(paginator) }}
{% endif %}

View File

@ -120,7 +120,7 @@ class PersonSearch extends AbstractSearch implements ContainerAwareInterface,
$paginator = $this->paginatorFactory->create($total);
if ($format === 'html') {
return $this->container->get('templating')->render('ChillPersonBundle:Person:list.html.twig',
return $this->container->get('templating')->render('@ChillPerson/Person/list_with_period.html.twig',
array(
'persons' => $this->search($terms, $start, $limit, $options),
'pattern' => $this->recomposePattern($terms, array('nationality',

View File

@ -5,10 +5,12 @@ namespace Chill\PersonBundle\Templating\Entity;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Component\Templating\EngineInterface;
class SocialIssueRender implements ChillEntityRenderInterface
{
private TranslatableStringHelper $translatableStringHelper;
private EngineInterface $engine;
public const SEPARATOR_KEY = 'default.separator';
@ -16,14 +18,15 @@ class SocialIssueRender implements ChillEntityRenderInterface
self::SEPARATOR_KEY => ' > ',
];
public function __construct(TranslatableStringHelper $translatableStringHelper)
public function __construct(TranslatableStringHelper $translatableStringHelper, EngineInterface $engine)
{
$this->translatableStringHelper = $translatableStringHelper;
$this->engine = $engine;
}
public function supports($entity, array $options): bool
{
return $entity instanceof SocialIssueRender;
return $entity instanceof SocialIssue;
}
public function renderString($socialIssue, array $options): string
@ -42,9 +45,27 @@ class SocialIssueRender implements ChillEntityRenderInterface
return $str;
}
public function renderBox($entity, array $options): string
protected function buildParents($socialIssue): array
{
return "renderBox not implemented for social issue";
$parents = [];
while ($socialIssue->hasParent()) {
$socialIssue = $parents[] = $socialIssue->getParent();
}
return $parents;
}
public function renderBox($socialIssue, array $options): string
{
$options = \array_merge(self::DEFAULT_ARGS, $options);
// give some help to twig: an array of parents
$parents = $this->buildParents($socialIssue);
return $this->engine->render('@ChillPerson/Entity/social_issue.html.twig', [
'socialIssue' => $socialIssue,
'parents' => $parents,
'options' => $options
]);
}
}

View File

@ -17,3 +17,6 @@ services:
Chill\PersonBundle\Templating\Entity\SocialIssueRender:
arguments:
$translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper'
$engine: '@Symfony\Component\Templating\EngineInterface'
tags:
- 'chill.render_entity'

View File

@ -46,7 +46,7 @@ Add new phone: Ajouter un numéro de téléphone
Remove phone: Supprimer
'Notes on contact information': 'Remarques sur les informations de contact'
'Remarks': 'Remarques'
'{0} Born the %date% | {1} Born the %date%': '{0} Né le %date% | {1} Née le %date%'
'Born the %date%': '{0} Né le %date% | {1} Née le %date%'
'Spoken languages': 'Langues parlées'
'Unknown spoken languages': 'Langues parlées inconnues'
Male: Homme
@ -125,6 +125,8 @@ Reset: 'Remise à zéro'
'Person search results': 'Recherche de personnes'
Person search results by phonenumber: Recherche de personnes par numéro de téléphone
'Search within persons': 'Recherche parmi les personnes'
Open person file: Ouvrir le dossier
and %number% other: '{0} et aucun autre| {1} et une autre |]1, Inf] et %number% autres'
'%total% persons matching the search pattern:': '{0} Aucune personne ne correspond aux termes de recherche : | {1} Une personne a été trouvée par la recherche : | ]1,Inf] %total% personnes correspondent aux termes de recherche :'
'Last opening since %last_opening%': 'Dernière ouverture le %last_opening%.'
'Person accompanying period - %name%': 'Historique du dossier - %name%'