diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php index ac22b6e8b..bbec0612a 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php +++ b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php @@ -2,10 +2,12 @@ namespace Chill\PersonBundle\Entity\Household; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\Collection; -use Chill\MainBundle\Entity\Address; use Symfony\Component\Serializer\Annotation as Serializer; +use Chill\MainBundle\Entity\Address; +use Chill\PersonBundle\Entity\Household\HouseholdMember; /** * @ORM\Entity @@ -24,16 +26,10 @@ class Household * @ORM\Column(type="integer") * @Serializer\Groups({"read"}) */ - private $id; - - public function getId(): ?int - { - return $this->id; - } + private ?int $id; /** * Addresses - * @var Collection * * @ORM\ManyToMany( * targetEntity="Chill\MainBundle\Entity\Address", @@ -41,8 +37,26 @@ class Household * @ORM\JoinTable(name="chill_person_household_to_addresses") * @ORM\OrderBy({"validFrom" = "DESC"}) */ - private $addresses; + private Collection $addresses; + /** + * @ORM\OneToMany( + * targetEntity=HouseholdMember::class, + * mappedBy="household" + * ) + */ + private Collection $members; + + public function __construct() + { + $this->addresses = new ArrayCollection(); + $this->members = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } /** * @param Address $address @@ -74,4 +88,34 @@ class Household return $this->addresses; } + /** + * @return Collection|HouseholdMember[] + */ + public function getMembers(): Collection + { + return $this->members; + } + + public function addMember(HouseholdMember $member): self + { + if (!$this->members->contains($member)) { + $this->members[] = $member; + $member->setHousehold($this); + } + + return $this; + } + + public function removeMember(HouseholdMember $member): self + { + if ($this->members->removeElement($member)) { + // set the owning side to null (unless already changed) + if ($member->getHousehold() === $this) { + $member->setHousehold(null); + } + } + + return $this; + } + } diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Household/addresses.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Household/addresses.html.twig index 9a15b6ecd..aa0aa443b 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Household/addresses.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Household/addresses.html.twig @@ -7,7 +7,8 @@
Household with id {{ household.id }}
- + {{ 'Move household'|trans }}