mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Adapt entity AccompanyingPeriodParticipation attributes and methods (dont break UI)
This commit is contained in:
@@ -209,7 +209,7 @@ class Person implements HasCenterInterface
|
||||
* mappedBy="person",
|
||||
* cascade={"persist", "remove", "merge", "detach"})
|
||||
*/
|
||||
private $accompanyingPeriods;
|
||||
private $accompanyingPeriodParticipations;
|
||||
|
||||
/**
|
||||
* A remark over the person
|
||||
@@ -262,7 +262,7 @@ class Person implements HasCenterInterface
|
||||
*/
|
||||
public function __construct(\DateTime $opening = null)
|
||||
{
|
||||
$this->accompanyingPeriods = new ArrayCollection();
|
||||
$this->accompanyingPeriodParticipations = new ArrayCollection();
|
||||
$this->spokenLanguages = new ArrayCollection();
|
||||
$this->addresses = new ArrayCollection();
|
||||
$this->altNames = new ArrayCollection();
|
||||
@@ -273,16 +273,39 @@ class Person implements HasCenterInterface
|
||||
|
||||
$this->open(new AccompanyingPeriod($opening));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add AccompanyingPeriod
|
||||
* This private function scan accompanyingPeriodParticipations Collection,
|
||||
* searching for a given AccompanyingPeriod
|
||||
*/
|
||||
private function participationsContainAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod): ?AccompanyingPeriodParticipation
|
||||
{
|
||||
foreach ($this->accompanyingPeriodParticipations as $participation) {
|
||||
/** @var AccompanyingPeriodParticipation $participation */
|
||||
if ($accompanyingPeriod === $participation->getAccompanyingPeriod()) {
|
||||
return $participation;
|
||||
}}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This public function is the same but return only true or false
|
||||
*/
|
||||
public function containsAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod): bool
|
||||
{
|
||||
return ($this->participationsContainAccompanyingPeriod($accompanyingPeriod)) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add AccompanyingPeriodParticipation
|
||||
*
|
||||
* @uses AccompanyingPeriod::addPerson
|
||||
*/
|
||||
public function addAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod): self
|
||||
{
|
||||
$accompanyingPeriod->addPerson($this);
|
||||
$this->accompanyingPeriods->add($accompanyingPeriod);
|
||||
$participation = new AccompanyingPeriodParticipation($accompanyingPeriod, $this);
|
||||
$this->accompanyingPeriodParticipations->add($participation);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -292,7 +315,12 @@ class Person implements HasCenterInterface
|
||||
*/
|
||||
public function removeAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod) : void
|
||||
{
|
||||
$this->accompanyingPeriods->remove($accompanyingPeriod);
|
||||
$participation = $this->participationsContainAccompanyingPeriod($accompanyingPeriod);
|
||||
|
||||
if (! null === $participation) {
|
||||
$participation->setEndDate(\DateTimeImmutable::class);
|
||||
$this->accompanyingPeriodParticipations->removeElement($participation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -335,9 +363,10 @@ class Person implements HasCenterInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($this->accompanyingPeriods as $period) {
|
||||
if ($period->isOpen()) {
|
||||
return $period;
|
||||
foreach ($this->accompanyingPeriodParticipations as $participation) {
|
||||
/** @var AccompanyingPeriodParticipation $participation */
|
||||
if ($participation->getAccompanyingPeriod()->isOpen()) {
|
||||
return $participation->getAccompanyingPeriod();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -353,19 +382,33 @@ class Person implements HasCenterInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get AccompanyingPeriods Collection
|
||||
* Get AccompanyingPeriods array
|
||||
*/
|
||||
public function getAccompanyingPeriods() : Collection
|
||||
public function getAccompanyingPeriods(): array
|
||||
{
|
||||
return $this->accompanyingPeriods;
|
||||
$accompanyingPeriods = [];
|
||||
foreach ($this->accompanyingPeriodParticipations as $participation)
|
||||
{
|
||||
/** @var AccompanyingPeriodParticipation $participation */
|
||||
$accompanyingPeriods[] = $participation->getAccompanyingPeriod();
|
||||
}
|
||||
return $accompanyingPeriods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get AccompanyingPeriodParticipations Collection
|
||||
*/
|
||||
public function getAccompanyingPeriodParticipations(): Collection
|
||||
{
|
||||
return $this->accompanyingPeriodParticipations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the accompanying periods of a give person with the chronological order.
|
||||
*/
|
||||
public function getAccompanyingPeriodsOrdered() : array
|
||||
public function getAccompanyingPeriodsOrdered(): array
|
||||
{
|
||||
$periods = $this->getAccompanyingPeriods()->toArray();
|
||||
$periods = $this->getAccompanyingPeriods();
|
||||
|
||||
//order by date :
|
||||
usort($periods, function($a, $b) {
|
||||
@@ -504,7 +547,7 @@ class Person implements HasCenterInterface
|
||||
* @param PersonAltName $altName
|
||||
* @return $this
|
||||
*/
|
||||
public function removeAltName(PersonAltName $altName)
|
||||
public function removeAltName(PersonAltName $altName)
|
||||
{
|
||||
if ($this->altNames->contains($altName)) {
|
||||
$altName->setPerson(null);
|
||||
|
Reference in New Issue
Block a user