diff --git a/.changes/unreleased/Fixed-20240410-103736.yaml b/.changes/unreleased/Fixed-20240410-103736.yaml new file mode 100644 index 000000000..355d24b1e --- /dev/null +++ b/.changes/unreleased/Fixed-20240410-103736.yaml @@ -0,0 +1,6 @@ +kind: Fixed +body: Fix resolving of centers for an household, which will fix in turn the access + control +time: 2024-04-10T10:37:36.462484988+02:00 +custom: + Issue: "" diff --git a/src/Bundle/ChillMainBundle/Entity/Center.php b/src/Bundle/ChillMainBundle/Entity/Center.php index fd8e0dd75..182fe3219 100644 --- a/src/Bundle/ChillMainBundle/Entity/Center.php +++ b/src/Bundle/ChillMainBundle/Entity/Center.php @@ -82,10 +82,7 @@ class Center implements HasCenterInterface, \Stringable return $this->groupCenters; } - /** - * @return int - */ - public function getId() + public function getId(): null|int { return $this->id; } diff --git a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php index 48494e034..fd3d5571b 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Household/Household.php +++ b/src/Bundle/ChillPersonBundle/Entity/Household/Household.php @@ -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;