mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-30 03:23:48 +00:00
fix cs
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -182,21 +183,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.
|
||||
*
|
||||
@@ -910,32 +913,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) {
|
||||
@@ -949,6 +926,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) {
|
||||
@@ -1562,7 +1557,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
|
||||
@@ -1582,40 +1576,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
|
||||
*/
|
||||
@@ -1818,6 +1785,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.
|
||||
|
Reference in New Issue
Block a user