Show alt names in person search results

This commit is contained in:
Julien Fastré 2021-11-05 12:52:31 +00:00
parent 74df496e38
commit 5111a0ff6a
6 changed files with 72 additions and 95 deletions

View File

@ -21,6 +21,9 @@ and this project adheres to
* refactor `AuthorizationHelper` and `UserACLAwareRepository` to fix constructor, and separate logic for parent role helper into `ParentRoleHelper` * refactor `AuthorizationHelper` and `UserACLAwareRepository` to fix constructor, and separate logic for parent role helper into `ParentRoleHelper`
* [main]: filter location and locationType in backend: exclude NULL names, only active and availableToUsers * [main]: filter location and locationType in backend: exclude NULL names, only active and availableToUsers
* [activity]: perform client-side validation & show/hide fields in the "new location" modal * [activity]: perform client-side validation & show/hide fields in the "new location" modal
* [person] show current address in search results
* [person] show alt names in search results
* [admin]: links to activity admin section added again.
* [tasks]: different layout for task list / my tasks, and fix link to tasks in alert or in warning * [tasks]: different layout for task list / my tasks, and fix link to tasks in alert or in warning
* [admin]: links to activity admin section added again. * [admin]: links to activity admin section added again.
* [household]: household addresses ordered by ValidFrom date and by id to show the last created address on top. * [household]: household addresses ordered by ValidFrom date and by id to show the last created address on top.

View File

@ -83,6 +83,10 @@
{% endmacro %} {% endmacro %}
{#
this enclose the rendering inside a "li", which ease the placement operation when the address
must be shown in such list
#}
{%- if render == 'list' -%} {%- if render == 'list' -%}
<li class="chill-entity entity-address"> <li class="chill-entity entity-address">
{% if options['with_picto'] %} {% if options['with_picto'] %}

View File

@ -1283,11 +1283,14 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/** /**
* get the address associated with the person at the given date * get the address associated with the person at the given date
* *
* If the `$at` parameter is now, use the method `getCurrentPersonAddress`, which is optimized
* on database side.
*
* @param DateTime|null $at * @param DateTime|null $at
* @return Address|null * @return Address|null
* @throws \Exception * @throws \Exception
*/ */
public function getCurrentPersonAddress(?\DateTime $at = null): ?Address public function getAddressAt(?\DateTime $at = null): ?Address
{ {
$at ??= new DateTime('now'); $at ??= new DateTime('now');
@ -1305,6 +1308,20 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
current($addresses); current($addresses);
} }
/**
* Get the current person address
*
* @return Address|null
*/
public function getCurrentPersonAddress(): ?Address
{
if (null === $this->currentPersonAddress) {
return null;
}
return $this->currentPersonAddress->getAddress();
}
/** /**
* Validation callback that checks if the accompanying periods are valid * Validation callback that checks if the accompanying periods are valid
* *

View File

@ -67,7 +67,7 @@
{%- endif -%} {%- endif -%}
</div> </div>
{%- if options['addInfo'] -%} {%- if options['addInfo'] -%}
{% set gender = (person.gender == 'woman') ? 'fa-venus' : {% set gender = (person.gender == 'woman') ? 'fa-venus' :
(person.gender == 'man') ? 'fa-mars' : (person.gender == 'neuter') ? 'fa-neuter' : 'fa-genderless' %} (person.gender == 'man') ? 'fa-mars' : (person.gender == 'neuter') ? 'fa-neuter' : 'fa-genderless' %}
{% set genderTitle = (person.gender == 'woman') ? 'woman' : {% set genderTitle = (person.gender == 'woman') ? 'woman' :
(person.gender == 'man') ? 'man' : (person.gender == 'neuter') ? 'neuter' : 'Not given'|trans %} (person.gender == 'man') ? 'man' : (person.gender == 'neuter') ? 'neuter' : 'Not given'|trans %}
@ -123,13 +123,15 @@
</div> </div>
<div class="item-col"> <div class="item-col">
<ul class="list-content fa-ul"> <ul class="list-content fa-ul">
{% set multiline = (options['address_multiline']) ? true : false %} {% if person.getCurrentPersonAddress is not null %}
{{ person.getLastAddress|chill_entity_render_box({ {% set multiline = (options['address_multiline']) ? true : false %}
'render': 'list', {{ person.getCurrentPersonAddress|chill_entity_render_box({
'with_picto': true, 'render': 'list',
'multiline': multiline, 'with_picto': true,
'with_valid_from': false 'multiline': multiline,
}) }} 'with_valid_from': false
}) }}
{% endif %}
<li> <li>
{% if person.mobilenumber %} {% if person.mobilenumber %}
<i class="fa fa-li fa-mobile"></i><a href="{{ 'tel:' ~ person.mobilenumber }}"> <i class="fa fa-li fa-mobile"></i><a href="{{ 'tel:' ~ person.mobilenumber }}">

View File

@ -53,7 +53,7 @@
'addLink': true, 'addLink': true,
'addInfo': true, 'addInfo': true,
'addAge': true, 'addAge': true,
'addAltNames': false, 'addAltNames': true,
'addCenter': true, 'addCenter': true,
'address_multiline': false, 'address_multiline': false,
'customButtons': { 'after': _self.button_person(person) } 'customButtons': { 'after': _self.button_person(person) }

View File

@ -2,8 +2,8 @@
/* /*
* Chill is a software for social workers * Chill is a software for social workers
* *
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS, * Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop> * <http://www.champs-libres.coop>, <info@champs-libres.coop>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -38,57 +38,57 @@ use Generator;
class PersonTest extends \PHPUnit\Framework\TestCase class PersonTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* Test the creation of an accompanying, its closure and the access to * Test the creation of an accompanying, its closure and the access to
* the current accompaniying period via the getCurrentAccompanyingPeriod * the current accompaniying period via the getCurrentAccompanyingPeriod
* function. * function.
*/ */
public function testGetCurrentAccompanyingPeriod() public function testGetCurrentAccompanyingPeriod()
{ {
$d = new \DateTime('yesterday'); $d = new \DateTime('yesterday');
$p = new Person(); $p = new Person();
$p->addAccompanyingPeriod(new AccompanyingPeriod($d)); $p->addAccompanyingPeriod(new AccompanyingPeriod($d));
$period = $p->getCurrentAccompanyingPeriod(); $period = $p->getCurrentAccompanyingPeriod();
$this->assertInstanceOf(AccompanyingPeriod::class, $period); $this->assertInstanceOf(AccompanyingPeriod::class, $period);
$this->assertTrue($period->isOpen()); $this->assertTrue($period->isOpen());
$this->assertEquals($d, $period->getOpeningDate()); $this->assertEquals($d, $period->getOpeningDate());
//close and test //close and test
$period->setClosingDate(new \DateTime('tomorrow')); $period->setClosingDate(new \DateTime('tomorrow'));
$shouldBeNull = $p->getCurrentAccompanyingPeriod(); $shouldBeNull = $p->getCurrentAccompanyingPeriod();
$this->assertNull($shouldBeNull); $this->assertNull($shouldBeNull);
} }
/** /**
* Test if the getAccompanyingPeriodsOrdered function return a list of * Test if the getAccompanyingPeriodsOrdered function return a list of
* periods ordered ascendency. * periods ordered ascendency.
*/ */
public function testAccompanyingPeriodOrderWithUnorderedAccompanyingPeriod() public function testAccompanyingPeriodOrderWithUnorderedAccompanyingPeriod()
{ {
$d = new \DateTime("2013/2/1"); $d = new \DateTime("2013/2/1");
$p = new Person(); $p = new Person();
$p->addAccompanyingPeriod(new AccompanyingPeriod($d)); $p->addAccompanyingPeriod(new AccompanyingPeriod($d));
$e = new \DateTime("2013/3/1"); $e = new \DateTime("2013/3/1");
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e); $period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
$p->close($period); $p->close($period);
$f = new \DateTime("2013/1/1"); $f = new \DateTime("2013/1/1");
$p->open(new AccompanyingPeriod($f)); $p->open(new AccompanyingPeriod($f));
$g = new \DateTime("2013/4/1"); $g = new \DateTime("2013/4/1");
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($g); $period = $p->getCurrentAccompanyingPeriod()->setClosingDate($g);
$p->close($period); $p->close($period);
$r = $p->getAccompanyingPeriodsOrdered(); $r = $p->getAccompanyingPeriodsOrdered();
$date = $r[0]->getOpeningDate()->format('Y-m-d'); $date = $r[0]->getOpeningDate()->format('Y-m-d');
$this->assertEquals($date, '2013-01-01'); $this->assertEquals($date, '2013-01-01');
} }
/** /**
* Test if the getAccompanyingPeriodsOrdered function, for periods * Test if the getAccompanyingPeriodsOrdered function, for periods
* starting at the same time order regarding to the closing date. * starting at the same time order regarding to the closing date.
@ -97,25 +97,25 @@ class PersonTest extends \PHPUnit\Framework\TestCase
$d = new \DateTime("2013/2/1"); $d = new \DateTime("2013/2/1");
$p = new Person(); $p = new Person();
$p->addAccompanyingPeriod(new AccompanyingPeriod($d)); $p->addAccompanyingPeriod(new AccompanyingPeriod($d));
$g = new \DateTime("2013/4/1"); $g = new \DateTime("2013/4/1");
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($g); $period = $p->getCurrentAccompanyingPeriod()->setClosingDate($g);
$p->close($period); $p->close($period);
$f = new \DateTime("2013/2/1"); $f = new \DateTime("2013/2/1");
$p->open(new AccompanyingPeriod($f)); $p->open(new AccompanyingPeriod($f));
$e = new \DateTime("2013/3/1"); $e = new \DateTime("2013/3/1");
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e); $period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
$p->close($period); $p->close($period);
$r = $p->getAccompanyingPeriodsOrdered(); $r = $p->getAccompanyingPeriodsOrdered();
$date = $r[0]->getClosingDate()->format('Y-m-d'); $date = $r[0]->getClosingDate()->format('Y-m-d');
$this->assertEquals($date, '2013-03-01'); $this->assertEquals($date, '2013-03-01');
} }
/** /**
* Test if the function checkAccompanyingPeriodIsNotCovering returns * Test if the function checkAccompanyingPeriodIsNotCovering returns
* the good constant when two periods are collapsing : a period * the good constant when two periods are collapsing : a period
@ -125,23 +125,23 @@ class PersonTest extends \PHPUnit\Framework\TestCase
$d = new \DateTime("2013/2/1"); $d = new \DateTime("2013/2/1");
$p = new Person(); $p = new Person();
$p->addAccompanyingPeriod(new AccompanyingPeriod($d)); $p->addAccompanyingPeriod(new AccompanyingPeriod($d));
$e = new \DateTime("2013/3/1"); $e = new \DateTime("2013/3/1");
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e); $period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
$p->close($period); $p->close($period);
$f = new \DateTime("2013/1/1"); $f = new \DateTime("2013/1/1");
$p->open(new AccompanyingPeriod($f)); $p->open(new AccompanyingPeriod($f));
$g = new \DateTime("2013/4/1"); $g = new \DateTime("2013/4/1");
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($g); $period = $p->getCurrentAccompanyingPeriod()->setClosingDate($g);
$p->close($period); $p->close($period);
$r = $p->checkAccompanyingPeriodsAreNotCollapsing(); $r = $p->checkAccompanyingPeriodsAreNotCollapsing();
$this->assertEquals($r['result'], Person::ERROR_PERIODS_ARE_COLLAPSING); $this->assertEquals($r['result'], Person::ERROR_PERIODS_ARE_COLLAPSING);
} }
/** /**
* Test if the function checkAccompanyingPeriodIsNotCovering returns * Test if the function checkAccompanyingPeriodIsNotCovering returns
* the good constant when two periods are collapsing : a period is open * the good constant when two periods are collapsing : a period is open
@ -151,68 +151,19 @@ class PersonTest extends \PHPUnit\Framework\TestCase
$d = new \DateTime("2013/2/1"); $d = new \DateTime("2013/2/1");
$p = new Person(); $p = new Person();
$p->addAccompanyingPeriod(new AccompanyingPeriod($d)); $p->addAccompanyingPeriod(new AccompanyingPeriod($d));
$e = new \DateTime("2013/3/1"); $e = new \DateTime("2013/3/1");
$period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e); $period = $p->getCurrentAccompanyingPeriod()->setClosingDate($e);
$p->close($period); $p->close($period);
$f = new \DateTime("2013/1/1"); $f = new \DateTime("2013/1/1");
$p->open(new AccompanyingPeriod($f)); $p->open(new AccompanyingPeriod($f));
$r = $p->checkAccompanyingPeriodsAreNotCollapsing(); $r = $p->checkAccompanyingPeriodsAreNotCollapsing();
$this->assertEquals($r['result'], Person::ERROR_ADDIND_PERIOD_AFTER_AN_OPEN_PERIOD); $this->assertEquals($r['result'], Person::ERROR_ADDIND_PERIOD_AFTER_AN_OPEN_PERIOD);
} }
public function dateProvider(): Generator
{
yield [(DateTime::createFromFormat('Y-m-d', '2021-01-05'))->settime(0, 0)];
yield [(DateTime::createFromFormat('Y-m-d', '2021-02-05'))->settime(0, 0)];
yield [(DateTime::createFromFormat('Y-m-d', '2021-03-05'))->settime(0, 0)];
}
/**
* @dataProvider dateProvider
*/
public function testGetLastAddress(DateTime $date)
{
$p = new Person($date);
// Make sure that there is no last address.
$this::assertNull($p->getLastAddress());
// Take an arbitrary date before the $date in parameter.
$addressDate = clone $date;
// 1. Smoke test: Test that the first address added is the last one.
$address1 = (new Address())->setValidFrom($addressDate->sub(new DateInterval('PT180M')));
$p->addAddress($address1);
$this::assertCount(1, $p->getAddresses());
$this::assertSame($address1, $p->getLastAddress());
// 2. Add an older address, which should not be the last address.
$addressDate2 = clone $addressDate;
$address2 = (new Address())->setValidFrom($addressDate2->sub(new DateInterval('PT30M')));
$p->addAddress($address2);
$this::assertCount(2, $p->getAddresses());
$this::assertSame($address1, $p->getLastAddress());
// 3. Add a newer address, which should be the last address.
$addressDate3 = clone $addressDate;
$address3 = (new Address())->setValidFrom($addressDate3->add(new DateInterval('PT30M')));
$p->addAddress($address3);
$this::assertCount(3, $p->getAddresses());
$this::assertSame($address3, $p->getLastAddress());
// 4. Get the last address from a specific date.
$this::assertEquals($address1, $p->getLastAddress($addressDate));
$this::assertEquals($address2, $p->getLastAddress($addressDate2));
$this::assertEquals($address3, $p->getLastAddress($addressDate3));
}
public function testIsSharingHousehold() public function testIsSharingHousehold()
{ {
$person = new Person(); $person = new Person();