fix conflict when merging _77_address_household into master

This commit is contained in:
nobohan
2021-06-17 16:59:55 +02:00
39 changed files with 1850 additions and 215 deletions

View File

@@ -7,6 +7,8 @@ use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
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;
@@ -25,7 +27,7 @@ class Household
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Serializer\Groups({"read"})
* @Serializer\Groups({"write"})
*/
private ?int $id = null;
@@ -37,6 +39,7 @@ class Household
* cascade={"persist", "remove", "merge", "detach"})
* @ORM\JoinTable(name="chill_person_household_to_addresses")
* @ORM\OrderBy({"validFrom" = "DESC"})
* @Serializer\Groups({"write"})
*/
private Collection $addresses;
@@ -45,7 +48,7 @@ class Household
* targetEntity=HouseholdMember::class,
* mappedBy="household"
* )
* @Serializer\Groups({"read"})
* @Serializer\Groups({"write"})
*/
private Collection $members;
@@ -68,6 +71,11 @@ class Household
{
$this->addresses[] = $address;
foreach ($this->getAddresses() as $a) {
if ($a->getValidFrom() < $address->getValidFrom() && $a->getValidTo() === NULL) {
$a->setValidTo($address->getValidFrom());
}
}
return $this;
}
@@ -83,6 +91,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()
@@ -192,4 +201,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);
}
}