sf4 deprecated: migrate Doctrine ORM mapping to annotation

This commit is contained in:
2020-07-24 16:46:46 +02:00
parent 97d3afba9b
commit d39666bf8e
10 changed files with 423 additions and 286 deletions

View File

@@ -22,110 +22,248 @@ namespace Chill\PersonBundle\Entity;
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Country;
use Chill\PersonBundle\Entity\MaritalStatus;
use Doctrine\Common\Collections\ArrayCollection;
use Chill\MainBundle\Entity\HasCenterInterface;
use Chill\MainBundle\Entity\Address;
use Doctrine\Common\Collections\Criteria;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* Person
* Person Class
*
* @ORM\Entity(repositoryClass="Chill\PersonBundle\Repository\PersonRepository")
* @ORM\Table(name="chill_person_person",
* indexes={@ORM\Index(
* name="person_names",
* columns={"firstName", "lastName"}
* )})
* sf4 check index name
* @ORM\HasLifecycleCallbacks()
*/
class Person implements HasCenterInterface {
/** @var integer The person's id */
class Person implements HasCenterInterface
{
/**
* The person's id
* @var integer
*
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/** @var string The person's first name */
/**
* The person's first name
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private $firstName;
/** @var string The person's last name */
/**
* The person's last name
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private $lastName;
/**
* @var Collection
*
* @var \Doctrine\Common\Collections\Collection
* @ORM\OneToMany(
* targetEntity="Chill\PersonBundle\Entity\PersonAltName",
* mappedBy="person",
* cascade={"persist", "remove", "merge", "detach"},
* orphanRemoval=true)
*/
private $altNames;
/** @var \DateTime The person's birthdate */
/**
* The person's birthdate
* @var \DateTime
*
* @ORM\Column(type="date", nullable=true)
*/
private $birthdate; //to change in birthdate
/** @var string The person's place of birth */
/**
* The person's place of birth
* @var string
*
* @ORM\Column(type="string", length=255, name="place_of_birth")
*/
private $placeOfBirth = '';
/** @var \Chill\MainBundle\Entity\Country The person's country of birth */
/**
* 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;
/** @var \Chill\MainBundle\Entity\Country The person's nationality */
/**
* 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;
/** @var string The person's gender */
/**
* The person's gender
* @var string
*
* @ORM\Column(type="string", length=9, nullable=true)
*/
private $gender;
const MALE_GENDER = 'man';
const FEMALE_GENDER = 'woman';
const BOTH_GENDER = 'both';
/** @var \Chill\PersonBundle\Entity\MaritalStatus The marital status of the person */
/**
* The marital status of the person
* @var MaritalStatus
*
* @ORM\ManyToOne(targetEntity="Chill\PersonBundle\Entity\MaritalStatus")
* @ORM\JoinColumn(nullable=true)
*/
private $maritalStatus;
/** @var string Contact information for contacting the person */
/**
* Contact information for contacting the person
* @var string
*
* @ORM\Column(type="text", nullable=true)
*/
private $contactInfo = '';
/** @var string The person's email */
/**
* The person's email
* @var string
*
* @ORM\Column(type="text", nullable=true)
*/
private $email = '';
/** @var string The person's phonenumber */
/**
* The person's phonenumber
* @var string
*
* @ORM\Column(type="text", length=40, nullable=true)
*/
private $phonenumber = '';
/** @var string The person's mobile phone number */
/**
* The person's mobile phone number
* @var string
*
* @ORM\Column(type="text", length=40, nullable=true)
*/
private $mobilenumber = '';
//TO-ADD : caseOpeningDate
//TO-ADD caseOpeningDate
//TO-ADD nativeLanguag
/**
* @var \Doctrine\Common\Collections\ArrayCollection The person's spoken
* languages (ArrayCollection of Languages)
* 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;
/** @var \Chill\MainBundle\Entity\Center The person's center */
/**
* The person's center
* @var Center
*
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Center")
* @ORM\JoinColumn(nullable=false)
*/
private $center;
/**
* @var \Doctrine\Common\Collections\ArrayCollection The person's
* accompanying periods (when the person was accompanied by the center)*/
* The person's accompanying periods (when the person was accompanied by the center)
* @var ArrayCollection
*
* @ORM\OneToMany(
* targetEntity="Chill\PersonBundle\Entity\AccompanyingPeriod",
* mappedBy="person",
* cascade={"persist", "remove", "merge", "detach"})
*/
private $accompanyingPeriods; //TO-CHANGE in accompanyingHistory
/** @var string A remark over the person */
/**
* A remark over the person
* @var string
*
* @ORM\Column(type="text")
*/
private $memo = ''; // TO-CHANGE in remark
/**
* @var boolean
* @deprecated
*
* @ORM\Column(type="boolean")
*/
private $proxyAccompanyingPeriodOpenState = false; //TO-DELETE ?
/** @var array Array where customfield's data are stored */
/**
* Array where customfield's data are stored
* @var array
*
* @ORM\Column(type="json_array")
*/
private $cFData;
/**
* Addresses
* @var Collection
*
* @var \Doctrine\Common\Collections\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 string
*
* @ORM\Column(type="text", nullable=true)
*/
private $fullnameCanonical;
public function __construct(\DateTime $opening = null) {
/**
* Person constructor.
*
* @param \DateTime|null $opening
*/
public function __construct(\DateTime $opening = null)
{
$this->accompanyingPeriods = new ArrayCollection();
$this->spokenLanguages = new ArrayCollection();
$this->addresses = new ArrayCollection();
@@ -139,15 +277,20 @@ class Person implements HasCenterInterface {
}
/**
* @param \Chill\PersonBundle\Entity\AccompanyingPeriod $accompanyingPeriod
* @param AccompanyingPeriod $accompanyingPeriod
* @uses AccompanyingPeriod::setPerson
*/
public function addAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod) {
public function addAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod)
{
$accompanyingPeriod->setPerson($this);
$this->accompanyingPeriods->add($accompanyingPeriod);
}
public function removeAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod) {
/**
* @param AccompanyingPeriod $accompanyingPeriod
*/
public function removeAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod)
{
$this->accompanyingPeriods->remove($accompanyingPeriod);
}
@@ -161,15 +304,15 @@ class Person implements HasCenterInterface {
*
* To check if the Person and its accompanying period is consistent, use validation.
*
* @param \Chill\PersonBundle\Entity\AccompanyingPeriod $accompanyingPeriod
* @param AccompanyingPeriod $accompanyingPeriod
*/
public function open(AccompanyingPeriod $accompanyingPeriod) {
public function open(AccompanyingPeriod $accompanyingPeriod)
{
$this->proxyAccompanyingPeriodOpenState = true;
$this->addAccompanyingPeriod($accompanyingPeriod);
}
/**
*
* Set the Person file as closed at the given date.
*
* For update a closing date, you should update AccompanyingPeriod instance
@@ -190,7 +333,8 @@ class Person implements HasCenterInterface {
*
* @return AccompanyingPeriod
*/
public function getOpenedAccompanyingPeriod() {
public function getOpenedAccompanyingPeriod()
{
if ($this->isOpen() === false) {
return null;
}
@@ -214,10 +358,10 @@ class Person implements HasCenterInterface {
}
/**
*
* @return \Doctrine\Common\Collections\ArrayCollection
* @return ArrayCollection
*/
public function getAccompanyingPeriods() {
public function getAccompanyingPeriods()
{
return $this->accompanyingPeriods;
}
@@ -227,7 +371,8 @@ class Person implements HasCenterInterface {
*
* @return AccompanyingPeriod[]
*/
public function getAccompanyingPeriodsOrdered() {
public function getAccompanyingPeriodsOrdered()
{
$periods = $this->getAccompanyingPeriods()->toArray();
//order by date :
@@ -332,18 +477,29 @@ class Person implements HasCenterInterface {
return $this->lastName;
}
public function getAltNames(): \Doctrine\Common\Collections\Collection
/**
* @return Collection
*/
public function getAltNames(): Collection
{
return $this->altNames;
}
public function setAltNames(\Doctrine\Common\Collections\Collection $altNames)
/**
* @param Collection $altNames
* @return $this
*/
public function setAltNames(Collection $altNames)
{
$this->altNames = $altNames;
return $this;
}
/**
* @param PersonAltName $altName
* @return $this
*/
public function addAltName(PersonAltName $altName)
{
if (FALSE === $this->altNames->contains($altName)) {
@@ -354,6 +510,10 @@ class Person implements HasCenterInterface {
return $this;
}
/**
* @param PersonAltName $altName
* @return $this
*/
public function removeAltName(PersonAltName $altName)
{
if ($this->altNames->contains($altName)) {
@@ -387,7 +547,6 @@ class Person implements HasCenterInterface {
return $this->birthdate;
}
/**
* Set placeOfBirth
*
@@ -443,7 +602,8 @@ class Person implements HasCenterInterface {
* This is used for translations
* @return int
*/
public function getGenderNumeric() {
public function getGenderNumeric()
{
if ($this->getGender() == self::FEMALE_GENDER) {
return 1;
} else {
@@ -483,7 +643,7 @@ class Person implements HasCenterInterface {
/**
* Set maritalStatus
*
* @param \Chill\PersonBundle\Entity\MaritalStatus $maritalStatus
* @param MaritalStatus $maritalStatus
* @return Person
*/
public function setMaritalStatus(MaritalStatus $maritalStatus = null)
@@ -495,7 +655,7 @@ class Person implements HasCenterInterface {
/**
* Get maritalStatus
*
* @return \Chill\PersonBundle\Entity\MaritalStatus
* @return MaritalStatus
*/
public function getMaritalStatus()
{
@@ -600,15 +760,19 @@ class Person implements HasCenterInterface {
{
return $this->nationality;
}
public function getLabel() {
/**
* @return string
*/
public function getLabel()
{
return $this->getFirstName()." ".$this->getLastName();
}
/**
* Get center
*
* @return \Chill\MainBundle\Entity\Center
* @return Center
*/
public function getCenter()
{
@@ -618,16 +782,15 @@ class Person implements HasCenterInterface {
/**
* Set the center
*
* @param \Chill\MainBundle\Entity\Center $center
* @param Center $center
* @return \Chill\PersonBundle\Entity\Person
*/
public function setCenter(\Chill\MainBundle\Entity\Center $center)
public function setCenter(Center $center)
{
$this->center = $center;
return $this;
}
/**
* Set cFData
*
@@ -700,7 +863,10 @@ class Person implements HasCenterInterface {
{
return $this->mobilenumber;
}
/**
* @return string
*/
public function __toString()
{
return $this->getLabel();
@@ -728,14 +894,21 @@ class Person implements HasCenterInterface {
{
return $this->spokenLanguages;
}
/**
* @param Address $address
* @return $this
*/
public function addAddress(Address $address)
{
$this->addresses[] = $address;
return $this;
}
/**
* @param Address $address
*/
public function removeAddress(Address $address)
{
$this->addresses->removeElement($address);
@@ -751,7 +924,11 @@ class Person implements HasCenterInterface {
{
return $this->addresses;
}
/**
* @param \DateTime|null $date
* @return null
*/
public function getLastAddress(\DateTime $date = null)
{
if ($date === null) {