Solved bug in SourceMemberInformation

This commit is contained in:
Kevin Frantz 2018-12-30 01:14:28 +01:00
parent 25ed71221d
commit f77b5ae9a4
2 changed files with 40 additions and 7 deletions

View File

@ -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;
}

View File

@ -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();