mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-01 14:36:13 +00:00
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:
parent
a3efae7831
commit
0b40d807bc
6
.changes/unreleased/Fixed-20240410-103736.yaml
Normal file
6
.changes/unreleased/Fixed-20240410-103736.yaml
Normal 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: ""
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user