Merge branch '111_exports_suite' into testing

This commit is contained in:
2022-10-05 15:28:51 +02:00
194 changed files with 1581 additions and 1387 deletions

View File

@@ -46,6 +46,7 @@ use libphonenumber\PhoneNumber;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use UnexpectedValueException;
use function count;
use function in_array;
@@ -190,21 +191,23 @@ 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;
/**
* @ORM\OneToMany(targetEntity=PersonCenterHistory::class, mappedBy="person", cascade={"persist"})
*
* @var Collection|PersonCenterHistory[]
*/
private Collection $centerHistory;
/**
* Array where customfield's data are stored.
*
@@ -918,32 +921,6 @@ 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
{
if (null !== $this->centerCurrent) {
@@ -957,6 +934,24 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $currentCenterHistory->getCenter();
}
public function getCenterCurrent(): ?PersonCenterCurrent
{
if (null !== $this->centerCurrent) {
return $this->centerCurrent;
}
if (null === $currentCenterHistory = $this->getCurrentCenterHistory()) {
return null;
}
return new PersonCenterCurrent($currentCenterHistory);
}
public function getCenterHistory(): Collection
{
return $this->centerHistory;
}
public function getCFData(): ?array
{
if (null === $this->cFData) {
@@ -1570,7 +1565,6 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
/**
* Associate the center with the person. The association start on 'now'.
*
* @param Center $center
* @return $this
*/
public function setCenter(Center $center): self
@@ -1590,40 +1584,13 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this;
}
/**
* @return Collection
*/
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
*/
@@ -1826,6 +1793,34 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
return $this;
}
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');
}
}
/**
* This private function scan accompanyingPeriodParticipations Collection,
* searching for a given AccompanyingPeriod.