mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-30 03:23:48 +00:00
Merge branch '111_exports_suite' into testing
This commit is contained in:
@@ -27,6 +27,8 @@ use Chill\MainBundle\Validation\Constraint\PhonenumberConstraint;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
||||
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
|
||||
use Chill\PersonBundle\Entity\Person\PersonCenterCurrent;
|
||||
use Chill\PersonBundle\Entity\Person\PersonCenterHistory;
|
||||
use Chill\PersonBundle\Entity\Person\PersonCurrentAddress;
|
||||
use Chill\PersonBundle\Entity\Person\PersonResource;
|
||||
use Chill\PersonBundle\Validator\Constraints\Household\HouseholdMembershipSequential;
|
||||
@@ -188,9 +190,21 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
||||
* The person's center.
|
||||
*
|
||||
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Center")
|
||||
* @deprecated
|
||||
*/
|
||||
private ?Center $center = null;
|
||||
|
||||
/**
|
||||
* @ORM\OneToMany(targetEntity=PersonCenterHistory::class, mappedBy="person", cascade={"persist"})
|
||||
* @var Collection|PersonCenterHistory[]
|
||||
*/
|
||||
private Collection $centerHistory;
|
||||
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity=PersonCenterCurrent::class, mappedBy="person")
|
||||
*/
|
||||
private ?PersonCenterCurrent $centerCurrent = null;
|
||||
|
||||
/**
|
||||
* Array where customfield's data are stored.
|
||||
*
|
||||
@@ -531,6 +545,7 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
||||
$this->budgetResources = new ArrayCollection();
|
||||
$this->budgetCharges = new ArrayCollection();
|
||||
$this->resources = new ArrayCollection();
|
||||
$this->centerHistory = new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -903,9 +918,43 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
||||
return $this->budgetResources;
|
||||
}
|
||||
|
||||
private function getCurrentCenterHistory(): ?PersonCenterHistory
|
||||
{
|
||||
if (0 === $this->centerHistory->count()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$criteria = Criteria::create();
|
||||
$now = new DateTimeImmutable('now');
|
||||
$criteria->where(Criteria::expr()->lte('startDate', $now))
|
||||
->andWhere(Criteria::expr()->orX(
|
||||
Criteria::expr()->isNull('endDate'),
|
||||
Criteria::expr()->gt('endDate', $now)
|
||||
));
|
||||
|
||||
$histories = $this->centerHistory->matching($criteria);
|
||||
|
||||
switch ($histories->count()) {
|
||||
case 0:
|
||||
return null;
|
||||
case 1:
|
||||
return $histories->first();
|
||||
default:
|
||||
throw new \UnexpectedValueException('It should not contains more than one center at a time');
|
||||
}
|
||||
}
|
||||
|
||||
public function getCenter(): ?Center
|
||||
{
|
||||
return $this->center;
|
||||
if (null !== $this->centerCurrent) {
|
||||
return $this->centerCurrent->getCenter();
|
||||
}
|
||||
|
||||
if (null === $currentCenterHistory = $this->getCurrentCenterHistory()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $currentCenterHistory->getCenter();
|
||||
}
|
||||
|
||||
public function getCFData(): ?array
|
||||
@@ -1518,17 +1567,67 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Associate the center with the person. The association start on 'now'.
|
||||
*
|
||||
* @param Center $center
|
||||
* @return $this
|
||||
*/
|
||||
public function setCenter(Center $center): self
|
||||
{
|
||||
$this->center = $center;
|
||||
|
||||
$modification = new DateTimeImmutable('now');
|
||||
|
||||
foreach ($this->centerHistory as $centerHistory) {
|
||||
if (null === $centerHistory->getEndDate()) {
|
||||
$centerHistory->setEndDate($modification);
|
||||
}
|
||||
}
|
||||
|
||||
$this->centerHistory[] = $new = new PersonCenterHistory($this, $center, $modification);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Report
|
||||
* @return Collection
|
||||
*/
|
||||
public function setCFData(?array $cFData)
|
||||
public function getCenterHistory(): Collection
|
||||
{
|
||||
return $this->centerHistory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $centerHistory
|
||||
* @return Person
|
||||
*/
|
||||
public function setCenterHistory(Collection $centerHistory): Person
|
||||
{
|
||||
$this->centerHistory = $centerHistory;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PersonCenterCurrent|null
|
||||
*/
|
||||
public function getCenterCurrent(): ?PersonCenterCurrent
|
||||
{
|
||||
if (null !== $this->centerCurrent) {
|
||||
return $this->centerCurrent;
|
||||
}
|
||||
|
||||
if (null === $currentCenterHistory = $this->getCurrentCenterHistory()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new PersonCenterCurrent($currentCenterHistory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Person
|
||||
*/
|
||||
public function setCFData(?array $cFData): self
|
||||
{
|
||||
$this->cFData = $cFData;
|
||||
|
||||
|
Reference in New Issue
Block a user