add a many-to-many relation to addresses

This commit is contained in:
2016-03-10 17:59:01 +01:00
parent afd52294b1
commit afe6ace331
7 changed files with 197 additions and 2 deletions

View File

@@ -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
*