mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
1859 lines
44 KiB
PHP
1859 lines
44 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\PersonBundle\Entity;
|
|
|
|
use ArrayIterator;
|
|
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
|
|
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
|
use Chill\MainBundle\Entity\Address;
|
|
use Chill\MainBundle\Entity\Center;
|
|
use Chill\MainBundle\Entity\Civility;
|
|
use Chill\MainBundle\Entity\Country;
|
|
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
|
use Chill\MainBundle\Entity\HasCenterInterface;
|
|
use Chill\MainBundle\Entity\User;
|
|
use Chill\MainBundle\Validation\Constraint\PhonenumberConstraint;
|
|
use Chill\PersonBundle\Entity\Household\Household;
|
|
use Chill\PersonBundle\Entity\Household\HouseholdMember;
|
|
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
|
|
use Chill\PersonBundle\Entity\Person\PersonCurrentAddress;
|
|
use Chill\PersonBundle\Validator\Constraints\Household\HouseholdMembershipSequential;
|
|
use Chill\PersonBundle\Validator\Constraints\Person\Birthdate;
|
|
use Chill\PersonBundle\Validator\Constraints\Person\PersonHasCenter;
|
|
use DateTime;
|
|
use DateTimeImmutable;
|
|
use DateTimeInterface;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\Common\Collections\Criteria;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Exception;
|
|
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|
use function count;
|
|
use function in_array;
|
|
|
|
/**
|
|
* Person Class.
|
|
*
|
|
* @ORM\Entity
|
|
* @ORM\Table(name="chill_person_person",
|
|
* indexes={
|
|
* @ORM\Index(
|
|
* name="person_names",
|
|
* columns={"firstName", "lastName"}
|
|
* ),
|
|
* @ORM\Index(
|
|
* name="person_birthdate",
|
|
* columns={"birthdate"}
|
|
* )
|
|
* })
|
|
* @ORM\HasLifecycleCallbacks
|
|
* @DiscriminatorMap(typeProperty="type", mapping={
|
|
* "person": Person::class
|
|
* })
|
|
* @PersonHasCenter
|
|
* @HouseholdMembershipSequential(
|
|
* groups={"household_memberships"}
|
|
* )
|
|
*/
|
|
class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateInterface
|
|
{
|
|
public const BOTH_GENDER = 'both';
|
|
|
|
// have days in commun
|
|
public const ERROR_ADDIND_PERIOD_AFTER_AN_OPEN_PERIOD = 2; // where there exist
|
|
|
|
public const ERROR_PERIODS_ARE_COLLAPSING = 1; // when two different periods
|
|
|
|
public const FEMALE_GENDER = 'woman';
|
|
|
|
public const MALE_GENDER = 'man';
|
|
|
|
public const NO_INFORMATION = 'unknown';
|
|
|
|
/**
|
|
* Accept receiving email.
|
|
*
|
|
* @var bool
|
|
*
|
|
* @ORM\Column(type="boolean", options={"default": false})
|
|
*/
|
|
private ?bool $acceptEmail = false;
|
|
|
|
/**
|
|
* Accept short text message (aka SMS).
|
|
*
|
|
* @var bool
|
|
*
|
|
* @ORM\Column(type="boolean", options={"default": false})
|
|
*/
|
|
private ?bool $acceptSMS = false;
|
|
|
|
/**
|
|
* The person's accompanying periods (when the person was accompanied by the center).
|
|
*
|
|
* @var Collection
|
|
*
|
|
* @ORM\OneToMany(targetEntity=AccompanyingPeriodParticipation::class,
|
|
* mappedBy="person",
|
|
* cascade={"persist", "remove", "merge", "detach"})
|
|
*/
|
|
private $accompanyingPeriodParticipations;
|
|
|
|
/**
|
|
* The accompanying period requested by the Person.
|
|
*
|
|
* @ORM\OneToMany(targetEntity=AccompanyingPeriod::class,
|
|
* mappedBy="requestorPerson")
|
|
*
|
|
* @var AccompanyingPeriod[]|Collection
|
|
*/
|
|
private Collection $accompanyingPeriodRequested;
|
|
|
|
/**
|
|
* Addresses.
|
|
*
|
|
* @var Collection
|
|
*
|
|
* @ORM\ManyToMany(
|
|
* targetEntity="Chill\MainBundle\Entity\Address",
|
|
* cascade={"persist", "remove", "merge", "detach"})
|
|
* @ORM\JoinTable(name="chill_person_persons_to_addresses")
|
|
* @ORM\OrderBy({"validFrom": "DESC"})
|
|
*/
|
|
private $addresses;
|
|
|
|
/**
|
|
* @var Collection
|
|
*
|
|
* @ORM\OneToMany(
|
|
* targetEntity="Chill\PersonBundle\Entity\PersonAltName",
|
|
* mappedBy="person",
|
|
* cascade={"persist", "remove", "merge", "detach"},
|
|
* orphanRemoval=true)
|
|
*/
|
|
private $altNames;
|
|
|
|
/**
|
|
* The person's birthdate.
|
|
*
|
|
* @var DateTime
|
|
*
|
|
* @ORM\Column(type="date", nullable=true)
|
|
* @Birthdate
|
|
*/
|
|
private $birthdate;
|
|
|
|
/**
|
|
* The person's center.
|
|
*
|
|
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Center")
|
|
*/
|
|
private ?Center $center = null;
|
|
|
|
/**
|
|
* Array where customfield's data are stored.
|
|
*
|
|
* @var array
|
|
*
|
|
* @ORM\Column(type="json")
|
|
*/
|
|
private $cFData;
|
|
|
|
/**
|
|
* The marital status of the person.
|
|
*
|
|
* @var Civility
|
|
*
|
|
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Civility")
|
|
* @ORM\JoinColumn(nullable=true)
|
|
*/
|
|
private $civility;
|
|
|
|
/**
|
|
* Contact information for contacting the person.
|
|
*
|
|
* @var string
|
|
*
|
|
* @ORM\Column(type="text", nullable=true)
|
|
*/
|
|
private $contactInfo = '';
|
|
|
|
/**
|
|
* The person's country of birth.
|
|
*
|
|
* @var Country
|
|
*
|
|
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Country")
|
|
*
|
|
* sf4 check: option inversedBy="birthsIn" return error mapping !!
|
|
*
|
|
* @ORM\JoinColumn(nullable=true)
|
|
*/
|
|
private $countryOfBirth;
|
|
|
|
/**
|
|
* @ORM\Column(type="datetime", nullable=true, options={"default": NULL})
|
|
*/
|
|
private $createdAt;
|
|
|
|
/**
|
|
* @ORM\ManyToOne(targetEntity=User::class)
|
|
* @ORM\JoinColumn(nullable=true)
|
|
*/
|
|
private $createdBy;
|
|
|
|
/**
|
|
* Cache the computation of household.
|
|
*/
|
|
private array $currentHouseholdAt = [];
|
|
|
|
/**
|
|
* The current person address.
|
|
*
|
|
* This is computed through database and is optimized on database side.
|
|
*
|
|
* @ORM\OneToOne(targetEntity=PersonCurrentAddress::class, mappedBy="person")
|
|
*/
|
|
private ?PersonCurrentAddress $currentPersonAddress = null;
|
|
|
|
/**
|
|
* The person's deathdate.
|
|
*
|
|
* @var DateTimeImmutable
|
|
*
|
|
* @ORM\Column(type="date_immutable", nullable=true)
|
|
* @Assert\Date
|
|
* @Assert\GreaterThanOrEqual(propertyPath="birthdate")
|
|
* @Assert\LessThanOrEqual("today")
|
|
*/
|
|
private ?DateTimeImmutable $deathdate = null;
|
|
|
|
/**
|
|
* The person's email.
|
|
*
|
|
* @var string
|
|
*
|
|
* @ORM\Column(type="text", nullable=true)
|
|
* @Assert\Email(
|
|
* checkMX=true
|
|
* )
|
|
*/
|
|
private $email = '';
|
|
|
|
/**
|
|
* The person's first name.
|
|
*
|
|
* @var string
|
|
*
|
|
* @ORM\Column(type="string", length=255)
|
|
* @Assert\NotBlank(message="The firstname cannot be empty")
|
|
* @Assert\Length(
|
|
* max=255,
|
|
* )
|
|
*/
|
|
private $firstName;
|
|
|
|
/**
|
|
* fullname canonical. Read-only field, which is calculated by
|
|
* the database.
|
|
*
|
|
* @var string
|
|
*
|
|
* @ORM\Column(type="text", nullable=true)
|
|
*/
|
|
private $fullnameCanonical;
|
|
|
|
/**
|
|
* The person's gender.
|
|
*
|
|
* @var string
|
|
*
|
|
* @ORM\Column(type="string", length=9, nullable=true)
|
|
* @Assert\NotNull(message="The gender must be set")
|
|
*/
|
|
private $gender;
|
|
|
|
/**
|
|
* Comment on gender.
|
|
*
|
|
* @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="genderComment_")
|
|
*/
|
|
private CommentEmbeddable $genderComment;
|
|
|
|
/**
|
|
* Read-only field, computed by the database.
|
|
*
|
|
* @ORM\OneToMany(
|
|
* targetEntity=PersonHouseholdAddress::class,
|
|
* mappedBy="person"
|
|
* )
|
|
*/
|
|
private Collection $householdAddresses;
|
|
|
|
/**
|
|
* @ORM\OneToMany(
|
|
* targetEntity=HouseholdMember::class,
|
|
* mappedBy="person"
|
|
* )
|
|
*/
|
|
private Collection $householdParticipations;
|
|
|
|
/**
|
|
* The person's id.
|
|
*
|
|
* @ORM\Id
|
|
* @ORM\Column(name="id", type="integer")
|
|
* @ORM\GeneratedValue(strategy="AUTO")
|
|
*/
|
|
private ?int $id = null;
|
|
|
|
/**
|
|
* The person's last name.
|
|
*
|
|
* @var string
|
|
*
|
|
* @ORM\Column(type="string", length=255)
|
|
* @Assert\NotBlank(message="The lastname cannot be empty")
|
|
* @Assert\Length(
|
|
* max=255,
|
|
* )
|
|
*/
|
|
private $lastName;
|
|
|
|
/**
|
|
* The marital status of the person.
|
|
*
|
|
* @var MaritalStatus
|
|
*
|
|
* @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\MaritalStatus")
|
|
* @ORM\JoinColumn(nullable=true)
|
|
*/
|
|
private $maritalStatus;
|
|
|
|
/**
|
|
* Comment on marital status.
|
|
*
|
|
* @ORM\Embedded(class="Chill\MainBundle\Entity\Embeddable\CommentEmbeddable", columnPrefix="maritalStatusComment_")
|
|
*/
|
|
private CommentEmbeddable $maritalStatusComment;
|
|
|
|
/**
|
|
* The date of the last marital status change of the person.
|
|
*
|
|
* @var DateTime
|
|
*
|
|
* @ORM\Column(type="date", nullable=true)
|
|
* @Assert\Date
|
|
*/
|
|
private ?DateTime $maritalStatusDate = null;
|
|
|
|
/**
|
|
* A remark over the person.
|
|
*
|
|
* @var string
|
|
*
|
|
* @ORM\Column(type="text")
|
|
*/
|
|
private $memo = ''; // TO-CHANGE in remark
|
|
|
|
/**
|
|
* The person's mobile phone number.
|
|
*
|
|
* @ORM\Column(type="text")
|
|
* @Assert\Regex(
|
|
* pattern="/^([\+{1}])([0-9\s*]{4,20})$/",
|
|
* )
|
|
* @PhonenumberConstraint(
|
|
* type="mobile",
|
|
* )
|
|
*/
|
|
private string $mobilenumber = '';
|
|
|
|
/**
|
|
* The person's nationality.
|
|
*
|
|
* @var Country
|
|
*
|
|
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Country")
|
|
*
|
|
* sf4 check: option inversedBy="nationals" return error mapping !!
|
|
*
|
|
* @ORM\JoinColumn(nullable=true)
|
|
*/
|
|
private $nationality;
|
|
|
|
/**
|
|
* Number of children.
|
|
*
|
|
* @var int
|
|
*
|
|
* @ORM\Column(type="integer", nullable=true)
|
|
*/
|
|
private ?int $numberOfChildren = null;
|
|
|
|
/**
|
|
* @var Collection
|
|
*
|
|
* @ORM\OneToMany(
|
|
* targetEntity="Chill\PersonBundle\Entity\PersonPhone",
|
|
* mappedBy="person",
|
|
* cascade={"persist", "remove", "merge", "detach"},
|
|
* orphanRemoval=true
|
|
* )
|
|
* @Assert\Valid(
|
|
* traverse=true,
|
|
* )
|
|
*/
|
|
private $otherPhoneNumbers;
|
|
|
|
/**
|
|
* @ORM\OneToMany(
|
|
* targetEntity=AccompanyingPeriod::class,
|
|
* mappedBy="personLocation"
|
|
* )
|
|
*/
|
|
private Collection $periodLocatedOn;
|
|
|
|
/**
|
|
* The person's phonenumber.
|
|
*
|
|
* @ORM\Column(type="text")
|
|
* @Assert\Regex(
|
|
* pattern="/^([\+{1}])([0-9\s*]{4,20})$/",
|
|
* )
|
|
* @PhonenumberConstraint(
|
|
* type="landline",
|
|
* )
|
|
*/
|
|
private string $phonenumber = '';
|
|
|
|
/**
|
|
* The person's place of birth.
|
|
*
|
|
* @var string
|
|
*
|
|
* @ORM\Column(type="string", length=255, name="place_of_birth")
|
|
*/
|
|
private $placeOfBirth = '';
|
|
|
|
/**
|
|
* @var bool
|
|
*
|
|
* @deprecated
|
|
*
|
|
* @ORM\Column(type="boolean")
|
|
*/
|
|
private $proxyAccompanyingPeriodOpenState = false; //TO-DELETE ?
|
|
|
|
/**
|
|
* The person's spoken languages.
|
|
*
|
|
* @var ArrayCollection
|
|
*
|
|
* @ORM\ManyToMany(targetEntity="Chill\MainBundle\Entity\Language")
|
|
* @ORM\JoinTable(
|
|
* name="persons_spoken_languages",
|
|
* joinColumns={@ORM\JoinColumn(name="person_id", referencedColumnName="id")},
|
|
* inverseJoinColumns={@ORM\JoinColumn(name="language_id", referencedColumnName="id")}
|
|
* )
|
|
*/
|
|
private $spokenLanguages;
|
|
|
|
/**
|
|
* @ORM\Column(type="datetime", nullable=true, options={"default": NULL})
|
|
*/
|
|
private $updatedAt;
|
|
|
|
/**
|
|
* @ORM\ManyToOne(
|
|
* targetEntity=User::class
|
|
* )
|
|
*/
|
|
private $updatedBy;
|
|
|
|
/**
|
|
* Person constructor.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->accompanyingPeriodParticipations = new ArrayCollection();
|
|
$this->spokenLanguages = new ArrayCollection();
|
|
$this->addresses = new ArrayCollection();
|
|
$this->altNames = new ArrayCollection();
|
|
$this->otherPhoneNumbers = new ArrayCollection();
|
|
$this->householdParticipations = new ArrayCollection();
|
|
$this->householdAddresses = new ArrayCollection();
|
|
$this->genderComment = new CommentEmbeddable();
|
|
$this->maritalStatusComment = new CommentEmbeddable();
|
|
$this->periodLocatedOn = new ArrayCollection();
|
|
$this->accompanyingPeriodRequested = new ArrayCollection();
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function __toString()
|
|
{
|
|
return $this->getLabel();
|
|
}
|
|
|
|
/**
|
|
* Add AccompanyingPeriodParticipation.
|
|
*
|
|
* @uses AccompanyingPeriod::addPerson
|
|
*/
|
|
public function addAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod): self
|
|
{
|
|
$participation = new AccompanyingPeriodParticipation($accompanyingPeriod, $this);
|
|
$this->accompanyingPeriodParticipations->add($participation);
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return $this
|
|
*/
|
|
public function addAddress(Address $address)
|
|
{
|
|
$this->addresses[] = $address;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return $this
|
|
*/
|
|
public function addAltName(PersonAltName $altName)
|
|
{
|
|
if (false === $this->altNames->contains($altName)) {
|
|
$this->altNames->add($altName);
|
|
$altName->setPerson($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function addHouseholdParticipation(HouseholdMember $member): self
|
|
{
|
|
$this->householdParticipations[] = $member;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return $this
|
|
*/
|
|
public function addOtherPhoneNumber(PersonPhone $otherPhoneNumber)
|
|
{
|
|
if (false === $this->otherPhoneNumbers->contains($otherPhoneNumber)) {
|
|
$otherPhoneNumber->setPerson($this);
|
|
$this->otherPhoneNumbers->add($otherPhoneNumber);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Function used for validation that check if the accompanying periods of
|
|
* the person are not collapsing (i.e. have not shared days) or having
|
|
* a period after an open period.
|
|
*
|
|
* @return true | array True if the accompanying periods are not collapsing,
|
|
* an array with data for displaying the error
|
|
*/
|
|
public function checkAccompanyingPeriodsAreNotCollapsing()
|
|
{
|
|
$periods = $this->getAccompanyingPeriodsOrdered();
|
|
$periodsNbr = count($periods);
|
|
$i = 0;
|
|
|
|
while ($periodsNbr - 1 > $i) {
|
|
$periodI = $periods[$i];
|
|
$periodAfterI = $periods[$i + 1];
|
|
|
|
if ($periodI->isOpen()) {
|
|
return [
|
|
'result' => self::ERROR_ADDIND_PERIOD_AFTER_AN_OPEN_PERIOD,
|
|
'dateOpening' => $periodAfterI->getOpeningDate(),
|
|
'dateClosing' => $periodAfterI->getClosingDate(),
|
|
'date' => $periodI->getOpeningDate(),
|
|
];
|
|
}
|
|
|
|
if ($periodI->getClosingDate() >= $periodAfterI->getOpeningDate()) {
|
|
return [
|
|
'result' => self::ERROR_PERIODS_ARE_COLLAPSING,
|
|
'dateOpening' => $periodI->getOpeningDate(),
|
|
|
|
'dateClosing' => $periodI->getClosingDate(),
|
|
'date' => $periodAfterI->getOpeningDate(),
|
|
];
|
|
}
|
|
++$i;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Set the Person file as closed at the given date.
|
|
*
|
|
* For update a closing date, you should update AccompanyingPeriod instance
|
|
* directly.
|
|
*
|
|
* To check if the Person and its accompanying period are consistent, use validation.
|
|
*
|
|
* @throws Exception if two lines of the accompanying period are open.
|
|
*/
|
|
public function close(?AccompanyingPeriod $accompanyingPeriod = null): void
|
|
{
|
|
$this->proxyAccompanyingPeriodOpenState = false;
|
|
}
|
|
|
|
/**
|
|
* This public function is the same but return only true or false.
|
|
*/
|
|
public function containsAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod): bool
|
|
{
|
|
return ($this->participationsContainAccompanyingPeriod($accompanyingPeriod)) ? false : true;
|
|
}
|
|
|
|
/**
|
|
* Handy method to get the AccompanyingPeriodParticipation
|
|
* matching a given AccompanyingPeriod.
|
|
*
|
|
* Used in template, to find the participation when iterating on a list
|
|
* of period.
|
|
*
|
|
* @return AccompanyingPeriodParticipation
|
|
*/
|
|
public function findParticipationForPeriod(AccompanyingPeriod $period): ?AccompanyingPeriodParticipation
|
|
{
|
|
$closeCandidates = [];
|
|
|
|
foreach ($this->getAccompanyingPeriodParticipations() as $participation) {
|
|
if ($participation->getAccompanyingPeriod() === $period) {
|
|
if ($participation->isOpen()) {
|
|
return $participation;
|
|
}
|
|
$closeCandidates[] = $participation;
|
|
}
|
|
}
|
|
|
|
if (0 < count($closeCandidates)) {
|
|
return $closeCandidates[0];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function getAcceptEmail(): ?bool
|
|
{
|
|
return $this->acceptEmail;
|
|
}
|
|
|
|
public function getAcceptSMS(): ?bool
|
|
{
|
|
return $this->acceptSMS;
|
|
}
|
|
|
|
/**
|
|
* Return a list of all accompanying period where the person is involved:.
|
|
*
|
|
* * as requestor;
|
|
* * as participant, only for opened participation;
|
|
*
|
|
* @param bool $asParticipantOpen add participation which are still opened
|
|
* @param bool $asRequestor add accompanying period where the person is requestor
|
|
*
|
|
* @return AccompanyingPeriod[]|Collection
|
|
*/
|
|
public function getAccompanyingPeriodInvolved(
|
|
bool $asParticipantOpen = true,
|
|
bool $asRequestor = true
|
|
): Collection {
|
|
$result = new ArrayCollection();
|
|
|
|
if ($asParticipantOpen) {
|
|
foreach ($this->getAccompanyingPeriodParticipations()
|
|
->map(fn (AccompanyingPeriodParticipation $app) => $app->getAccompanyingPeriod())
|
|
as $period
|
|
) {
|
|
if (!$result->contains($period)) {
|
|
$result->add($period);
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($asRequestor) {
|
|
foreach ($this->accompanyingPeriodRequested as $period) {
|
|
if (!$result->contains($period)) {
|
|
$result->add($period);
|
|
}
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Get AccompanyingPeriodParticipations Collection.
|
|
*
|
|
* @return AccompanyingPeriodParticipation[]|Collection
|
|
*/
|
|
public function getAccompanyingPeriodParticipations(): Collection
|
|
{
|
|
return $this->accompanyingPeriodParticipations;
|
|
}
|
|
|
|
/**
|
|
* @return AccompanyingPeriod[]|Collection
|
|
*/
|
|
public function getAccompanyingPeriodRequested(): Collection
|
|
{
|
|
return $this->accompanyingPeriodRequested;
|
|
}
|
|
|
|
/**
|
|
* Get AccompanyingPeriods array.
|
|
*/
|
|
public function getAccompanyingPeriods(): array
|
|
{
|
|
$accompanyingPeriods = [];
|
|
|
|
foreach ($this->accompanyingPeriodParticipations as $participation) {
|
|
/** @var AccompanyingPeriodParticipation $participation */
|
|
$accompanyingPeriods[] = $participation->getAccompanyingPeriod();
|
|
}
|
|
|
|
return $accompanyingPeriods;
|
|
}
|
|
|
|
/**
|
|
* Get the accompanying periods of a give person with the chronological order.
|
|
*/
|
|
public function getAccompanyingPeriodsOrdered(): array
|
|
{
|
|
$periods = $this->getAccompanyingPeriods();
|
|
|
|
//order by date :
|
|
usort($periods, static function ($a, $b) {
|
|
$dateA = $a->getOpeningDate();
|
|
$dateB = $b->getOpeningDate();
|
|
|
|
if ($dateA === $dateB) {
|
|
$dateEA = $a->getClosingDate();
|
|
$dateEB = $b->getClosingDate();
|
|
|
|
if ($dateEA === $dateEB) {
|
|
return 0;
|
|
}
|
|
|
|
if ($dateEA < $dateEB) {
|
|
return -1;
|
|
}
|
|
|
|
return +1;
|
|
}
|
|
|
|
if ($dateA < $dateB) {
|
|
return -1;
|
|
}
|
|
|
|
return 1;
|
|
});
|
|
|
|
return $periods;
|
|
}
|
|
|
|
/**
|
|
* get the address associated with the person at the given date.
|
|
*
|
|
* If the `$at` parameter is now, use the method `getCurrentPersonAddress`, which is optimized
|
|
* on database side.
|
|
*
|
|
* @deprecated since chill2.0, address is linked to the household. Use @see{Person::getCurrentHouseholdAddress}
|
|
*
|
|
* @throws Exception
|
|
*/
|
|
public function getAddressAt(?DateTimeInterface $at = null): ?Address
|
|
{
|
|
$at ??= new DateTime('now');
|
|
|
|
if ($at instanceof DateTimeImmutable) {
|
|
$at = DateTime::createFromImmutable($at);
|
|
}
|
|
|
|
/** @var ArrayIterator $addressesIterator */
|
|
$addressesIterator = $this->getAddresses()
|
|
->filter(static fn (Address $address): bool => $address->getValidFrom() <= $at)
|
|
->getIterator();
|
|
|
|
$addressesIterator->uasort(
|
|
static fn (Address $left, Address $right): int => $right->getValidFrom() <=> $left->getValidFrom()
|
|
);
|
|
|
|
return [] === ($addresses = iterator_to_array($addressesIterator)) ?
|
|
null :
|
|
current($addresses);
|
|
}
|
|
|
|
/**
|
|
* By default, the addresses are ordered by date, descending (the most
|
|
* recent first).
|
|
*/
|
|
public function getAddresses(): Collection
|
|
{
|
|
return $this->addresses;
|
|
}
|
|
|
|
/**
|
|
* Return the age of a person, calculated at the date 'now'.
|
|
*
|
|
* If the person has a deathdate, calculate the age at the deathdate.
|
|
*
|
|
* @param string $at A valid string to create a DateTime.
|
|
*/
|
|
public function getAge(string $at = 'now'): ?int
|
|
{
|
|
if ($this->birthdate instanceof DateTimeInterface) {
|
|
if ($this->deathdate instanceof DateTimeInterface) {
|
|
return (int) date_diff($this->birthdate, $this->deathdate)->format('%y');
|
|
}
|
|
|
|
return (int) date_diff($this->birthdate, date_create($at))->format('%y');
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function getAltNames(): Collection
|
|
{
|
|
return $this->altNames;
|
|
}
|
|
|
|
/**
|
|
* Get birthdate.
|
|
*
|
|
* @return DateTime
|
|
*/
|
|
public function getBirthdate()
|
|
{
|
|
return $this->birthdate;
|
|
}
|
|
|
|
/**
|
|
* Get center.
|
|
*
|
|
* @return Center
|
|
*/
|
|
public function getCenter()
|
|
{
|
|
return $this->center;
|
|
}
|
|
|
|
/**
|
|
* Get cFData.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function getCFData()
|
|
{
|
|
if (null === $this->cFData) {
|
|
$this->cFData = [];
|
|
}
|
|
|
|
return $this->cFData;
|
|
}
|
|
|
|
/**
|
|
* Get civility.
|
|
*
|
|
* @return Civility
|
|
*/
|
|
public function getCivility()
|
|
{
|
|
return $this->civility;
|
|
}
|
|
|
|
/**
|
|
* Get contactInfo.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getcontactInfo()
|
|
{
|
|
return $this->contactInfo;
|
|
}
|
|
|
|
/**
|
|
* Get countryOfBirth.
|
|
*
|
|
* @return Chill\MainBundle\Entity\Country
|
|
*/
|
|
public function getCountryOfBirth()
|
|
{
|
|
return $this->countryOfBirth;
|
|
}
|
|
|
|
public function getCreatedAt(): ?DateTimeInterface
|
|
{
|
|
return $this->createdAt;
|
|
}
|
|
|
|
public function getCreatedBy(): ?User
|
|
{
|
|
return $this->createdBy;
|
|
}
|
|
|
|
/**
|
|
* Returns the opened accompanying period.
|
|
*
|
|
* @deprecated since 1.1 use `getOpenedAccompanyingPeriod instead
|
|
*/
|
|
public function getCurrentAccompanyingPeriod(): ?AccompanyingPeriod
|
|
{
|
|
return $this->getOpenedAccompanyingPeriod();
|
|
}
|
|
|
|
/**
|
|
* Get current accompanyingPeriods array.
|
|
*/
|
|
public function getCurrentAccompanyingPeriods(): array
|
|
{
|
|
$currentAccompanyingPeriods = [];
|
|
$currentDate = new DateTime();
|
|
|
|
foreach ($this->accompanyingPeriodParticipations as $participation) {
|
|
$endDate = $participation->getEndDate();
|
|
|
|
if (null === $endDate || $endDate > $currentDate) {
|
|
$currentAccompanyingPeriods[] = $participation->getAccompanyingPeriod();
|
|
}
|
|
}
|
|
|
|
return $currentAccompanyingPeriods;
|
|
}
|
|
|
|
public function getCurrentHousehold(?DateTimeImmutable $at = null): ?Household
|
|
{
|
|
$participation = $this->getCurrentHouseholdParticipationShareHousehold($at);
|
|
|
|
return $participation instanceof HouseholdMember ?
|
|
$participation->getHousehold()
|
|
: null;
|
|
}
|
|
|
|
/**
|
|
* Get the household address at the given date.
|
|
*
|
|
* if the given date is 'now', use instead @see{getCurrentPersonAddress}, which is optimized on
|
|
* database side.
|
|
*/
|
|
public function getCurrentHouseholdAddress(?DateTimeImmutable $at = null): ?Address
|
|
{
|
|
if (
|
|
null === $at
|
|
|| $at->format('Ymd') === (new DateTime('today'))->format('Ymd')
|
|
) {
|
|
return $this->currentPersonAddress instanceof PersonCurrentAddress
|
|
? $this->currentPersonAddress->getAddress() : null;
|
|
}
|
|
|
|
// if not now, compute the date from history
|
|
$criteria = new Criteria();
|
|
$expr = Criteria::expr();
|
|
|
|
$criteria->where(
|
|
$expr->lte('validFrom', $at)
|
|
)
|
|
->andWhere(
|
|
$expr->orX(
|
|
$expr->isNull('validTo'),
|
|
$expr->gte('validTo', $at)
|
|
)
|
|
);
|
|
|
|
$addrs = $this->getHouseholdAddresses()
|
|
->matching($criteria);
|
|
|
|
if ($addrs->count() > 0) {
|
|
return $addrs->first()->getAddress();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function getCurrentHouseholdParticipationShareHousehold(?DateTimeImmutable $at = null): ?HouseholdMember
|
|
{
|
|
$criteria = new Criteria();
|
|
$expr = Criteria::expr();
|
|
$date = null === $at ? new DateTimeImmutable('today') : $at;
|
|
$datef = $date->format('Y-m-d');
|
|
|
|
if (
|
|
null !== ($this->currentHouseholdParticipationAt[$datef] ?? null)) {
|
|
return $this->currentHouseholdParticipationAt[$datef];
|
|
}
|
|
|
|
$criteria
|
|
->where(
|
|
$expr->andX(
|
|
$expr->lte('startDate', $date),
|
|
$expr->orX(
|
|
$expr->isNull('endDate'),
|
|
$expr->gt('endDate', $date)
|
|
),
|
|
$expr->eq('shareHousehold', true)
|
|
)
|
|
);
|
|
|
|
$participations = $this->getHouseholdParticipations()
|
|
->matching($criteria);
|
|
|
|
return $participations->count() > 0 ?
|
|
$this->currentHouseholdParticipationAt[$datef] = $participations->first()
|
|
: null;
|
|
}
|
|
|
|
/**
|
|
* Get the current person address.
|
|
*/
|
|
public function getCurrentPersonAddress(): ?Address
|
|
{
|
|
if (null === $this->currentPersonAddress) {
|
|
return null;
|
|
}
|
|
|
|
return $this->currentPersonAddress->getAddress();
|
|
}
|
|
|
|
public function getDeathdate(): ?DateTimeInterface
|
|
{
|
|
return $this->deathdate;
|
|
}
|
|
|
|
/**
|
|
* Get email.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getEmail()
|
|
{
|
|
return $this->email;
|
|
}
|
|
|
|
/**
|
|
* Get firstName.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getFirstName()
|
|
{
|
|
return $this->firstName;
|
|
}
|
|
|
|
public function getFullnameCanonical(): string
|
|
{
|
|
return $this->fullnameCanonical;
|
|
}
|
|
|
|
/**
|
|
* Get gender.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getGender()
|
|
{
|
|
return $this->gender;
|
|
}
|
|
|
|
public function getGenderComment(): CommentEmbeddable
|
|
{
|
|
return $this->genderComment;
|
|
}
|
|
|
|
/**
|
|
* return gender as a Numeric form.
|
|
* This is used for translations.
|
|
*
|
|
* @return int
|
|
*
|
|
* @deprecated Keep for legacy. Used in Chill 1.5 for feminize before icu translations
|
|
*/
|
|
public function getGenderNumeric()
|
|
{
|
|
switch ($this->getGender()) {
|
|
case self::FEMALE_GENDER:
|
|
return 1;
|
|
|
|
case self::MALE_GENDER:
|
|
return 0;
|
|
|
|
case self::BOTH_GENDER:
|
|
return 2;
|
|
|
|
default:
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
public function getHouseholdAddresses(): Collection
|
|
{
|
|
return $this->householdAddresses;
|
|
}
|
|
|
|
public function getHouseholdParticipations(): Collection
|
|
{
|
|
return $this->householdParticipations;
|
|
}
|
|
|
|
/**
|
|
* Get participation where the person does not share the household.
|
|
*
|
|
* Order by startDate, desc
|
|
*/
|
|
public function getHouseholdParticipationsNotShareHousehold(): Collection
|
|
{
|
|
$criteria = new Criteria();
|
|
$expr = Criteria::expr();
|
|
|
|
$criteria
|
|
->where(
|
|
$expr->eq('shareHousehold', false)
|
|
)
|
|
->orderBy(['startDate' => Criteria::DESC]);
|
|
|
|
return $this->getHouseholdParticipations()
|
|
->matching($criteria);
|
|
}
|
|
|
|
/**
|
|
* Get participation where the person does share the household.
|
|
*
|
|
* Order by startDate, desc
|
|
*/
|
|
public function getHouseholdParticipationsShareHousehold(): Collection
|
|
{
|
|
$criteria = new Criteria();
|
|
$expr = Criteria::expr();
|
|
|
|
$criteria
|
|
->where(
|
|
$expr->eq('shareHousehold', true)
|
|
)
|
|
->orderBy(['startDate' => Criteria::DESC, 'id' => Criteria::DESC]);
|
|
|
|
return $this->getHouseholdParticipations()
|
|
->matching($criteria);
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getLabel()
|
|
{
|
|
return $this->getFirstName() . ' ' . $this->getLastName();
|
|
}
|
|
|
|
/**
|
|
* @deprecated Use `getCurrentPersonAddress` instead
|
|
*
|
|
* @throws Exception
|
|
*
|
|
* @return false|mixed|null
|
|
*/
|
|
public function getLastAddress(?DateTime $from = null)
|
|
{
|
|
return $this->getCurrentPersonAddress();
|
|
}
|
|
|
|
/**
|
|
* Get lastName.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getLastName()
|
|
{
|
|
return $this->lastName;
|
|
}
|
|
|
|
/**
|
|
* Get maritalStatus.
|
|
*
|
|
* @return MaritalStatus
|
|
*/
|
|
public function getMaritalStatus()
|
|
{
|
|
return $this->maritalStatus;
|
|
}
|
|
|
|
public function getMaritalStatusComment(): CommentEmbeddable
|
|
{
|
|
return $this->maritalStatusComment;
|
|
}
|
|
|
|
public function getMaritalStatusDate(): ?DateTimeInterface
|
|
{
|
|
return $this->maritalStatusDate;
|
|
}
|
|
|
|
/**
|
|
* Get memo.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getMemo()
|
|
{
|
|
return $this->memo;
|
|
}
|
|
|
|
/**
|
|
* Get mobilenumber.
|
|
*/
|
|
public function getMobilenumber(): string
|
|
{
|
|
return $this->mobilenumber;
|
|
}
|
|
|
|
/**
|
|
* Get nationality.
|
|
*
|
|
* @return Country
|
|
*/
|
|
public function getNationality(): ?Country
|
|
{
|
|
return $this->nationality;
|
|
}
|
|
|
|
public function getNumberOfChildren(): ?int
|
|
{
|
|
return $this->numberOfChildren;
|
|
}
|
|
|
|
/**
|
|
* Return the opened accompanying period.
|
|
*/
|
|
public function getOpenedAccompanyingPeriod(): ?AccompanyingPeriod
|
|
{
|
|
if ($this->isOpen() === false) {
|
|
return null;
|
|
}
|
|
|
|
foreach ($this->accompanyingPeriodParticipations as $participation) {
|
|
/** @var AccompanyingPeriodParticipation $participation */
|
|
if ($participation->getAccompanyingPeriod()->isOpen()) {
|
|
return $participation->getAccompanyingPeriod();
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Return a collection of participation, where the participation
|
|
* is still opened or in draft state.
|
|
*
|
|
* @return AccompanyingPeriodParticipation[]|Collection
|
|
*/
|
|
public function getOpenedParticipations(): Collection
|
|
{
|
|
// create a criteria for filtering easily
|
|
$criteria = Criteria::create();
|
|
$criteria
|
|
->andWhere(Criteria::expr()->eq('endDate', null))
|
|
->orWhere(Criteria::expr()->gt('endDate', new DateTime('now')));
|
|
|
|
return $this->getAccompanyingPeriodParticipations()
|
|
->matching($criteria)
|
|
->filter(static function (AccompanyingPeriodParticipation $app) {
|
|
return AccompanyingPeriod::STEP_CLOSED !== $app->getAccompanyingPeriod()->getStep();
|
|
});
|
|
}
|
|
|
|
public function getOtherPhoneNumbers(): Collection
|
|
{
|
|
return $this->otherPhoneNumbers;
|
|
}
|
|
|
|
/**
|
|
* Get phonenumber.
|
|
*/
|
|
public function getPhonenumber(): string
|
|
{
|
|
return $this->phonenumber;
|
|
}
|
|
|
|
/**
|
|
* Get placeOfBirth.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getPlaceOfBirth()
|
|
{
|
|
return $this->placeOfBirth;
|
|
}
|
|
|
|
/**
|
|
* Get spokenLanguages.
|
|
*
|
|
* @return ArrayCollection
|
|
*/
|
|
public function getSpokenLanguages()
|
|
{
|
|
return $this->spokenLanguages;
|
|
}
|
|
|
|
public function getUpdatedAt(): ?DateTimeInterface
|
|
{
|
|
return $this->updatedAt;
|
|
}
|
|
|
|
public function getUpdatedBy(): ?User
|
|
{
|
|
return $this->updatedBy;
|
|
}
|
|
|
|
public function hasCurrentHouseholdAddress(?DateTimeImmutable $at = null): bool
|
|
{
|
|
return null !== $this->getCurrentHouseholdAddress($at);
|
|
}
|
|
|
|
/**
|
|
* Return true if the person has two addresses with the
|
|
* same validFrom date (in format 'Y-m-d').
|
|
*/
|
|
public function hasTwoAdressWithSameValidFromDate()
|
|
{
|
|
$validYMDDates = [];
|
|
|
|
foreach ($this->addresses as $ad) {
|
|
$validDate = $ad->getValidFrom()->format('Y-m-d');
|
|
|
|
if (in_array($validDate, $validYMDDates, true)) {
|
|
return true;
|
|
}
|
|
$validYMDDates[] = $validDate;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Validation callback that checks if the accompanying periods are valid.
|
|
*
|
|
* This method add violation errors.
|
|
*
|
|
* @Assert\Callback(
|
|
* groups={"accompanying_period_consistent"}
|
|
* )
|
|
*/
|
|
public function isAccompanyingPeriodValid(ExecutionContextInterface $context)
|
|
{
|
|
$r = $this->checkAccompanyingPeriodsAreNotCollapsing();
|
|
|
|
if (true !== $r) {
|
|
if (self::ERROR_PERIODS_ARE_COLLAPSING === $r['result']) {
|
|
$context->buildViolation('Two accompanying periods have days in commun')
|
|
->atPath('accompanyingPeriods')
|
|
->addViolation();
|
|
}
|
|
|
|
if (self::ERROR_ADDIND_PERIOD_AFTER_AN_OPEN_PERIOD === $r['result']) {
|
|
$context->buildViolation('A period is opened and a period is added after it')
|
|
->atPath('accompanyingPeriods')
|
|
->addViolation();
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Validation callback that checks if the addresses are valid (do not have
|
|
* two addresses with the same validFrom date).
|
|
*
|
|
* This method add violation errors.
|
|
*
|
|
* @Assert\Callback(
|
|
* groups={"addresses_consistent"}
|
|
* )
|
|
*/
|
|
public function isAddressesValid(ExecutionContextInterface $context)
|
|
{
|
|
if ($this->hasTwoAdressWithSameValidFromDate()) {
|
|
$context
|
|
->buildViolation('Two addresses has the same validFrom date')
|
|
->atPath('addresses')
|
|
->addViolation();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check if the person is opened.
|
|
*/
|
|
public function isOpen(): bool
|
|
{
|
|
foreach ($this->getAccompanyingPeriods() as $period) {
|
|
if ($period->isOpen()) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public function isSharingHousehold(?DateTimeImmutable $at = null): bool
|
|
{
|
|
return null !== $this->getCurrentHousehold($at);
|
|
}
|
|
|
|
/**
|
|
* set the Person file as open at the given date.
|
|
*
|
|
* For updating a opening's date, you should update AccompanyingPeriod instance
|
|
* directly.
|
|
*
|
|
* For closing a file, @see this::close
|
|
*
|
|
* To check if the Person and its accompanying period is consistent, use validation.
|
|
*/
|
|
public function open(AccompanyingPeriod $accompanyingPeriod): void
|
|
{
|
|
$this->proxyAccompanyingPeriodOpenState = true;
|
|
$this->addAccompanyingPeriod($accompanyingPeriod);
|
|
}
|
|
|
|
/**
|
|
* Remove AccompanyingPeriod.
|
|
*/
|
|
public function removeAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod): void
|
|
{
|
|
$participation = $this->participationsContainAccompanyingPeriod($accompanyingPeriod);
|
|
|
|
if (!null === $participation) {
|
|
$participation->setEndDate(DateTimeImmutable::class);
|
|
$this->accompanyingPeriodParticipations->removeElement($participation);
|
|
}
|
|
}
|
|
|
|
public function removeAddress(Address $address)
|
|
{
|
|
$this->addresses->removeElement($address);
|
|
}
|
|
|
|
/**
|
|
* @return $this
|
|
*/
|
|
public function removeAltName(PersonAltName $altName)
|
|
{
|
|
if ($this->altNames->contains($altName)) {
|
|
$altName->setPerson(null);
|
|
$this->altNames->removeElement($altName);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return $this
|
|
*/
|
|
public function removeOtherPhoneNumber(PersonPhone $otherPhoneNumber)
|
|
{
|
|
if ($this->otherPhoneNumbers->contains($otherPhoneNumber)) {
|
|
$this->otherPhoneNumbers->removeElement($otherPhoneNumber);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setAcceptEmail(bool $acceptEmail): self
|
|
{
|
|
$this->acceptEmail = $acceptEmail;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setAcceptSMS(bool $acceptSMS): self
|
|
{
|
|
$this->acceptSMS = $acceptSMS;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return $this
|
|
*/
|
|
public function setAltNames(Collection $altNames)
|
|
{
|
|
$this->altNames = $altNames;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set birthdate.
|
|
*
|
|
* @param DateTime $birthdate
|
|
*
|
|
* @return Person
|
|
*/
|
|
public function setBirthdate($birthdate)
|
|
{
|
|
$this->birthdate = $birthdate;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set the center.
|
|
*
|
|
* @return \Chill\PersonBundle\Entity\Person
|
|
*/
|
|
public function setCenter(Center $center)
|
|
{
|
|
$this->center = $center;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set cFData.
|
|
*
|
|
* @param array $cFData
|
|
*
|
|
* @return Report
|
|
*/
|
|
public function setCFData($cFData)
|
|
{
|
|
$this->cFData = $cFData;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set civility.
|
|
*
|
|
* @param Civility $civility
|
|
*
|
|
* @return Person
|
|
*/
|
|
public function setCivility(?Civility $civility = null)
|
|
{
|
|
$this->civility = $civility;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set contactInfo.
|
|
*
|
|
* @param string $contactInfo
|
|
*
|
|
* @return Person
|
|
*/
|
|
public function setcontactInfo($contactInfo)
|
|
{
|
|
if (null === $contactInfo) {
|
|
$contactInfo = '';
|
|
}
|
|
|
|
$this->contactInfo = $contactInfo;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set countryOfBirth.
|
|
*
|
|
* @param Chill\MainBundle\Entity\Country $countryOfBirth
|
|
*
|
|
* @return Person
|
|
*/
|
|
public function setCountryOfBirth(?Country $countryOfBirth = null)
|
|
{
|
|
$this->countryOfBirth = $countryOfBirth;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setCreatedAt(DateTimeInterface $datetime): self
|
|
{
|
|
$this->createdAt = $datetime;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setCreatedBy(User $createdBy): self
|
|
{
|
|
$this->createdBy = $createdBy;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setDeathdate(?DateTimeInterface $deathdate): self
|
|
{
|
|
$this->deathdate = $deathdate;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set email.
|
|
*
|
|
* @param string $email
|
|
*
|
|
* @return Person
|
|
*/
|
|
public function setEmail($email)
|
|
{
|
|
if (null === $email) {
|
|
$email = '';
|
|
}
|
|
|
|
$this->email = $email;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set firstName.
|
|
*
|
|
* @param string $firstName
|
|
*
|
|
* @return Person
|
|
*/
|
|
public function setFirstName($firstName)
|
|
{
|
|
$this->firstName = $firstName;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setFullnameCanonical($fullnameCanonical): Person
|
|
{
|
|
$this->fullnameCanonical = $fullnameCanonical;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set gender.
|
|
*
|
|
* @param string $gender
|
|
*
|
|
* @return Person
|
|
*/
|
|
public function setGender($gender)
|
|
{
|
|
$this->gender = $gender;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setGenderComment(CommentEmbeddable $genderComment): self
|
|
{
|
|
$this->genderComment = $genderComment;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set lastName.
|
|
*
|
|
* @param string $lastName
|
|
*
|
|
* @return Person
|
|
*/
|
|
public function setLastName($lastName)
|
|
{
|
|
$this->lastName = $lastName;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set maritalStatus.
|
|
*
|
|
* @param MaritalStatus $maritalStatus
|
|
*
|
|
* @return Person
|
|
*/
|
|
public function setMaritalStatus(?MaritalStatus $maritalStatus = null)
|
|
{
|
|
$this->maritalStatus = $maritalStatus;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setMaritalStatusComment(CommentEmbeddable $maritalStatusComment): self
|
|
{
|
|
$this->maritalStatusComment = $maritalStatusComment;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setMaritalStatusDate(?DateTimeInterface $maritalStatusDate): self
|
|
{
|
|
$this->maritalStatusDate = $maritalStatusDate;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set memo.
|
|
*
|
|
* @param string $memo
|
|
*
|
|
* @return Person
|
|
*/
|
|
public function setMemo($memo)
|
|
{
|
|
if (null === $memo) {
|
|
$memo = '';
|
|
}
|
|
|
|
if ($this->memo !== $memo) {
|
|
$this->memo = $memo;
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set mobilenumber.
|
|
*
|
|
* @param string $mobilenumber
|
|
*
|
|
* @return Person
|
|
*/
|
|
public function setMobilenumber(?string $mobilenumber = '')
|
|
{
|
|
$this->mobilenumber = (string) $mobilenumber;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set nationality.
|
|
*
|
|
* @param Chill\MainBundle\Entity\Country $nationality
|
|
*
|
|
* @return Person
|
|
*/
|
|
public function setNationality(?Country $nationality = null)
|
|
{
|
|
$this->nationality = $nationality;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setNumberOfChildren(?int $numberOfChildren): self
|
|
{
|
|
$this->numberOfChildren = $numberOfChildren;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return $this
|
|
*/
|
|
public function setOtherPhoneNumbers(Collection $otherPhoneNumbers)
|
|
{
|
|
$this->otherPhoneNumbers = $otherPhoneNumbers;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set phonenumber.
|
|
*
|
|
* @param string $phonenumber
|
|
*
|
|
* @return Person
|
|
*/
|
|
public function setPhonenumber(?string $phonenumber = '')
|
|
{
|
|
$this->phonenumber = (string) $phonenumber;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set placeOfBirth.
|
|
*
|
|
* @param string $placeOfBirth
|
|
*
|
|
* @return Person
|
|
*/
|
|
public function setPlaceOfBirth($placeOfBirth)
|
|
{
|
|
if (null === $placeOfBirth) {
|
|
$placeOfBirth = '';
|
|
}
|
|
|
|
$this->placeOfBirth = $placeOfBirth;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set spokenLanguages.
|
|
*
|
|
* @param type $spokenLanguages
|
|
*
|
|
* @return Person
|
|
*/
|
|
public function setSpokenLanguages($spokenLanguages)
|
|
{
|
|
$this->spokenLanguages = $spokenLanguages;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setUpdatedAt(DateTimeInterface $datetime): self
|
|
{
|
|
$this->updatedAt = $datetime;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function setUpdatedBy(User $user): self
|
|
{
|
|
$this->updatedBy = $user;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* 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 ($participation->getAccompanyingPeriod() === $accompanyingPeriod) {
|
|
return $participation;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|