mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-01 14:36:13 +00:00
add mobilenumber + validation on email and phonenumber (regex)
This commit is contained in:
parent
db00a0d265
commit
2f03f925ca
@ -5,7 +5,7 @@ namespace Chill\PersonBundle\Entity;
|
|||||||
/*
|
/*
|
||||||
* Chill is a software for social workers
|
* Chill is a software for social workers
|
||||||
*
|
*
|
||||||
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||||
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
|
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
@ -48,17 +48,17 @@ class Person implements HasCenterInterface {
|
|||||||
|
|
||||||
/** @var string The person's place of birth */
|
/** @var string The person's place of birth */
|
||||||
private $placeOfBirth = '';
|
private $placeOfBirth = '';
|
||||||
|
|
||||||
/** @var \Chill\MainBundle\Entity\Country The person's country of birth */
|
/** @var \Chill\MainBundle\Entity\Country The person's country of birth */
|
||||||
private $countryOfBirth;
|
private $countryOfBirth;
|
||||||
|
|
||||||
/** @var \Chill\MainBundle\Entity\Country The person's nationality */
|
/** @var \Chill\MainBundle\Entity\Country The person's nationality */
|
||||||
private $nationality;
|
private $nationality;
|
||||||
|
|
||||||
/** @var string The person's gender */
|
/** @var string The person's gender */
|
||||||
private $gender;
|
private $gender;
|
||||||
|
|
||||||
const MALE_GENDER = 'man';
|
const MALE_GENDER = 'man';
|
||||||
const FEMALE_GENDER = 'woman';
|
const FEMALE_GENDER = 'woman';
|
||||||
|
|
||||||
/** @var \Chill\PersonBundle\Entity\MaritalStatus The marital status of the person */
|
/** @var \Chill\PersonBundle\Entity\MaritalStatus The marital status of the person */
|
||||||
@ -72,27 +72,30 @@ class Person implements HasCenterInterface {
|
|||||||
/** @var string The person's phonenumber */
|
/** @var string The person's phonenumber */
|
||||||
private $phonenumber = '';
|
private $phonenumber = '';
|
||||||
|
|
||||||
|
/** @var string The person's mobile phone number */
|
||||||
|
private $mobilenumber = '';
|
||||||
|
|
||||||
//TO-ADD : caseOpeningDate
|
//TO-ADD : caseOpeningDate
|
||||||
|
|
||||||
//TO-ADD nativeLanguag
|
//TO-ADD nativeLanguag
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Doctrine\Common\Collections\ArrayCollection The person's spoken
|
* @var \Doctrine\Common\Collections\ArrayCollection The person's spoken
|
||||||
* languages (ArrayCollection of Languages)
|
* languages (ArrayCollection of Languages)
|
||||||
*/
|
*/
|
||||||
private $spokenLanguages;
|
private $spokenLanguages;
|
||||||
|
|
||||||
/** @var \Chill\MainBundle\Entity\Center The person's center */
|
/** @var \Chill\MainBundle\Entity\Center The person's center */
|
||||||
private $center;
|
private $center;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Doctrine\Common\Collections\ArrayCollection The person's
|
* @var \Doctrine\Common\Collections\ArrayCollection The person's
|
||||||
* accompanying periods (when the person was accompanied by the center)*/
|
* accompanying periods (when the person was accompanied by the center)*/
|
||||||
private $accompanyingPeriods; //TO-CHANGE in accompanyingHistory
|
private $accompanyingPeriods; //TO-CHANGE in accompanyingHistory
|
||||||
|
|
||||||
/** @var string A remark over the person */
|
/** @var string A remark over the person */
|
||||||
private $memo = ''; // TO-CHANGE in remark
|
private $memo = ''; // TO-CHANGE in remark
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var boolean
|
* @var boolean
|
||||||
* @deprecated
|
* @deprecated
|
||||||
@ -102,25 +105,25 @@ class Person implements HasCenterInterface {
|
|||||||
|
|
||||||
/** @var array Array where customfield's data are stored */
|
/** @var array Array where customfield's data are stored */
|
||||||
private $cFData;
|
private $cFData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var \Doctrine\Common\Collections\Collection
|
* @var \Doctrine\Common\Collections\Collection
|
||||||
*/
|
*/
|
||||||
private $addresses;
|
private $addresses;
|
||||||
|
|
||||||
public function __construct(\DateTime $opening = null) {
|
public function __construct(\DateTime $opening = null) {
|
||||||
$this->accompanyingPeriods = new ArrayCollection();
|
$this->accompanyingPeriods = new ArrayCollection();
|
||||||
$this->spokenLanguages = new ArrayCollection();
|
$this->spokenLanguages = new ArrayCollection();
|
||||||
$this->addresses = new ArrayCollection();
|
$this->addresses = new ArrayCollection();
|
||||||
|
|
||||||
if ($opening === null) {
|
if ($opening === null) {
|
||||||
$opening = new \DateTime();
|
$opening = new \DateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->open(new AccompanyingPeriod($opening));
|
$this->open(new AccompanyingPeriod($opening));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Chill\PersonBundle\Entity\AccompanyingPeriod $accompanyingPeriod
|
* @param \Chill\PersonBundle\Entity\AccompanyingPeriod $accompanyingPeriod
|
||||||
* @uses AccompanyingPeriod::setPerson
|
* @uses AccompanyingPeriod::setPerson
|
||||||
@ -129,21 +132,21 @@ class Person implements HasCenterInterface {
|
|||||||
$accompanyingPeriod->setPerson($this);
|
$accompanyingPeriod->setPerson($this);
|
||||||
$this->accompanyingPeriods->add($accompanyingPeriod);
|
$this->accompanyingPeriods->add($accompanyingPeriod);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod) {
|
public function removeAccompanyingPeriod(AccompanyingPeriod $accompanyingPeriod) {
|
||||||
$this->accompanyingPeriods->remove($accompanyingPeriod);
|
$this->accompanyingPeriods->remove($accompanyingPeriod);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the Person file as open at the given date.
|
* set the Person file as open at the given date.
|
||||||
*
|
*
|
||||||
* For updating a opening's date, you should update AccompanyingPeriod instance
|
* For updating a opening's date, you should update AccompanyingPeriod instance
|
||||||
* directly.
|
* directly.
|
||||||
*
|
*
|
||||||
* For closing a file, @see this::close
|
* For closing a file, @see this::close
|
||||||
*
|
*
|
||||||
* To check if the Person and its accompanying period is consistent, use validation.
|
* To check if the Person and its accompanying period is consistent, use validation.
|
||||||
*
|
*
|
||||||
* @param \Chill\PersonBundle\Entity\AccompanyingPeriod $accompanyingPeriod
|
* @param \Chill\PersonBundle\Entity\AccompanyingPeriod $accompanyingPeriod
|
||||||
*/
|
*/
|
||||||
public function open(AccompanyingPeriod $accompanyingPeriod) {
|
public function open(AccompanyingPeriod $accompanyingPeriod) {
|
||||||
@ -152,42 +155,42 @@ class Person implements HasCenterInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Set the Person file as closed at the given date.
|
* Set the Person file as closed at the given date.
|
||||||
*
|
*
|
||||||
* For update a closing date, you should update AccompanyingPeriod instance
|
* For update a closing date, you should update AccompanyingPeriod instance
|
||||||
* directly.
|
* directly.
|
||||||
*
|
*
|
||||||
* To check if the Person and its accompanying period are consistent, use validation.
|
* To check if the Person and its accompanying period are consistent, use validation.
|
||||||
*
|
*
|
||||||
* @param accompanyingPeriod
|
* @param accompanyingPeriod
|
||||||
* @throws \Exception if two lines of the accompanying period are open.
|
* @throws \Exception if two lines of the accompanying period are open.
|
||||||
*/
|
*/
|
||||||
public function close(AccompanyingPeriod $accompanyingPeriod = null)
|
public function close(AccompanyingPeriod $accompanyingPeriod = null)
|
||||||
{
|
{
|
||||||
$this->proxyAccompanyingPeriodOpenState = false;
|
$this->proxyAccompanyingPeriodOpenState = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the opened accompanying period.
|
* Return the opened accompanying period.
|
||||||
*
|
*
|
||||||
* @return AccompanyingPeriod
|
* @return AccompanyingPeriod
|
||||||
*/
|
*/
|
||||||
public function getOpenedAccompanyingPeriod() {
|
public function getOpenedAccompanyingPeriod() {
|
||||||
if ($this->isOpen() === false) {
|
if ($this->isOpen() === false) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->accompanyingPeriods as $period) {
|
foreach ($this->accompanyingPeriods as $period) {
|
||||||
if ($period->isOpen()) {
|
if ($period->isOpen()) {
|
||||||
return $period;
|
return $period;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the opened accompanying period.
|
* Returns the opened accompanying period.
|
||||||
*
|
*
|
||||||
* @return AccompanyingPeriod
|
* @return AccompanyingPeriod
|
||||||
* @deprecated since 1.1 use `getOpenedAccompanyingPeriod instead
|
* @deprecated since 1.1 use `getOpenedAccompanyingPeriod instead
|
||||||
*/
|
*/
|
||||||
@ -195,74 +198,74 @@ class Person implements HasCenterInterface {
|
|||||||
{
|
{
|
||||||
return $this->getOpenedAccompanyingPeriod();
|
return $this->getOpenedAccompanyingPeriod();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return \Doctrine\Common\Collections\ArrayCollection
|
* @return \Doctrine\Common\Collections\ArrayCollection
|
||||||
*/
|
*/
|
||||||
public function getAccompanyingPeriods() {
|
public function getAccompanyingPeriods() {
|
||||||
return $this->accompanyingPeriods;
|
return $this->accompanyingPeriods;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the accompanying periods of a give person with the
|
* Get the accompanying periods of a give person with the
|
||||||
* chronological order.
|
* chronological order.
|
||||||
*
|
*
|
||||||
* @return AccompanyingPeriod[]
|
* @return AccompanyingPeriod[]
|
||||||
*/
|
*/
|
||||||
public function getAccompanyingPeriodsOrdered() {
|
public function getAccompanyingPeriodsOrdered() {
|
||||||
$periods = $this->getAccompanyingPeriods()->toArray();
|
$periods = $this->getAccompanyingPeriods()->toArray();
|
||||||
|
|
||||||
//order by date :
|
//order by date :
|
||||||
usort($periods, function($a, $b) {
|
usort($periods, function($a, $b) {
|
||||||
$dateA = $a->getOpeningDate();
|
$dateA = $a->getOpeningDate();
|
||||||
$dateB = $b->getOpeningDate();
|
$dateB = $b->getOpeningDate();
|
||||||
|
|
||||||
if ($dateA == $dateB) {
|
if ($dateA == $dateB) {
|
||||||
$dateEA = $a->getClosingDate();
|
$dateEA = $a->getClosingDate();
|
||||||
$dateEB = $b->getClosingDate();
|
$dateEB = $b->getClosingDate();
|
||||||
|
|
||||||
if ($dateEA == $dateEB) {
|
if ($dateEA == $dateEB) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dateEA < $dateEB) {
|
if ($dateEA < $dateEB) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
return +1;
|
return +1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dateA < $dateB) {
|
if ($dateA < $dateB) {
|
||||||
return -1 ;
|
return -1 ;
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return $periods;
|
return $periods;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if the person is opened
|
* check if the person is opened
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function isOpen()
|
public function isOpen()
|
||||||
{
|
{
|
||||||
foreach ($this->getAccompanyingPeriods() as $period) {
|
foreach ($this->getAccompanyingPeriods() as $period) {
|
||||||
if ($period->isOpen()) {
|
if ($period->isOpen()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get id
|
* Get id
|
||||||
*
|
*
|
||||||
* @return integer
|
* @return integer
|
||||||
*/
|
*/
|
||||||
public function getId()
|
public function getId()
|
||||||
{
|
{
|
||||||
@ -278,14 +281,14 @@ class Person implements HasCenterInterface {
|
|||||||
public function setFirstName($firstName)
|
public function setFirstName($firstName)
|
||||||
{
|
{
|
||||||
$this->firstName = $firstName;
|
$this->firstName = $firstName;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get firstName
|
* Get firstName
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getFirstName()
|
public function getFirstName()
|
||||||
{
|
{
|
||||||
@ -301,14 +304,14 @@ class Person implements HasCenterInterface {
|
|||||||
public function setLastName($lastName)
|
public function setLastName($lastName)
|
||||||
{
|
{
|
||||||
$this->lastName = $lastName;
|
$this->lastName = $lastName;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get lastName
|
* Get lastName
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getLastName()
|
public function getLastName()
|
||||||
{
|
{
|
||||||
@ -324,14 +327,14 @@ class Person implements HasCenterInterface {
|
|||||||
public function setBirthdate($birthdate)
|
public function setBirthdate($birthdate)
|
||||||
{
|
{
|
||||||
$this->birthdate = $birthdate;
|
$this->birthdate = $birthdate;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get birthdate
|
* Get birthdate
|
||||||
*
|
*
|
||||||
* @return \DateTime
|
* @return \DateTime
|
||||||
*/
|
*/
|
||||||
public function getBirthdate()
|
public function getBirthdate()
|
||||||
{
|
{
|
||||||
@ -350,16 +353,16 @@ class Person implements HasCenterInterface {
|
|||||||
if ($placeOfBirth === null) {
|
if ($placeOfBirth === null) {
|
||||||
$placeOfBirth = '';
|
$placeOfBirth = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->placeOfBirth = $placeOfBirth;
|
$this->placeOfBirth = $placeOfBirth;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get placeOfBirth
|
* Get placeOfBirth
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getPlaceOfBirth()
|
public function getPlaceOfBirth()
|
||||||
{
|
{
|
||||||
@ -375,20 +378,20 @@ class Person implements HasCenterInterface {
|
|||||||
public function setGender($gender)
|
public function setGender($gender)
|
||||||
{
|
{
|
||||||
$this->gender = $gender;
|
$this->gender = $gender;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get gender
|
* Get gender
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getGender()
|
public function getGender()
|
||||||
{
|
{
|
||||||
return $this->gender;
|
return $this->gender;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return gender as a Numeric form.
|
* return gender as a Numeric form.
|
||||||
* This is used for translations
|
* This is used for translations
|
||||||
@ -413,18 +416,18 @@ class Person implements HasCenterInterface {
|
|||||||
if ($memo === null) {
|
if ($memo === null) {
|
||||||
$memo = '';
|
$memo = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->memo !== $memo) {
|
if ($this->memo !== $memo) {
|
||||||
$this->memo = $memo;
|
$this->memo = $memo;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get memo
|
* Get memo
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getMemo()
|
public function getMemo()
|
||||||
{
|
{
|
||||||
@ -446,7 +449,7 @@ class Person implements HasCenterInterface {
|
|||||||
/**
|
/**
|
||||||
* Get maritalStatus
|
* Get maritalStatus
|
||||||
*
|
*
|
||||||
* @return \Chill\PersonBundle\Entity\MaritalStatus
|
* @return \Chill\PersonBundle\Entity\MaritalStatus
|
||||||
*/
|
*/
|
||||||
public function getMaritalStatus()
|
public function getMaritalStatus()
|
||||||
{
|
{
|
||||||
@ -465,16 +468,16 @@ class Person implements HasCenterInterface {
|
|||||||
if ($email === null) {
|
if ($email === null) {
|
||||||
$email = '';
|
$email = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->email = $email;
|
$this->email = $email;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get email
|
* Get email
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getEmail()
|
public function getEmail()
|
||||||
{
|
{
|
||||||
@ -488,7 +491,7 @@ class Person implements HasCenterInterface {
|
|||||||
* @return Person
|
* @return Person
|
||||||
*/
|
*/
|
||||||
public function setCountryOfBirth(Country $countryOfBirth = null)
|
public function setCountryOfBirth(Country $countryOfBirth = null)
|
||||||
{
|
{
|
||||||
$this->countryOfBirth = $countryOfBirth;
|
$this->countryOfBirth = $countryOfBirth;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -496,7 +499,7 @@ class Person implements HasCenterInterface {
|
|||||||
/**
|
/**
|
||||||
* Get countryOfBirth
|
* Get countryOfBirth
|
||||||
*
|
*
|
||||||
* @return Chill\MainBundle\Entity\Country
|
* @return Chill\MainBundle\Entity\Country
|
||||||
*/
|
*/
|
||||||
public function getCountryOfBirth()
|
public function getCountryOfBirth()
|
||||||
{
|
{
|
||||||
@ -512,27 +515,27 @@ class Person implements HasCenterInterface {
|
|||||||
public function setNationality(Country $nationality = null)
|
public function setNationality(Country $nationality = null)
|
||||||
{
|
{
|
||||||
$this->nationality = $nationality;
|
$this->nationality = $nationality;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get nationality
|
* Get nationality
|
||||||
*
|
*
|
||||||
* @return Chill\MainBundle\Entity\Country
|
* @return Chill\MainBundle\Entity\Country
|
||||||
*/
|
*/
|
||||||
public function getNationality()
|
public function getNationality()
|
||||||
{
|
{
|
||||||
return $this->nationality;
|
return $this->nationality;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLabel() {
|
public function getLabel() {
|
||||||
return $this->getFirstName()." ".$this->getLastName();
|
return $this->getFirstName()." ".$this->getLastName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get center
|
* Get center
|
||||||
*
|
*
|
||||||
* @return \Chill\MainBundle\Entity\Center
|
* @return \Chill\MainBundle\Entity\Center
|
||||||
*/
|
*/
|
||||||
public function getCenter()
|
public function getCenter()
|
||||||
@ -542,7 +545,7 @@ class Person implements HasCenterInterface {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the center
|
* Set the center
|
||||||
*
|
*
|
||||||
* @param \Chill\MainBundle\Entity\Center $center
|
* @param \Chill\MainBundle\Entity\Center $center
|
||||||
* @return \Chill\PersonBundle\Entity\Person
|
* @return \Chill\PersonBundle\Entity\Person
|
||||||
*/
|
*/
|
||||||
@ -552,7 +555,7 @@ class Person implements HasCenterInterface {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set cFData
|
* Set cFData
|
||||||
*
|
*
|
||||||
@ -589,20 +592,43 @@ class Person implements HasCenterInterface {
|
|||||||
public function setPhonenumber($phonenumber = '')
|
public function setPhonenumber($phonenumber = '')
|
||||||
{
|
{
|
||||||
$this->phonenumber = $phonenumber;
|
$this->phonenumber = $phonenumber;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get phonenumber
|
* Get phonenumber
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getPhonenumber()
|
public function getPhonenumber()
|
||||||
{
|
{
|
||||||
return $this->phonenumber;
|
return $this->phonenumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set mobilenumber
|
||||||
|
*
|
||||||
|
* @param string $mobilenumber
|
||||||
|
* @return Person
|
||||||
|
*/
|
||||||
|
public function setMobilenumber($mobilenumber = '')
|
||||||
|
{
|
||||||
|
$this->mobilenumber = $mobilenumber;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get mobilenumber
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getMobilenumber()
|
||||||
|
{
|
||||||
|
return $this->mobilenumber;
|
||||||
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
return $this->getLabel();
|
return $this->getLabel();
|
||||||
@ -630,62 +656,62 @@ class Person implements HasCenterInterface {
|
|||||||
{
|
{
|
||||||
return $this->spokenLanguages;
|
return $this->spokenLanguages;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addAddress(Address $address)
|
public function addAddress(Address $address)
|
||||||
{
|
{
|
||||||
$this->addresses[] = $address;
|
$this->addresses[] = $address;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeAddress(Address $address)
|
public function removeAddress(Address $address)
|
||||||
{
|
{
|
||||||
$this->addresses->removeElement($address);
|
$this->addresses->removeElement($address);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* By default, the addresses are ordered by date, descending (the most
|
* By default, the addresses are ordered by date, descending (the most
|
||||||
* recent first)
|
* recent first)
|
||||||
*
|
*
|
||||||
* @return \Chill\MainBundle\Entity\Address[]
|
* @return \Chill\MainBundle\Entity\Address[]
|
||||||
*/
|
*/
|
||||||
public function getAddresses()
|
public function getAddresses()
|
||||||
{
|
{
|
||||||
return $this->addresses;
|
return $this->addresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLastAddress(\DateTime $date = null)
|
public function getLastAddress(\DateTime $date = null)
|
||||||
{
|
{
|
||||||
if ($date === null) {
|
if ($date === null) {
|
||||||
$date = new \DateTime('now');
|
$date = new \DateTime('now');
|
||||||
}
|
}
|
||||||
|
|
||||||
$addresses = $this->getAddresses();
|
$addresses = $this->getAddresses();
|
||||||
|
|
||||||
if ($addresses == null) {
|
if ($addresses == null) {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $addresses->first();
|
return $addresses->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validation callback that checks if the accompanying periods are valid
|
* Validation callback that checks if the accompanying periods are valid
|
||||||
*
|
*
|
||||||
* This method add violation errors.
|
* This method add violation errors.
|
||||||
*/
|
*/
|
||||||
public function isAccompanyingPeriodValid(ExecutionContextInterface $context)
|
public function isAccompanyingPeriodValid(ExecutionContextInterface $context)
|
||||||
{
|
{
|
||||||
$r = $this->checkAccompanyingPeriodsAreNotCollapsing();
|
$r = $this->checkAccompanyingPeriodsAreNotCollapsing();
|
||||||
|
|
||||||
if ($r !== true) {
|
if ($r !== true) {
|
||||||
if ($r['result'] === self::ERROR_PERIODS_ARE_COLLAPSING) {
|
if ($r['result'] === self::ERROR_PERIODS_ARE_COLLAPSING) {
|
||||||
$context->addViolationAt('accompanyingPeriods',
|
$context->addViolationAt('accompanyingPeriods',
|
||||||
'Two accompanying periods have days in commun',
|
'Two accompanying periods have days in commun',
|
||||||
array());
|
array());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($r['result'] === self::ERROR_ADDIND_PERIOD_AFTER_AN_OPEN_PERIOD) {
|
if ($r['result'] === self::ERROR_ADDIND_PERIOD_AFTER_AN_OPEN_PERIOD) {
|
||||||
$context->addViolationAt('accompanyingPeriods',
|
$context->addViolationAt('accompanyingPeriods',
|
||||||
'A period is opened and a period is added after it',
|
'A period is opened and a period is added after it',
|
||||||
@ -693,27 +719,27 @@ class Person implements HasCenterInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if the person has two addresses with the
|
* Return true if the person has two addresses with the
|
||||||
* same validFrom date (in format 'Y-m-d')
|
* same validFrom date (in format 'Y-m-d')
|
||||||
*/
|
*/
|
||||||
public function hasTwoAdressWithSameValidFromDate()
|
public function hasTwoAdressWithSameValidFromDate()
|
||||||
{
|
{
|
||||||
$validYMDDates = array();
|
$validYMDDates = array();
|
||||||
|
|
||||||
foreach ($this->addresses as $ad) {
|
foreach ($this->addresses as $ad) {
|
||||||
$validDate = $ad->getValidFrom()->format('Y-m-d');
|
$validDate = $ad->getValidFrom()->format('Y-m-d');
|
||||||
|
|
||||||
if (in_array($validDate, $validYMDDates)) {
|
if (in_array($validDate, $validYMDDates)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$validYMDDates[] = $validDate;
|
$validYMDDates[] = $validDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validation callback that checks if the addresses are valid (do not have
|
* Validation callback that checks if the addresses are valid (do not have
|
||||||
* two addresses with the same validFrom date)
|
* two addresses with the same validFrom date)
|
||||||
@ -730,18 +756,18 @@ class Person implements HasCenterInterface {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const ERROR_PERIODS_ARE_COLLAPSING = 1; // when two different periods
|
const ERROR_PERIODS_ARE_COLLAPSING = 1; // when two different periods
|
||||||
// have days in commun
|
// have days in commun
|
||||||
const ERROR_ADDIND_PERIOD_AFTER_AN_OPEN_PERIOD = 2; // where there exist
|
const ERROR_ADDIND_PERIOD_AFTER_AN_OPEN_PERIOD = 2; // where there exist
|
||||||
// a period opened and another one after it
|
// a period opened and another one after it
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function used for validation that check if the accompanying periods of
|
* Function used for validation that check if the accompanying periods of
|
||||||
* the person are not collapsing (i.e. have not shared days) or having
|
* the person are not collapsing (i.e. have not shared days) or having
|
||||||
* a period after an open period.
|
* a period after an open period.
|
||||||
*
|
*
|
||||||
* @return true | array True if the accompanying periods are not collapsing,
|
* @return true | array True if the accompanying periods are not collapsing,
|
||||||
* an array with data for displaying the error
|
* an array with data for displaying the error
|
||||||
*/
|
*/
|
||||||
@ -750,12 +776,12 @@ class Person implements HasCenterInterface {
|
|||||||
$periods = $this->getAccompanyingPeriodsOrdered();
|
$periods = $this->getAccompanyingPeriodsOrdered();
|
||||||
$periodsNbr = sizeof($periods);
|
$periodsNbr = sizeof($periods);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
while($i < $periodsNbr - 1) {
|
while($i < $periodsNbr - 1) {
|
||||||
$periodI = $periods[$i];
|
$periodI = $periods[$i];
|
||||||
$periodAfterI = $periods[$i + 1];
|
$periodAfterI = $periods[$i + 1];
|
||||||
|
|
||||||
if($periodI->isOpen()) {
|
if($periodI->isOpen()) {
|
||||||
return array(
|
return array(
|
||||||
'result' => self::ERROR_ADDIND_PERIOD_AFTER_AN_OPEN_PERIOD,
|
'result' => self::ERROR_ADDIND_PERIOD_AFTER_AN_OPEN_PERIOD,
|
||||||
'dateOpening' => $periodAfterI->getOpeningDate(),
|
'dateOpening' => $periodAfterI->getOpeningDate(),
|
||||||
@ -766,14 +792,14 @@ class Person implements HasCenterInterface {
|
|||||||
return array(
|
return array(
|
||||||
'result' => self::ERROR_PERIODS_ARE_COLLAPSING,
|
'result' => self::ERROR_PERIODS_ARE_COLLAPSING,
|
||||||
'dateOpening' => $periodI->getOpeningDate(),
|
'dateOpening' => $periodI->getOpeningDate(),
|
||||||
|
|
||||||
'dateClosing' => $periodI->getClosingDate(),
|
'dateClosing' => $periodI->getClosingDate(),
|
||||||
'date' => $periodAfterI->getOpeningDate()
|
'date' => $periodAfterI->getOpeningDate()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
|||||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||||
|
|
||||||
use Chill\PersonBundle\Form\Type\GenderType;
|
use Chill\PersonBundle\Form\Type\GenderType;
|
||||||
use Chill\MainBundle\Form\Type\Select2CountryType;
|
use Chill\MainBundle\Form\Type\Select2CountryType;
|
||||||
@ -80,7 +81,7 @@ class PersonType extends AbstractType
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->config['email'] === 'visible') {
|
if ($this->config['email'] === 'visible') {
|
||||||
$builder->add('email', TextareaType::class, array('required' => false));
|
$builder->add('email', EmailType::class, array('required' => false));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->config['country_of_birth'] === 'visible') {
|
if ($this->config['country_of_birth'] === 'visible') {
|
||||||
|
@ -30,6 +30,17 @@ Chill\PersonBundle\Entity\Person:
|
|||||||
accompanyingPeriods:
|
accompanyingPeriods:
|
||||||
- Valid:
|
- Valid:
|
||||||
traverse: true
|
traverse: true
|
||||||
|
email:
|
||||||
|
- Email:
|
||||||
|
groups: [general, creation]
|
||||||
|
message: 'The email "{{ value }}" is not a valid email.'
|
||||||
|
phonenumber:
|
||||||
|
- Regex:
|
||||||
|
pattern: '/^([\+{1}]|[0])([0-9\s*]{4,20})$/'
|
||||||
|
groups: [general, creation]
|
||||||
|
message: 'Invalid phone number: it should begin with "0" or "+", hold only digits and be smaller than 20 characters '
|
||||||
|
|
||||||
|
|
||||||
constraints:
|
constraints:
|
||||||
- Callback:
|
- Callback:
|
||||||
callback: isAccompanyingPeriodValid
|
callback: isAccompanyingPeriodValid
|
||||||
|
Loading…
x
Reference in New Issue
Block a user