mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Adapt entity AccompanyingPeriodParticipation attributes and methods (dont break UI)
This commit is contained in:
@@ -35,7 +35,7 @@ use Chill\MainBundle\Entity\User;
|
||||
/**
|
||||
* AccompanyingPeriod Class
|
||||
*
|
||||
* @ORM\Entity(repositoryClass=AccompanyingPeriodRepository::class)
|
||||
* @ORM\Entity(repositoryClass="Chill\PersonBundle\Repository\AccompanyingPeriodRepository")
|
||||
* @ORM\Table(name="chill_person_accompanying_period")
|
||||
*/
|
||||
class AccompanyingPeriod
|
||||
@@ -79,9 +79,10 @@ class AccompanyingPeriod
|
||||
* @var Collection
|
||||
*
|
||||
* @ORM\OneToMany(targetEntity=AccompanyingPeriodParticipation::class,
|
||||
* mappedBy="accompanyingPeriod")
|
||||
* mappedBy="accompanyingPeriod",
|
||||
* cascade={"persist", "remove", "merge", "detach"})
|
||||
*/
|
||||
private $persons;
|
||||
private $participations;
|
||||
|
||||
/**
|
||||
* @var AccompanyingPeriod\ClosingMotive
|
||||
@@ -175,7 +176,7 @@ class AccompanyingPeriod
|
||||
*/
|
||||
public function __construct(\DateTime $dateOpening) {
|
||||
$this->setOpeningDate($dateOpening);
|
||||
$this->persons = new ArrayCollection();
|
||||
$this->participations = new ArrayCollection();
|
||||
$this->scopes = new ArrayCollection();
|
||||
}
|
||||
|
||||
@@ -280,37 +281,63 @@ class AccompanyingPeriod
|
||||
{
|
||||
return $this->remark;
|
||||
}
|
||||
|
||||
public function getPersons(): Collection
|
||||
{
|
||||
return $this->persons;
|
||||
}
|
||||
|
||||
public function containsPerson(Person $person): bool
|
||||
/**
|
||||
* Get Participations Collection
|
||||
*/
|
||||
public function getParticipations(): Collection
|
||||
{
|
||||
foreach ($this->persons as $p) {
|
||||
if ($p === $person) { return true; }
|
||||
}
|
||||
|
||||
return false;
|
||||
return $this->participations;
|
||||
}
|
||||
|
||||
/**
|
||||
* For consistency, you should use Person::addAccompanyingPeriod instead.
|
||||
* @see Person::addAccompanyingPeriod
|
||||
* This private function scan Participations Collection,
|
||||
* searching for a given Person
|
||||
*/
|
||||
private function participationsContainsPerson(Person $person): ?AccompanyingPeriodParticipation
|
||||
{
|
||||
foreach ($this->participations as $participation) {
|
||||
/** @var AccompanyingPeriodParticipation $participation */
|
||||
if ($person === $participation->getPerson()) {
|
||||
return $participation;
|
||||
}}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This public function is the same but return only true or false
|
||||
*/
|
||||
public function containsPerson(Person $person): bool
|
||||
{
|
||||
return ($this->participationsContainsPerson($person) === null) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Person
|
||||
*/
|
||||
public function addPerson(Person $person = null): self
|
||||
{
|
||||
$this->persons[] = $person;
|
||||
$participation = new AccompanyingPeriodParticipation($this, $person);
|
||||
$this->participations[] = $participation;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Person
|
||||
*/
|
||||
public function removePerson(Person $person): void
|
||||
{
|
||||
$this->persons->removeElement($person);
|
||||
$participation = $this->participationsContainsPerson($person);
|
||||
|
||||
if (! null === $participation) {
|
||||
$participation->setEndDate(new \DateTimeImmutable('now'));
|
||||
$this->participations->removeElement($participation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getClosingMotive(): ?ClosingMotive
|
||||
{
|
||||
return $this->closingMotive;
|
||||
@@ -335,11 +362,12 @@ class AccompanyingPeriod
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($this->getPersons() as $p) {
|
||||
if ($p === $person) {
|
||||
$periods = $p->getAccompanyingPeriodsOrdered();
|
||||
return end($periods) === $this;
|
||||
}
|
||||
$participation = $this->participationsContainsPerson($person);
|
||||
if (!null === $participation)
|
||||
{
|
||||
$person = $participation->getPerson();
|
||||
$periods = $person->getAccompanyingPeriodsOrdered();
|
||||
return end($periods) === $this;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user