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:
Julien Fastré 2024-04-10 10:37:50 +02:00
parent a3efae7831
commit 0b40d807bc
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
3 changed files with 23 additions and 5 deletions

View File

@ -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: ""

View File

@ -82,10 +82,7 @@ class Center implements HasCenterInterface, \Stringable
return $this->groupCenters; return $this->groupCenters;
} }
/** public function getId(): null|int
* @return int
*/
public function getId()
{ {
return $this->id; return $this->id;
} }

View File

@ -13,6 +13,8 @@ namespace Chill\PersonBundle\Entity\Household;
use Chill\MainBundle\Entity\Address; use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use Chill\MainBundle\Entity\HasCenterInterface;
use Chill\MainBundle\Entity\HasCentersInterface;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Validator\Constraints\Household\MaxHolder; use Chill\PersonBundle\Validator\Constraints\Household\MaxHolder;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
@ -29,7 +31,7 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
#[ORM\Entity] #[ORM\Entity]
#[ORM\Table(name: 'chill_person_household')] #[ORM\Table(name: 'chill_person_household')]
#[MaxHolder(groups: ['household_memberships'])] #[MaxHolder(groups: ['household_memberships'])]
class Household class Household implements HasCentersInterface
{ {
/** /**
* Addresses. * Addresses.
@ -155,6 +157,19 @@ class Household
return $addresses; 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 public function getCommentMembers(): CommentEmbeddable
{ {
return $this->commentMembers; return $this->commentMembers;