mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +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:
@@ -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;
|
||||
|
Reference in New Issue
Block a user