mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
[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:
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Entity\Person;
|
||||
|
||||
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
|
||||
use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
|
||||
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
||||
use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Associate a Person with the current center.
|
||||
*
|
||||
* The process of selecting the current center is done on database side,
|
||||
* using a SQL view.
|
||||
*
|
||||
* @ORM\Entity(readOnly=true)
|
||||
* @ORM\Table(name="view_chill_person_person_center_history_current")
|
||||
* @psalm-internal Chill\PersonBundle\Entity
|
||||
*/
|
||||
class PersonCenterCurrent
|
||||
{
|
||||
/**
|
||||
* @ORM\Id
|
||||
* @ORM\Column(type="integer")
|
||||
*/
|
||||
private ?int $id = null;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=Person::class, inversedBy="centerCurrent")
|
||||
*/
|
||||
private Person $person;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity=Center::class)
|
||||
*/
|
||||
private Center $center;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="date_immutable", nullable=false)
|
||||
*/
|
||||
private \DateTimeImmutable $startDate;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
|
||||
*/
|
||||
private ?\DateTimeImmutable $endDate = null;
|
||||
|
||||
/**
|
||||
* Populate the properties person, center, start and end date from history.
|
||||
*
|
||||
* The creator and updatedby are not filled.
|
||||
*
|
||||
* @internal Should not be instantied, unless inside Person entity
|
||||
* @param PersonCenterHistory $history
|
||||
*/
|
||||
public function __construct(PersonCenterHistory $history)
|
||||
{
|
||||
$this->person = $history->getPerson();
|
||||
$this->center = $history->getCenter();
|
||||
$this->startDate = $history->getStartDate();
|
||||
$this->endDate = $history->getEndDate();
|
||||
$this->id = $history->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* The id will be the same as the current @link{PersonCenterHistory::class}
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Person
|
||||
*/
|
||||
public function getPerson(): Person
|
||||
{
|
||||
return $this->person;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Center
|
||||
*/
|
||||
public function getCenter(): Center
|
||||
{
|
||||
return $this->center;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTimeImmutable
|
||||
*/
|
||||
public function getStartDate(): \DateTimeImmutable
|
||||
{
|
||||
return $this->startDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTimeImmutable|null
|
||||
*/
|
||||
public function getEndDate(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->endDate;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user