[person] Feature: add a person's center history

The association between Person and Center is now stored in a dedicated
Entity: `PersonCenterHistory`, which have a date interval (start date
and endDate). The SQL counterpart is a table, with a constraint which
ensure that no person might be associated with two center at the same time.

For ease, a view is created to get the current center associated with
the person.

The dedicated migration creates also:

* indexes for a rapid search for person at current date;
* and populate the table from current data, setting the startdate to the
  person's creation date and time if any, `NOW()` unless.

The `Person` entity is also updated to use the information from the
PersonCenterHistory classes, but this commit does not yet delete the
`Center` column.
This commit is contained in:
2022-09-26 21:11:01 +02:00
parent e3764f6f91
commit 49d2e98a1a
7 changed files with 468 additions and 3 deletions

View File

@@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Tests\Entity;
use Chill\MainBundle\Entity\Center;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Entity\Household\HouseholdMember;
@@ -191,4 +192,29 @@ final class PersonTest extends \PHPUnit\Framework\TestCase
$this->assertEquals($r['result'], Person::ERROR_ADDIND_PERIOD_AFTER_AN_OPEN_PERIOD);
}
public function testSetCenter()
{
$person = new Person();
$centerA = new Center();
$centerB = new Center();
$this->assertCount(0, $person->getCenterHistory());
$this->assertNull($person->getCenter());
$this->assertNull($person->getCenterCurrent());
$person->setCenter($centerA);
$this->assertCount(1, $person->getCenterHistory());
$this->assertSame($centerA, $person->getCenter());
$this->assertInstanceOf(Person\PersonCenterCurrent::class, $person->getCenterCurrent());
$this->assertSame($centerA, $person->getCenterCurrent()->getCenter());
$person->setCenter($centerB);
$this->assertCount(2, $person->getCenterHistory());
$this->assertSame($centerB, $person->getCenter());
$this->assertInstanceOf(Person\PersonCenterCurrent::class, $person->getCenterCurrent());
$this->assertSame($centerB, $person->getCenterCurrent()->getCenter());
}
}