mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 13:57:10 +02:00
Optimized draft for MemberRelation
This commit is contained in:
50
application/src/Domain/MemberManagement/MemberManager.php
Normal file
50
application/src/Domain/MemberManagement/MemberManager.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\MemberManagement;
|
||||
|
||||
use App\Entity\Meta\Relation\Member\MemberRelationInterface;
|
||||
|
||||
final class MemberManager implements MemberManagerInterface
|
||||
{
|
||||
/**
|
||||
* @var MemberRelationInterface
|
||||
*/
|
||||
private $memberRelation;
|
||||
|
||||
public function __construct(MemberRelationInterface $memberRelation)
|
||||
{
|
||||
$this->memberRelation = $memberRelation;
|
||||
}
|
||||
|
||||
public function addMember(MemberRelationInterface $member): void
|
||||
{
|
||||
if (!$this->memberRelation->getMembers()->contains($member)) {
|
||||
$this->memberRelation->getMembers()[] = $member;
|
||||
(new self($member))->addMembership($this->memberRelation);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeMember(MemberRelationInterface $member): void
|
||||
{
|
||||
if ($this->memberRelation->getMembers()->contains($member)) {
|
||||
$this->memberRelation->getMembers()->removeElement($member);
|
||||
(new self($member))->removeMembership($this->memberRelation);
|
||||
}
|
||||
}
|
||||
|
||||
public function addMembership(MemberRelationInterface $membership): void
|
||||
{
|
||||
if (!$this->memberRelation->getMemberships()->contains($membership)) {
|
||||
$this->memberRelation->getMemberships()[] = $membership;
|
||||
(new self($membership))->addMember($this->memberRelation);
|
||||
}
|
||||
}
|
||||
|
||||
public function removeMembership(MemberRelationInterface $membership): void
|
||||
{
|
||||
if ($this->memberRelation->getMemberships()->contains($membership)) {
|
||||
$this->memberRelation->getMemberships()->removeElement($membership);
|
||||
(new self($membership))->removeMember($this->memberRelation);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\MemberManagement;
|
||||
|
||||
use App\Entity\Meta\Relation\Member\MemberRelationInterface;
|
||||
|
||||
interface MemberManagerInterface
|
||||
{
|
||||
/**
|
||||
* @param MemberRelationInterface $member
|
||||
*/
|
||||
public function addMember(MemberRelationInterface $member): void;
|
||||
|
||||
/**
|
||||
* @param MemberRelationInterface $member
|
||||
*/
|
||||
public function removeMember(MemberRelationInterface $member): void;
|
||||
|
||||
/**
|
||||
* @param MemberRelationInterface $membership
|
||||
*/
|
||||
public function addMembership(MemberRelationInterface $membership): void;
|
||||
|
||||
/**
|
||||
* @param MemberRelationInterface $membership
|
||||
*/
|
||||
public function removeMembership(MemberRelationInterface $membership): void;
|
||||
}
|
23
application/src/Entity/Attribut/MemberRelationAttribut.php
Normal file
23
application/src/Entity/Attribut/MemberRelationAttribut.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Attribut;
|
||||
|
||||
use App\Entity\Meta\Relation\Member\MemberRelationInterface;
|
||||
|
||||
trait MemberRelationAttribut
|
||||
{
|
||||
/**
|
||||
* @var MemberRelationInterface
|
||||
*/
|
||||
protected $memberRelation;
|
||||
|
||||
public function setMembersRelation(MemberRelationInterface $memberRelation): void
|
||||
{
|
||||
$this->memberRelation = $memberRelation;
|
||||
}
|
||||
|
||||
public function getMemberRelation(): MemberRelationInterface
|
||||
{
|
||||
return $this->memberRelation;
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Entity\Attribut;
|
||||
|
||||
use App\Entity\Meta\Relation\Member\MemberRelationInterface;
|
||||
|
||||
interface MemberRelationAttributInterface
|
||||
{
|
||||
public function setMembersRelation(MemberRelationInterface $memberRelation): void;
|
||||
|
||||
public function getMemberRelation(): MemberRelationInterface;
|
||||
}
|
@@ -3,7 +3,7 @@
|
||||
namespace App\Entity\Attribut;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use App\Entity\Meta\Relation\Member\MemberRelationInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@@ -11,12 +11,12 @@ use App\Entity\Source\SourceInterface;
|
||||
trait MembersAttribut
|
||||
{
|
||||
/**
|
||||
* @var Collection|SourceInterface[]
|
||||
* @var Collection|MemberRelationInterface[]
|
||||
*/
|
||||
protected $members;
|
||||
|
||||
/**
|
||||
* @return Collection|SourceInterface[]
|
||||
* @return Collection|MemberRelationInterface[]
|
||||
*/
|
||||
public function getMembers(): Collection
|
||||
{
|
||||
@@ -24,7 +24,7 @@ trait MembersAttribut
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection|SourceInterface[] $members
|
||||
* @param Collection|MemberRelationInterface[] $members
|
||||
*/
|
||||
public function setMembers(Collection $members): void
|
||||
{
|
||||
|
@@ -3,7 +3,7 @@
|
||||
namespace App\Entity\Attribut;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use App\Entity\Meta\Relation\Member\MemberRelationInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@@ -11,12 +11,12 @@ use App\Entity\Source\SourceInterface;
|
||||
interface MembersAttributInterface
|
||||
{
|
||||
/**
|
||||
* @param Collection|SourceInterface[] $members
|
||||
* @param Collection|MemberRelationInterface[] $members
|
||||
*/
|
||||
public function setMembers(Collection $members): void;
|
||||
|
||||
/**
|
||||
* @return Collection|SourceInterface[]
|
||||
* @return Collection|MemberRelationInterface[]
|
||||
*/
|
||||
public function getMembers(): Collection;
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@
|
||||
namespace App\Entity\Attribut;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use App\Entity\Meta\Relation\Member\MemberRelationInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@@ -11,12 +11,12 @@ use App\Entity\Source\SourceInterface;
|
||||
trait MembershipsAttribut
|
||||
{
|
||||
/**
|
||||
* @var Collection|SourceInterface[]
|
||||
* @var Collection|MemberRelationInterface[]
|
||||
*/
|
||||
protected $memberships;
|
||||
|
||||
/**
|
||||
* @return Collection|SourceInterface[]
|
||||
* @return Collection|MemberRelationInterface[]
|
||||
*/
|
||||
public function getMemberships(): Collection
|
||||
{
|
||||
@@ -24,7 +24,7 @@ trait MembershipsAttribut
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection|SourceInterface[] $memberships
|
||||
* @param Collection|MemberRelationInterface[] $memberships
|
||||
*/
|
||||
public function setMemberships(Collection $memberships): void
|
||||
{
|
||||
|
@@ -3,7 +3,7 @@
|
||||
namespace App\Entity\Attribut;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use App\Entity\Meta\Relation\Member\MemberRelationInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@@ -11,12 +11,12 @@ use App\Entity\Source\SourceInterface;
|
||||
interface MembershipsAttributInterface
|
||||
{
|
||||
/**
|
||||
* @param Collection|SourceInterface[] $groups
|
||||
* @param Collection|MemberRelationInterface[] $groups
|
||||
*/
|
||||
public function setMemberships(Collection $memberships): void;
|
||||
|
||||
/**
|
||||
* @return Collection|SourceInterface[]
|
||||
* @return Collection|MemberRelationInterface[]
|
||||
*/
|
||||
public function getMemberships(): Collection;
|
||||
}
|
||||
|
@@ -3,12 +3,22 @@
|
||||
namespace App\Entity\Meta\Relation;
|
||||
|
||||
use App\Entity\Meta\AbstractMeta;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
abstract class AbstractRelation extends AbstractMeta implements RelationInterface
|
||||
{
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="App\Entity\Source\AbstractSource",cascade={"persist", "remove"})
|
||||
* @ORM\JoinColumn(name="source_id", referencedColumnName="id",onDelete="CASCADE")
|
||||
*
|
||||
* @var SourceInterface
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
@@ -5,8 +5,40 @@ namespace App\Entity\Meta\Relation\Member;
|
||||
use App\Entity\Meta\Relation\AbstractRelation;
|
||||
use App\Entity\Attribut\MembersAttribut;
|
||||
use App\Entity\Attribut\MembershipsAttribut;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
* @ORM\Entity()
|
||||
*/
|
||||
class MemberRelation extends AbstractRelation implements MemberRelationInterface
|
||||
{
|
||||
use MembersAttribut,MembershipsAttribut;
|
||||
|
||||
/**
|
||||
* Many Sources have many Source Members.
|
||||
*
|
||||
* @var Collection|MemberRelationInterface[]
|
||||
* @ORM\ManyToMany(targetEntity="MemberRelation", inversedBy="memberships",cascade={"persist", "remove"})
|
||||
* @ORM\JoinTable(name="source_members",
|
||||
* joinColumns={@ORM\JoinColumn(name="source_id", referencedColumnName="id",onDelete="CASCADE")},
|
||||
* inverseJoinColumns={@ORM\JoinColumn(name="member_id", referencedColumnName="id",onDelete="CASCADE")}
|
||||
* )
|
||||
*/
|
||||
protected $members;
|
||||
|
||||
/**
|
||||
* @var Collection|MemberRelationInterface[]
|
||||
* @ORM\ManyToMany(targetEntity="MemberRelation",mappedBy="members")
|
||||
*/
|
||||
protected $memberships;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->members = new ArrayCollection();
|
||||
$this->memberships = new ArrayCollection();
|
||||
}
|
||||
}
|
||||
|
@@ -4,7 +4,6 @@ namespace App\Entity\Meta\Relation\Parent;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Source\SourceInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@@ -12,14 +11,6 @@ use App\Entity\Source\SourceInterface;
|
||||
*/
|
||||
class CreatorRelation extends AbstractParentRelation implements CreatorRelationInterface
|
||||
{
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="App\Entity\Source\AbstractSource",cascade={"persist", "remove"})
|
||||
* @ORM\JoinColumn(name="source_id", referencedColumnName="id",onDelete="CASCADE")
|
||||
*
|
||||
* @var SourceInterface
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity="CreatorRelation",mappedBy="childs")
|
||||
*
|
||||
|
@@ -5,19 +5,18 @@ namespace App\Entity\Source;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use JMS\Serializer\Annotation\Exclude;
|
||||
use App\Entity\AbstractEntity;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Entity\Attribut\LawAttribut;
|
||||
use App\Entity\Meta\LawInterface;
|
||||
use App\Entity\Meta\Law;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use App\Entity\Attribut\MembershipsAttribut;
|
||||
use App\Entity\Attribut\SlugAttribut;
|
||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use App\Entity\Attribut\MembersAttribut;
|
||||
use App\Entity\Attribut\CreatorRelationAttribut;
|
||||
use App\Entity\Meta\Relation\CreatorRelationInterface;
|
||||
use App\Entity\Meta\Relation\Parent\CreatorRelationInterface;
|
||||
use App\Entity\Meta\Relation\Parent\CreatorRelation;
|
||||
use App\Entity\Attribut\MemberRelationAttribut;
|
||||
use App\Entity\Meta\Relation\Member\MemberRelation;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
@@ -47,7 +46,7 @@ use App\Entity\Meta\Relation\Parent\CreatorRelation;
|
||||
*/
|
||||
abstract class AbstractSource extends AbstractEntity implements SourceInterface
|
||||
{
|
||||
use MembershipsAttribut, LawAttribut,SlugAttribut,MembersAttribut,CreatorRelationAttribut;
|
||||
use LawAttribut,SlugAttribut,CreatorRelationAttribut, MemberRelationAttribut;
|
||||
|
||||
/**
|
||||
* System slugs should be writen in UPPER CASES
|
||||
@@ -69,22 +68,12 @@ abstract class AbstractSource extends AbstractEntity implements SourceInterface
|
||||
protected $creatorRelation;
|
||||
|
||||
/**
|
||||
* Many Sources have many Source Members.
|
||||
*
|
||||
* @var Collection|SourceInterface[]
|
||||
* @ORM\ManyToMany(targetEntity="AbstractSource", inversedBy="memberships",cascade={"persist", "remove"})
|
||||
* @ORM\JoinTable(name="source_members",
|
||||
* joinColumns={@ORM\JoinColumn(name="source_id", referencedColumnName="id",onDelete="CASCADE")},
|
||||
* inverseJoinColumns={@ORM\JoinColumn(name="member_id", referencedColumnName="id",onDelete="CASCADE")}
|
||||
* )
|
||||
* @var CreatorRelationInterface
|
||||
* @ORM\OneToOne(targetEntity="App\Entity\Meta\Relation\Member\MemberRelation",cascade={"persist", "remove"})
|
||||
* @ORM\JoinColumn(name="member_relation_id", referencedColumnName="id", onDelete="CASCADE")
|
||||
* @Exclude
|
||||
*/
|
||||
protected $members;
|
||||
|
||||
/**
|
||||
* @var Collection|SourceInterface[]
|
||||
* @ORM\ManyToMany(targetEntity="AbstractSource",mappedBy="members")
|
||||
*/
|
||||
protected $memberships;
|
||||
protected $memberRelation;
|
||||
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="App\Entity\Meta\Law",cascade={"persist", "remove"})
|
||||
@@ -99,6 +88,8 @@ abstract class AbstractSource extends AbstractEntity implements SourceInterface
|
||||
parent::__construct();
|
||||
$this->creatorRelation = new CreatorRelation();
|
||||
$this->creatorRelation->setSource($this);
|
||||
$this->memberRelation = new MemberRelation();
|
||||
$this->memberRelation->setSource($this);
|
||||
$this->law = new Law();
|
||||
$this->law->setSource($this);
|
||||
/*
|
||||
|
@@ -5,14 +5,13 @@ namespace App\Entity\Source;
|
||||
use App\Entity\Attribut\IdAttributInterface;
|
||||
use App\Entity\EntityInterface;
|
||||
use App\Entity\Attribut\LawAttributInterface;
|
||||
use App\Entity\Attribut\MembershipsAttributInterface;
|
||||
use App\Entity\Attribut\SlugAttributInterface;
|
||||
use App\Entity\Attribut\MembersAttributInterface;
|
||||
use App\Entity\Attribut\CreatorRelationAttributInterface;
|
||||
use App\Entity\Attribut\MemberRelationAttributInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface SourceInterface extends IdAttributInterface, EntityInterface, MembershipsAttributInterface, LawAttributInterface, SlugAttributInterface, MembersAttributInterface, CreatorRelationAttributInterface
|
||||
interface SourceInterface extends IdAttributInterface, EntityInterface, LawAttributInterface, SlugAttributInterface, CreatorRelationAttributInterface, MemberRelationAttributInterface
|
||||
{
|
||||
}
|
||||
|
Reference in New Issue
Block a user