diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php index c4c11b918..0ef2bbb3c 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php +++ b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php @@ -6,6 +6,8 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\Collection; use Symfony\Component\Serializer\Annotation as Serializer; +use Symfony\Component\Validator\Constraints as Assert; +use Symfony\Component\Validator\Context\ExecutionContextInterface; use Chill\MainBundle\Entity\Address; use Chill\PersonBundle\Entity\Household\HouseholdMember; @@ -88,6 +90,7 @@ class Household * By default, the addresses are ordered by date, descending (the most * recent first) * + * @Assert\Callback(methods={"validate"}) * @return \Chill\MainBundle\Entity\Address[] */ public function getAddresses() @@ -125,4 +128,20 @@ class Household return $this; } + public function validate(ExecutionContextInterface $context, $payload) + { + $addresses = $this->getAddresses(); + $cond = True; + for ($i=0; $i < count($addresses) - 1; $i++) { + if ($addresses[$i]->getValidFrom() != $addresses[$i + 1]->getValidTo()) { + $cond = False; + $context->buildViolation('The address are not sequentials. The validFrom date of one address should be equal to the validTo date of the previous address.') + ->atPath('addresses') + ->addViolation(); + } + } + dump($cond); + + } + }