diff --git a/application/src/Domain/LawManagement/LawPermissionCheckerService.php b/application/src/Domain/LawManagement/LawPermissionCheckerService.php index eddc576..6a06093 100644 --- a/application/src/Domain/LawManagement/LawPermissionCheckerService.php +++ b/application/src/Domain/LawManagement/LawPermissionCheckerService.php @@ -83,12 +83,8 @@ final class LawPermissionCheckerService implements LawPermissionCheckerServiceIn private function memberExist(RightInterface $right, SourceInterface $recieverSource): bool { $rightMemberInformation = new SourceMemberInformation($right->getReciever()); -// $rightMemberSources = $rightMemberInformation->getAllMembers(); - $rightMemberSources = new ArrayCollection(); + $rightMemberSources = $rightMemberInformation->getAllMembers(); foreach ($rightMemberSources as $memberSource) { -// var_dump($memberSource); -// echo "______________________________"; -// var_dump($recieverSource); if ($memberSource === $recieverSource) { return true; } diff --git a/application/src/Domain/SourceManagement/SourceMemberInformation.php b/application/src/Domain/SourceManagement/SourceMemberInformation.php index d920e65..ace1c69 100644 --- a/application/src/Domain/SourceManagement/SourceMemberInformation.php +++ b/application/src/Domain/SourceManagement/SourceMemberInformation.php @@ -6,6 +6,8 @@ use Doctrine\Common\Collections\Collection; use App\Entity\Source\SourceInterface; use Doctrine\Common\Collections\ArrayCollection; use App\Entity\Attribut\MemberRelationAttributInterface; +use App\Entity\Meta\Relation\Member\MemberRelationInterface; +use App\Entity\EntityInterface; final class SourceMemberInformation implements SourceMemberInformationInterface { @@ -31,12 +33,47 @@ final class SourceMemberInformation implements SourceMemberInformationInterface { foreach ($members as $member) { if (!$this->members->contains($member)) { - $this->members->add($member); - $this->itterateOverMembers($member->getMemberRelation()->getMembers()); + $this->addMemberSource($member); + $this->itterateOverMembers($this->getMemberMembers($member)); } } } + /** + * @todo Implement tests! + * + * @param EntityInterface $member + */ + private function addMemberSource(EntityInterface $member): void + { + if ($member instanceof MemberRelationInterface) { + $this->members->add($member->getSource()); + } else { + $this->members->add($member); + } + } + + /** + * @todo Implement tests + * + * @param EntityInterface $member + * + * @return Collection + */ + private function getMemberMembers(EntityInterface $member): Collection + { + if ($member instanceof MemberRelationInterface) { + return $member->getMembers(); + } + + return $member->getMemberRelation()->getMembers(); + } + + /** + * {@inheritdoc} + * + * @see \App\Domain\SourceManagement\SourceMemberInformationInterface::getAllMembers() + */ public function getAllMembers(): Collection { $this->members = new ArrayCollection();