Implement HasCentersInterface in Household class (will fix access control)

The Household class now implements the HasCentersInterface and includes a method to get all centers associated with current persons in the household. This enhancement will allow fetching of all household-associated centers easier.
This commit is contained in:
2024-04-10 10:37:50 +02:00
parent a3efae7831
commit 0b40d807bc
3 changed files with 23 additions and 5 deletions

View File

@@ -13,6 +13,8 @@ namespace Chill\PersonBundle\Entity\Household;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use Chill\MainBundle\Entity\HasCenterInterface;
use Chill\MainBundle\Entity\HasCentersInterface;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Validator\Constraints\Household\MaxHolder;
use Doctrine\Common\Collections\ArrayCollection;
@@ -29,7 +31,7 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
#[ORM\Entity]
#[ORM\Table(name: 'chill_person_household')]
#[MaxHolder(groups: ['household_memberships'])]
class Household
class Household implements HasCentersInterface
{
/**
* Addresses.
@@ -155,6 +157,19 @@ class Household
return $addresses;
}
public function getCenters(): ?iterable
{
$centers = [];
foreach ($this->getCurrentPersons() as $person) {
if (null !== $center = $person->getCenter()) {
$centers[$center->getId() ?? spl_object_hash($center)] = $center;
}
}
return array_values($centers);
}
public function getCommentMembers(): CommentEmbeddable
{
return $this->commentMembers;