From e7f82c4835529ef7b8c5aa2b194b89df8ff321c6 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Wed, 31 Oct 2018 17:19:10 +0100 Subject: [PATCH] In between commit implementing reciever --- .../src/Entity/Attribut/MembersAttribut.php | 54 +++++++++++++++++++ .../Attribut/MembersAttributInterface.php | 7 ++- application/src/Entity/Meta/Reciever.php | 7 +-- .../src/Entity/Meta/RecieverInterface.php | 3 +- .../Source/Attribut/MembersAttribut.php | 26 --------- application/src/Entity/Source/GroupSource.php | 4 +- .../Entity/Source/GroupSourceInterface.php | 2 +- .../tests/unit/Entity/Meta/RecieverTest.php | 14 ++--- 8 files changed, 77 insertions(+), 40 deletions(-) create mode 100644 application/src/Entity/Attribut/MembersAttribut.php rename application/src/Entity/{Source => }/Attribut/MembersAttributInterface.php (70%) delete mode 100644 application/src/Entity/Source/Attribut/MembersAttribut.php diff --git a/application/src/Entity/Attribut/MembersAttribut.php b/application/src/Entity/Attribut/MembersAttribut.php new file mode 100644 index 0000000..5cf4024 --- /dev/null +++ b/application/src/Entity/Attribut/MembersAttribut.php @@ -0,0 +1,54 @@ +members; + } + + public function setMembers(Collection $members): void + { + $this->members = $members; + } + + /** + * @param int $dimension The dimensions start with 1 for the members of the actuall dimension and NULL for all members + * @param Collection $members A reference to a members list, to which new members should be add + * + * @return Collection|MembersAttributInterface[] Returns all members till the defined dimension + */ + public function getMembersInclusiveChildren(int $dimension = null, Collection &$members = null): Collection + { + // Subtract minus one, so that following members start on a other dimension: + --$dimension; + + //Define members if no members are passed + if (!$members) { + $members = new ArrayCollection(); + } + foreach ($this->members as $member) { + if (!$members->contains($member)) { + $members->add($member); + if ($dimension > 0 || null === $dimension) { + $member->getMembersInclusiveChildren($dimension, $members); + } + } + } + + return $members; + } +} diff --git a/application/src/Entity/Source/Attribut/MembersAttributInterface.php b/application/src/Entity/Attribut/MembersAttributInterface.php similarity index 70% rename from application/src/Entity/Source/Attribut/MembersAttributInterface.php rename to application/src/Entity/Attribut/MembersAttributInterface.php index 6f1f5a3..67ae2e1 100644 --- a/application/src/Entity/Source/Attribut/MembersAttributInterface.php +++ b/application/src/Entity/Attribut/MembersAttributInterface.php @@ -1,6 +1,6 @@ members->getValues() as $source) { + } } - } diff --git a/application/src/Entity/Meta/RecieverInterface.php b/application/src/Entity/Meta/RecieverInterface.php index 6cf653e..9223ebe 100644 --- a/application/src/Entity/Meta/RecieverInterface.php +++ b/application/src/Entity/Meta/RecieverInterface.php @@ -4,11 +4,12 @@ namespace App\Entity\Meta; use Doctrine\Common\Collections\ArrayCollection; use App\Entity\Attribut\RelationAttributInterface; +use App\Entity\Attribut\MembersAttributInterface; /** * @author kevinfrantz */ -interface RecieverInterface extends RelationAttributInterface, MetaInterface +interface RecieverInterface extends RelationAttributInterface, MetaInterface, MembersAttributInterface { public function getAllRecievers(): ArrayCollection; } diff --git a/application/src/Entity/Source/Attribut/MembersAttribut.php b/application/src/Entity/Source/Attribut/MembersAttribut.php deleted file mode 100644 index 0fee10c..0000000 --- a/application/src/Entity/Source/Attribut/MembersAttribut.php +++ /dev/null @@ -1,26 +0,0 @@ -members; - } - - public function setMembers(Collection $members): void - { - $this->members = $members; - } -} diff --git a/application/src/Entity/Source/GroupSource.php b/application/src/Entity/Source/GroupSource.php index 304fffe..73a6998 100644 --- a/application/src/Entity/Source/GroupSource.php +++ b/application/src/Entity/Source/GroupSource.php @@ -4,8 +4,8 @@ namespace App\Entity\Source; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\Collection; -use App\Entity\Source\Attribut\MembersAttributInterface; -use App\Entity\Source\Attribut\MembersAttribut; +use App\Entity\Attribut\MembersAttributInterface; +use App\Entity\Attribut\MembersAttribut; use Doctrine\Common\Collections\ArrayCollection; /** diff --git a/application/src/Entity/Source/GroupSourceInterface.php b/application/src/Entity/Source/GroupSourceInterface.php index 5e66a58..167d3cb 100644 --- a/application/src/Entity/Source/GroupSourceInterface.php +++ b/application/src/Entity/Source/GroupSourceInterface.php @@ -2,7 +2,7 @@ namespace App\Entity\Source; -use App\Entity\Source\Attribut\MembersAttributInterface; +use App\Entity\Attribut\MembersAttributInterface; /** * @author kevinfrantz diff --git a/application/tests/unit/Entity/Meta/RecieverTest.php b/application/tests/unit/Entity/Meta/RecieverTest.php index dec4101..673ef13 100644 --- a/application/tests/unit/Entity/Meta/RecieverTest.php +++ b/application/tests/unit/Entity/Meta/RecieverTest.php @@ -1,4 +1,5 @@ reciever = new Reciever(); } - - public function testConstructor():void { + + public function testConstructor(): void + { $this->assertEquals(Collection::class, $this->reciever->getAllRecievers()); } -} \ No newline at end of file +}