Implemented add and remove for member

This commit is contained in:
Kevin Frantz
2018-11-24 21:21:59 +01:00
parent c927322153
commit e97610893d
3 changed files with 84 additions and 2 deletions

View File

@@ -22,6 +22,10 @@ use App\Entity\Attribut\MembersAttribut;
/**
* @author kevinfrantz
*
* For the members\memberships attribut checkout:
*
* @see http://www.inanzzz.com/index.php/post/h0jt/bidirectional-many-to-many-cascade-remove-and-orphan-removal-operations-in-doctrine
*
* @ORM\Entity
* @ORM\Table(name="source")
* @ORM\InheritanceType("JOINED")
@@ -99,4 +103,36 @@ abstract class AbstractSource extends AbstractEntity implements SourceInterface
$this->memberships = new ArrayCollection();
$this->members = new ArrayCollection();
}
public function addMember(SourceInterface $member): void
{
if (!$this->members->contains($member)) {
$this->members[] = $member;
$member->addMembership($this);
}
}
public function removeMember(SourceInterface $member): void
{
if ($this->members->contains($member)) {
$this->members->removeElement($member);
$member->removeMembership($this);
}
}
public function addMembership(SourceInterface $membership): void
{
if (!$this->memberships->contains($membership)) {
$this->memberships[] = $membership;
$membership->addMember($this);
}
}
public function removeMembership(SourceInterface $membership): void
{
if ($this->memberships->contains($membership)) {
$this->memberships->removeElement($membership);
$membership->removeMember($this);
}
}
}

View File

@@ -15,4 +15,23 @@ use App\Entity\Attribut\MembersAttributInterface;
*/
interface SourceInterface extends IdAttributInterface, EntityInterface, MembershipsAttributInterface, LawAttributInterface, RelationAttributInterface, SlugAttributInterface, MembersAttributInterface
{
/**
* @param SourceInterface $member
*/
public function addMember(SourceInterface $member): void;
/**
* @param SourceInterface $member
*/
public function removeMember(SourceInterface $member): void;
/**
* @param SourceInterface $membership
*/
public function addMembership(SourceInterface $membership): void;
/**
* @param SourceInterface $membership
*/
public function removeMembership(SourceInterface $membership): void;
}