mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 02:23:51 +00:00
add a many-to-many relation to addresses
This commit is contained in:
@@ -27,6 +27,8 @@ 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;
|
||||
|
||||
/**
|
||||
* Person
|
||||
@@ -100,9 +102,16 @@ class Person implements HasCenterInterface {
|
||||
/** @var array Array where customfield's data are stored */
|
||||
private $cFData;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var \Doctrine\Common\Collections\Collection
|
||||
*/
|
||||
private $addresses;
|
||||
|
||||
public function __construct(\DateTime $opening = null) {
|
||||
$this->accompanyingPeriods = new ArrayCollection();
|
||||
$this->spokenLanguages = new ArrayCollection();
|
||||
$this->addresses = new ArrayCollection();
|
||||
|
||||
if ($opening === null) {
|
||||
$opening = new \DateTime();
|
||||
@@ -597,6 +606,50 @@ class Person implements HasCenterInterface {
|
||||
return $this->spokenLanguages;
|
||||
}
|
||||
|
||||
public function addAddress(Address $address)
|
||||
{
|
||||
$this->addresses[] = $address;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeAddress(Address $address)
|
||||
{
|
||||
$this->addresses->removeElement($address);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \Chill\MainBundle\Entity\Address[]@return Address[]
|
||||
*/
|
||||
public function getAddresses()
|
||||
{
|
||||
return $this->addresses;
|
||||
}
|
||||
|
||||
public function getLastAddress(\DateTime $date = null)
|
||||
{
|
||||
if ($date === null) {
|
||||
$date = new \DateTime('now');
|
||||
}
|
||||
|
||||
$lastAddress = null;
|
||||
|
||||
foreach ($this->getAddresses() as $address) {
|
||||
if ($address->getValidFrom() < $date) {
|
||||
if ($lastAddress === NULL) {
|
||||
$lastAddress = $address;
|
||||
} else {
|
||||
if ($lastAddress->getValidFrom() < $address->getValidFrom()) {
|
||||
$lastAddress = $address;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $lastAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation callback that checks if the accompanying periods are valid
|
||||
*
|
||||
|
Reference in New Issue
Block a user