Merge branch '_8_entity_parcours' into 'master'

WIP issue8 : entity parcours

See merge request Chill-Projet/chill-bundles!8
This commit is contained in:
2021-04-13 20:48:36 +00:00
31 changed files with 1814 additions and 346 deletions

View File

@@ -3,7 +3,7 @@
/*
* Chill is a software for social workers
*
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
* Copyright (C) 2014-2021, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
@@ -22,18 +22,28 @@
namespace Chill\PersonBundle\Entity;
use Chill\MainBundle\Entity\Scope;
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Chill\MainBundle\Entity\User;
/**
* AccompanyingPeriod
* AccompanyingPeriod Class
*
* @ORM\Entity()
* @ORM\Entity(repositoryClass="Chill\PersonBundle\Repository\AccompanyingPeriodRepository")
* @ORM\Table(name="chill_person_accompanying_period")
*/
class AccompanyingPeriod
{
const INTENSITY = ['occasional', 'regular'];
/**
* @var integer
*
@@ -63,16 +73,24 @@ class AccompanyingPeriod
* @ORM\Column(type="text")
*/
private $remark = '';
/**
* @var Person
* @var Collection
*
* @ORM\ManyToOne(
* targetEntity="Chill\PersonBundle\Entity\Person",
* inversedBy="accompanyingPeriods",
* cascade={"refresh"})
* @ORM\OneToMany(targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\Comment",
* mappedBy="accompanyingPeriod"
* )
*/
private $person;
private $comments;
/**
* @var Collection
*
* @ORM\OneToMany(targetEntity=AccompanyingPeriodParticipation::class,
* mappedBy="accompanyingPeriod",
* cascade={"persist", "remove", "merge", "detach"})
*/
private $participations;
/**
* @var AccompanyingPeriod\ClosingMotive
@@ -84,14 +102,88 @@ class AccompanyingPeriod
private $closingMotive = null;
/**
* The user making the accompanying
* @var User
*
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=true)
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=true)
*/
private $createdBy;
/**
* @var string
* @ORM\Column(type="string", length=32, nullable=true)
*/
private $step = 'DRAFT';
/**
* @ORM\ManyToOne(targetEntity=Origin::class)
* @ORM\JoinColumn(nullable=true)
*/
private $origin;
/**
* @var string
* @ORM\Column(type="string", nullable=true)
*/
private $intensity;
/**
* @var Collection
* @ORM\ManyToMany(
* targetEntity=Scope::class,
* cascade={}
* )
* @ORM\JoinTable(
* name="accompanying_periods_scopes",
* joinColumns={@ORM\JoinColumn(name="accompanying_period_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="scope_id", referencedColumnName="id")}
* )
*/
private $scopes;
/**
* @ORM\ManyToOne(targetEntity=Person::class)
* @ORM\JoinColumn(nullable=true)
*/
private $requestorPerson;
/**
* @ORM\ManyToOne(targetEntity=ThirdParty::class)
* @ORM\JoinColumn(nullable=true)
*/
private $requestorThirdParty;
/**
* @var bool
* @ORM\Column(type="boolean")
*/
private $requestorAnonymous = false;
/**
* @var bool
* @ORM\Column(type="boolean")
*/
private $emergency = false;
/**
* @var bool
* @ORM\Column(type="boolean")
*/
private $confidential = false;
/**
* @var Collection
*
* @ORM\OneToMany(
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod\Resource",
* mappedBy="accompanyingPeriod"
* )
*/
private $resources;
/**
* AccompanyingPeriod constructor.
@@ -101,12 +193,14 @@ class AccompanyingPeriod
*/
public function __construct(\DateTime $dateOpening) {
$this->setOpeningDate($dateOpening);
$this->participations = new ArrayCollection();
$this->scopes = new ArrayCollection();
}
/**
* Get id
*
* @return integer
* @return integer
*/
public function getId()
{
@@ -129,7 +223,7 @@ class AccompanyingPeriod
/**
* Get openingDate
*
* @return \DateTime
* @return \DateTime
*/
public function getOpeningDate()
{
@@ -138,12 +232,12 @@ class AccompanyingPeriod
/**
* Set closingDate
*
*
* For closing a Person file, you should use Person::setClosed instead.
*
* @param \DateTime $dateClosing
* @return AccompanyingPeriod
*
*
*/
public function setClosingDate($closingDate)
{
@@ -155,7 +249,7 @@ class AccompanyingPeriod
/**
* Get closingDate
*
* @return \DateTime
* @return \DateTime
*/
public function getClosingDate()
{
@@ -165,26 +259,20 @@ class AccompanyingPeriod
/**
* @return boolean
*/
public function isOpen(): bool
public function isOpen(): bool
{
if ($this->getOpeningDate() > new \DateTime('now')) {
if ($this->getOpeningDate() > new \DateTimeImmutable('now')) {
return false;
}
if ($this->getClosingDate() === null) {
return true;
} else {
return false;
}
return false;
}
/**
* Set remark
*
* @param string $remark
* @return AccompanyingPeriod
*/
public function setRemark($remark)
public function setRemark(string $remark): self
{
if ($remark === null) {
$remark = '';
@@ -194,83 +282,123 @@ class AccompanyingPeriod
return $this;
}
/**
* Get remark
*
* @return string
*/
public function getRemark()
public function getRemark(): string
{
return $this->remark;
}
/**
* Set person.
*
* For consistency, you should use Person::addAccompanyingPeriod instead.
*
* @param Person $person
* @return AccompanyingPeriod
* @see Person::addAccompanyingPeriod
*/
public function setPerson(Person $person = null)
public function getComments(): Collection
{
$this->person = $person;
return $this->comments;
}
public function addComment(Comment $comment): self
{
$this->comments[] = $comment;
return $this;
}
public function removeComment(Comment $comment): void
{
$this->comments->removeElement($comment);
}
/**
* Get Participations Collection
*/
public function getParticipations(): Collection
{
return $this->participations;
}
/**
* 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
{
$participation = new AccompanyingPeriodParticipation($this, $person);
$this->participations[] = $participation;
return $this;
}
/**
* Get person
*
* @return Person
*/
public function getPerson()
{
return $this->person;
}
/**
* @return AccompanyingPeriod\ClosingMotive
* Remove Person
*/
public function getClosingMotive()
public function removePerson(Person $person): void
{
$participation = $this->participationsContainsPerson($person);
if (! null === $participation) {
$participation->setEndDate(new \DateTimeImmutable('now'));
$this->participations->removeElement($participation);
}
}
public function getClosingMotive(): ?ClosingMotive
{
return $this->closingMotive;
}
/**
* @param AccompanyingPeriod\ClosingMotive|null $closingMotive
* @return $this
*/
public function setClosingMotive(AccompanyingPeriod\ClosingMotive $closingMotive = null)
public function setClosingMotive(ClosingMotive $closingMotive = null): self
{
$this->closingMotive = $closingMotive;
return $this;
}
/**
* If the period can be reopened.
*
* This function test if the period is closed and if the period is the last
* for the associated person
*
* @return boolean
*
* This function test if the period is closed and if the period is the last
* for the given person
*/
public function canBeReOpened()
public function canBeReOpened(Person $person): bool
{
if ($this->isOpen() === true) {
return false;
}
$periods = $this->getPerson()->getAccompanyingPeriodsOrdered();
$participation = $this->participationsContainsPerson($person);
if (!null === $participation)
{
$person = $participation->getPerson();
$periods = $person->getAccompanyingPeriodsOrdered();
return end($periods) === $this;
}
return end($periods) === $this;
return false;
}
/**
*/
public function reOpen()
public function reOpen(): void
{
$this->setClosingDate(null);
$this->setClosingMotive(null);
@@ -294,7 +422,7 @@ class AccompanyingPeriod
/**
* Returns true if the closing date is after the opening date.
*
*
* @return boolean
*/
public function isClosingAfterOpening()
@@ -308,23 +436,165 @@ class AccompanyingPeriod
}
}
/**
* @return User|null
*/
function getUser(): ?User
{
return $this->user;
}
/**
* @param User $user
* @return AccompanyingPeriod
*/
function setUser(User $user): self
{
$this->user = $user;
return $this;
}
public function getOrigin(): Origin
{
return $this->origin;
}
public function setOrigin(Origin $origin): self
{
$this->origin = $origin;
return $this;
}
public function getRequestorPerson(): ?Person
{
return $this->requestorPerson;
}
public function setRequestorPerson(Person $requestorPerson): self
{
$this->requestorPerson = ($this->requestorThirdParty === null) ? $requestorPerson : null;
return $this;
}
public function getRequestorThirdParty(): ?ThirdParty
{
return $this->requestorThirdParty;
}
public function setRequestorThirdParty(ThirdParty $requestorThirdParty): self
{
$this->requestorThirdParty = ($this->requestorPerson === null) ? $requestorThirdParty : null;
return $this;
}
/**
* @return Person|ThirdParty
*/
public function getRequestor()
{
return $this->requestorPerson ?? $this->requestorThirdParty;
}
public function isRequestorAnonymous(): bool
{
return $this->requestorAnonymous;
}
public function setRequestorAnonymous(bool $requestorAnonymous): self
{
$this->requestorAnonymous = $requestorAnonymous;
return $this;
}
public function isEmergency(): bool
{
return $this->emergency;
}
public function setEmergency(bool $emergency): self
{
$this->emergency = $emergency;
return $this;
}
public function isConfidential(): bool
{
return $this->confidential;
}
public function setConfidential(bool $confidential): self
{
$this->confidential = $confidential;
return $this;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
public function setCreatedBy(User $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function getStep(): string
{
return $this->step;
}
public function setStep(string $step): self
{
$this->step = $step;
return $this;
}
public function getIntensity(): string
{
return $this->intensity;
}
public function setIntensity(string $intensity): self
{
$this->intensity = $intensity;
return $this;
}
public function getScopes(): Collection
{
return $this->scopes;
}
public function addScope(Scope $scope): self
{
$this->scopes[] = $scope;
return $this;
}
public function removeScope(Scope $scope): void
{
$this->scopes->removeElement($scope);
}
public function getResources(): Collection
{
return $this->resources;
}
public function addResource(Resource $resource): self
{
$this->resources[] = $resource;
return $this;
}
public function removeResource(Resource $resource): void
{
$this->resources->removeElement($resource);
}
}

View File

@@ -1,19 +1,21 @@
<?php
/*
*
* Copyright (C) 2014-2020, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
*
* Chill is a software for social workers
*
* Copyright (C) 2014-2021, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -28,8 +30,8 @@ use Doctrine\Common\Collections\ArrayCollection;
* ClosingMotive give an explanation why we closed the Accompanying period
*
* @ORM\Entity(
* repositoryClass="Chill\PersonBundle\Repository\ClosingMotiveRepository")
* @ORM\Table(name="chill_person_closingmotive")
* repositoryClass="Chill\PersonBundle\Repository\AccompanyingPeriod\ClosingMotiveRepository")
* @ORM\Table(name="chill_person_accompanying_period_closingmotive")
*/
class ClosingMotive
{

View File

@@ -0,0 +1,154 @@
<?php
/*
* Chill is a software for social workers
*
* Copyright (C) 2021, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Repository\AccompanyingPeriod\CommentRepository;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=CommentRepository::class)
* @ORM\Table(name="chill_person_accompanying_period_comment")
*/
class Comment
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod",
* inversedBy="comments")
* @ORM\JoinColumn(nullable=false)
*/
private $accompanyingPeriod;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=false)
*/
private $creator;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime")
*/
private $updatedAt;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=false)
*/
private $updatedBy;
/**
* @ORM\Column(type="text")
*/
private $content;
public function getId(): ?int
{
return $this->id;
}
public function getAccompanyingPeriod(): ?AccompanyingPeriod
{
return $this->accompanyingPeriod;
}
public function setAccompanyingPeriod(?AccompanyingPeriod $accompanyingPeriod): self
{
$this->accompanyingPeriod = $accompanyingPeriod;
return $this;
}
public function getCreator(): ?User
{
return $this->creator;
}
public function setCreator(?User $creator): self
{
$this->creator = $creator;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getUpdatedBy(): ?User
{
return $this->updatedBy;
}
public function setUpdatedBy(?User $updatedBy): self
{
$this->updatedBy = $updatedBy;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
}

View File

@@ -0,0 +1,79 @@
<?php
/*
* Chill is a software for social workers
*
* Copyright (C) 2021, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriod\OriginRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=OriginRepository::class)
* @ORM\Table(name="chill_person_accompanying_period_origin")
*/
class Origin
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $label;
/**
* @ORM\Column(type="date_immutable", nullable=true)
*/
private $noActiveAfter;
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): self
{
$this->label = $label;
return $this;
}
public function getNoActiveAfter(): ?\DateTimeImmutable
{
return $this->noActiveAfter;
}
public function setNoActiveAfter(?\DateTimeImmutable $noActiveAfter): self
{
$this->noActiveAfter = $noActiveAfter;
return $this;
}
}

View File

@@ -0,0 +1,132 @@
<?php
/*
* Chill is a software for social workers
*
* Copyright (C) 2021, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Repository\AccompanyingPeriod\ResourceRepository;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
use Chill\PersonBundle\Entity\Person;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ResourceRepository::class)
* @ORM\Table(name="chill_person_accompanying_period_resource")
*/
class Resource
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod",
* inversedBy="resources"
* )
* @ORM\JoinColumn(nullable=false)
*/
private $accompanyingPeriod;
/**
* @ORM\ManyToOne(targetEntity=ThirdParty::class)
* @ORM\JoinColumn(nullable=true)
*/
private $thirdParty;
/**
* @ORM\ManyToOne(targetEntity=Person::class)
* @ORM\JoinColumn(nullable=true)
*/
private $person;
/**
* @ORM\ManyToOne(targetEntity=Comment::class)
* @ORM\JoinColumn(nullable=true)
*/
private $comment;
public function getId(): ?int
{
return $this->id;
}
public function getAccompanyingPeriod(): ?AccompanyingPeriod
{
return $this->accompanyingPeriod;
}
public function setAccompanyingPeriod(?AccompanyingPeriod $accompanyingPeriod): self
{
$this->accompanyingPeriod = $accompanyingPeriod;
return $this;
}
public function getThirdParty(): ?ThirdParty
{
return $this->thirdParty;
}
public function setThirdParty(?ThirdParty $thirdParty): self
{
$this->thirdParty = $thirdParty;
return $this;
}
public function getPerson(): ?Person
{
return $this->person;
}
public function setPerson(?Person $person): self
{
$this->person = $person;
return $this;
}
public function getComment(): ?Comment
{
return $this->comment;
}
public function setComment(?Comment $comment): self
{
$this->comment = $comment;
return $this;
}
/**
* @return Person|ThirdParty
*/
public function getResource()
{
return $this->person ?? $this->thirdParty;
}
}

View File

@@ -0,0 +1,124 @@
<?php
/*
* Chill is a software for social workers
*
* Copyright (C) 2021, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Chill\PersonBundle\Entity;
use Chill\PersonBundle\Repository\AccompanyingPeriodParticipationRepository;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use Doctrine\ORM\Mapping as ORM;
/**
* AccompanyingPeriodParticipation Class
*
* @package Chill\PersonBundle\Entity
* @ORM\Entity(repositoryClass=AccompanyingPeriodParticipationRepository::class)
* @ORM\Table(name="chill_person_accompanying_period_participation")
*/
class AccompanyingPeriodParticipation
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Person::class, inversedBy="accompanyingPeriodParticipations")
* @ORM\JoinColumn(name="person_id", referencedColumnName="id", nullable=false)
*/
private $person;
/**
* @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class, inversedBy="participations")
* @ORM\JoinColumn(name="accompanyingperiod_id", referencedColumnName="id", nullable=false)
*/
private $accompanyingPeriod;
/**
* @ORM\Column(type="date", nullable=false)
*/
private $startDate;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $endDate = null;
public function __construct(AccompanyingPeriod $accompanyingPeriod, Person $person)
{
$this->startDate = new \DateTimeImmutable('now');
$this->accompanyingPeriod = $accompanyingPeriod;
$this->person = $person;
}
public function getId(): ?int
{
return $this->id;
}
public function getPerson(): ?Person
{
return $this->person;
}
public function setPerson(?Person $person): self
{
$this->person = $person;
return $this;
}
public function getAccompanyingPeriod(): ?AccompanyingPeriod
{
return $this->accompanyingPeriod;
}
public function setAccompanyingPeriod(?AccompanyingPeriod $accompanyingPeriod): self
{
$this->accompanyingPeriod = $accompanyingPeriod;
return $this;
}
public function getStartDate(): ?\DateTimeInterface
{
return $this->startDate;
}
/*
* public function setStartDate(\DateTimeInterface $startDate): self { $this->startDate = $startDate; return $this; }
*/
public function getEndDate(): ?\DateTimeInterface
{
return $this->endDate;
}
public function setEndDate(?\DateTimeInterface $endDate): self
{
$this->endDate = $endDate;
return $this;
}
}

View File

@@ -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;
}
}