From 0a181233844b4342da8679df17c790507f2aebe6 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Wed, 31 Oct 2018 21:07:57 +0100 Subject: [PATCH] Optimized reciever --- application/src/Entity/Meta/Reciever.php | 17 ++++++++++++++--- .../src/Entity/Meta/RecieverInterface.php | 4 ++-- .../tests/Unit/Entity/Meta/RecieverTest.php | 4 ++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/application/src/Entity/Meta/Reciever.php b/application/src/Entity/Meta/Reciever.php index 29b22b5..365929b 100644 --- a/application/src/Entity/Meta/Reciever.php +++ b/application/src/Entity/Meta/Reciever.php @@ -7,6 +7,7 @@ use Doctrine\ORM\Mapping as ORM; use App\Entity\Attribut\RelationAttribut; use App\Entity\Attribut\RelationAttributInterface; use App\Entity\Attribut\MembersAttribut; +use App\Entity\Source\SourceInterface; /** * @author kevinfrantz @@ -27,9 +28,19 @@ class Reciever extends AbstractMeta implements RecieverInterface */ protected $relation; - public function getAllRecievers(): ArrayCollection + /** + * @ORM\ManyToMany(targetEntity="App\Entity\AbstractSource") + * @ORM\JoinTable(name="meta_reciever_members", + * joinColumns={@ORM\JoinColumn(name="reciever_id", referencedColumnName="id")}, + * inverseJoinColumns={@ORM\JoinColumn(name="source_id", referencedColumnName="id")} + * ) + * + * @var ArrayCollection | SourceInterface[] + */ + protected $members; + + public function __construct() { - foreach ($this->members->getValues() as $source) { - } + $this->members = new ArrayCollection(); } } diff --git a/application/src/Entity/Meta/RecieverInterface.php b/application/src/Entity/Meta/RecieverInterface.php index 9223ebe..7f81f28 100644 --- a/application/src/Entity/Meta/RecieverInterface.php +++ b/application/src/Entity/Meta/RecieverInterface.php @@ -2,14 +2,14 @@ namespace App\Entity\Meta; -use Doctrine\Common\Collections\ArrayCollection; use App\Entity\Attribut\RelationAttributInterface; use App\Entity\Attribut\MembersAttributInterface; /** + * It's neccessary to have an own reciever class, because if you would use a GroupSource it would lead to an infinite loop. + * * @author kevinfrantz */ interface RecieverInterface extends RelationAttributInterface, MetaInterface, MembersAttributInterface { - public function getAllRecievers(): ArrayCollection; } diff --git a/application/tests/Unit/Entity/Meta/RecieverTest.php b/application/tests/Unit/Entity/Meta/RecieverTest.php index 6d94658..1efa455 100644 --- a/application/tests/Unit/Entity/Meta/RecieverTest.php +++ b/application/tests/Unit/Entity/Meta/RecieverTest.php @@ -3,9 +3,9 @@ namespace App\Tests\Unit\Entity\Meta; use PHPUnit\Framework\TestCase; -use Doctrine\Common\Collections\Collection; use App\Entity\Meta\Reciever; use App\Entity\Meta\RecieverInterface; +use Doctrine\Common\Collections\Collection; class RecieverTest extends TestCase { @@ -21,6 +21,6 @@ class RecieverTest extends TestCase public function testConstructor(): void { - $this->assertEquals(Collection::class, $this->reciever->getAllRecievers()); + $this->assertInstanceOf(Collection::class, $this->reciever->getMembers()); } }