mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Merge branch '_8_entity_parcours' into 'master'
WIP issue8 : entity parcours See merge request Chill-Projet/chill-bundles!8
This commit is contained in:
@@ -42,7 +42,6 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
* name="person_names",
|
||||
* columns={"firstName", "lastName"}
|
||||
* )})
|
||||
* sf4 check index name
|
||||
* @ORM\HasLifecycleCallbacks()
|
||||
*/
|
||||
class Person implements HasCenterInterface
|
||||
@@ -216,14 +215,13 @@ class Person implements HasCenterInterface
|
||||
|
||||
/**
|
||||
* The person's accompanying periods (when the person was accompanied by the center)
|
||||
* @var ArrayCollection
|
||||
* @var Collection
|
||||
*
|
||||
* @ORM\OneToMany(
|
||||
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod",
|
||||
* @ORM\OneToMany(targetEntity=AccompanyingPeriodParticipation::class,
|
||||
* mappedBy="person",
|
||||
* cascade={"persist", "remove", "merge", "detach"})
|
||||
*/
|
||||
private $accompanyingPeriods; //TO-CHANGE in accompanyingHistory
|
||||
private $accompanyingPeriodParticipations;
|
||||
|
||||
/**
|
||||
* A remark over the person
|
||||
@@ -275,7 +273,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();
|
||||
@@ -287,23 +285,54 @@ class Person implements HasCenterInterface
|
||||
|
||||
$this->open(new AccompanyingPeriod($opening));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param AccompanyingPeriod $accompanyingPeriod
|
||||
* @uses AccompanyingPeriod::setPerson
|
||||
* This private function scan accompanyingPeriodParticipations Collection,
|
||||
* searching for a given AccompanyingPeriod
|
||||
*/
|
||||
public function addAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod)
|
||||
private function participationsContainAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod): ?AccompanyingPeriodParticipation
|
||||
{
|
||||
$accompanyingPeriod->setPerson($this);
|
||||
$this->accompanyingPeriods->add($accompanyingPeriod);
|
||||
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
|
||||
{
|
||||
$participation = new AccompanyingPeriodParticipation($accompanyingPeriod, $this);
|
||||
$this->accompanyingPeriodParticipations->add($participation);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AccompanyingPeriod $accompanyingPeriod
|
||||
* Remove AccompanyingPeriod
|
||||
*/
|
||||
public function removeAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -315,10 +344,8 @@ class Person implements HasCenterInterface
|
||||
* For closing a file, @see this::close
|
||||
*
|
||||
* To check if the Person and its accompanying period is consistent, use validation.
|
||||
*
|
||||
* @param AccompanyingPeriod $accompanyingPeriod
|
||||
*/
|
||||
public function open(AccompanyingPeriod $accompanyingPeriod)
|
||||
public function open(AccompanyingPeriod $accompanyingPeriod) : void
|
||||
{
|
||||
$this->proxyAccompanyingPeriodOpenState = true;
|
||||
$this->addAccompanyingPeriod($accompanyingPeriod);
|
||||
@@ -332,28 +359,26 @@ class Person implements HasCenterInterface
|
||||
*
|
||||
* To check if the Person and its accompanying period are consistent, use validation.
|
||||
*
|
||||
* @param accompanyingPeriod
|
||||
* @throws \Exception if two lines of the accompanying period are open.
|
||||
*/
|
||||
public function close(AccompanyingPeriod $accompanyingPeriod = null)
|
||||
public function close(AccompanyingPeriod $accompanyingPeriod = null) : void
|
||||
{
|
||||
$this->proxyAccompanyingPeriodOpenState = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the opened accompanying period.
|
||||
*
|
||||
* @return AccompanyingPeriod
|
||||
*/
|
||||
public function getOpenedAccompanyingPeriod()
|
||||
public function getOpenedAccompanyingPeriod() : AccompanyingPeriod
|
||||
{
|
||||
if ($this->isOpen() === false) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -361,31 +386,41 @@ class Person implements HasCenterInterface
|
||||
/**
|
||||
* Returns the opened accompanying period.
|
||||
*
|
||||
* @return AccompanyingPeriod
|
||||
* @deprecated since 1.1 use `getOpenedAccompanyingPeriod instead
|
||||
*/
|
||||
public function getCurrentAccompanyingPeriod()
|
||||
public function getCurrentAccompanyingPeriod() : AccompanyingPeriod
|
||||
{
|
||||
return $this->getOpenedAccompanyingPeriod();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ArrayCollection
|
||||
* Get AccompanyingPeriods array
|
||||
*/
|
||||
public function getAccompanyingPeriods()
|
||||
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.
|
||||
*
|
||||
* @return AccompanyingPeriod[]
|
||||
* Get the accompanying periods of a give person with the chronological order.
|
||||
*/
|
||||
public function getAccompanyingPeriodsOrdered()
|
||||
public function getAccompanyingPeriodsOrdered(): array
|
||||
{
|
||||
$periods = $this->getAccompanyingPeriods()->toArray();
|
||||
$periods = $this->getAccompanyingPeriods();
|
||||
|
||||
//order by date :
|
||||
usort($periods, function($a, $b) {
|
||||
@@ -418,11 +453,9 @@ class Person implements HasCenterInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the person is opened
|
||||
*
|
||||
* @return boolean
|
||||
* Check if the person is opened
|
||||
*/
|
||||
public function isOpen()
|
||||
public function isOpen() : bool
|
||||
{
|
||||
foreach ($this->getAccompanyingPeriods() as $period) {
|
||||
if ($period->isOpen()) {
|
||||
@@ -1109,4 +1142,15 @@ class Person implements HasCenterInterface
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getFullnameCanonical() : string
|
||||
{
|
||||
return $this->fullnameCanonical;
|
||||
}
|
||||
|
||||
public function setFullnameCanonical($fullnameCanonical) : Person
|
||||
{
|
||||
$this->fullnameCanonical = $fullnameCanonical;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user