addresses = new ArrayCollection(); $this->members = new ArrayCollection(); } public function getId(): ?int { return $this->id; } /** * @param Address $address * @return $this */ public function addAddress(Address $address) { $this->addresses[] = $address; return $this; } /** * @param Address $address */ public function removeAddress(Address $address) { $this->addresses->removeElement($address); } /** * By default, the addresses are ordered by date, descending (the most * recent first) * * @return \Chill\MainBundle\Entity\Address[] */ public function getAddresses() { return $this->addresses; } /** * @return Collection|HouseholdMember[] */ public function getMembers(): Collection { return $this->members; } public function getCurrentMembers(?\DateTimeImmutable $now = null): Collection { $criteria = new Criteria(); $expr = Criteria::expr(); $date = $now === null ? (new \DateTimeImmutable('today')) : $now; $criteria ->where($expr->orX( $expr->isNull('startDate'), $expr->lte('startDate', $date) )) ->andWhere($expr->orX( $expr->isNull('endDate'), $expr->gte('endDate', $date) )); return $this->getMembers()->matching($criteria); } /** * Get the persons currently associated to the household. * * Return a list of Person, instead of a list of HouseholdMembers * * @return Person[] */ public function getCurrentPersons(?\DateTimeImmutable $now = null): Collection { return $this->getCurrentMembers($now) ->map(function(HouseholdMember $m) { return $m->getPerson(); }); } public function getNonCurrentMembers(\DateTimeImmutable $now = null): Collection { $criteria = new Criteria(); $expr = Criteria::expr(); $date = $now === null ? (new \DateTimeImmutable('today')) : $now; $criteria ->where( $expr->gt('startDate', $date) ) ->orWhere( $expr->andX( $expr->lt('endDate', $date), $expr->neq('endDate', null) ) ); return $this->getMembers()->matching($criteria); } public function getCurrentMembersByPosition(Position $position, \DateTimeInterface $now = null) { $criteria = new Criteria(); $expr = Criteria::expr(); $criteria->where($expr->eq('position', $position)); return $this->getCurrentMembers($now)->matching($criteria); } public function getNonCurrentMembersByPosition(Position $position, \DateTimeInterface $now = null) { $criteria = new Criteria(); $expr = Criteria::expr(); $criteria->where($expr->eq('position', $position)); return $this->getNonCurrentMembers($now)->matching($criteria); } 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; } }