From 56c81a2f433eaba98f8cf0bfdd3672bc517ae266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 5 Nov 2016 09:08:18 +0100 Subject: First draft to manage relation between User and Group --- src/Wallabag/GroupBundle/Entity/Group.php | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/Wallabag/GroupBundle/Entity/Group.php') diff --git a/src/Wallabag/GroupBundle/Entity/Group.php b/src/Wallabag/GroupBundle/Entity/Group.php index 57dc16d1..e889f74e 100644 --- a/src/Wallabag/GroupBundle/Entity/Group.php +++ b/src/Wallabag/GroupBundle/Entity/Group.php @@ -4,6 +4,7 @@ namespace Wallabag\GroupBundle\Entity; use FOS\UserBundle\Model\Group as BaseGroup; use Doctrine\ORM\Mapping as ORM; +use Wallabag\UserBundle\Entity\User; /** * @ORM\Entity @@ -17,4 +18,40 @@ class Group extends BaseGroup * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; + + /** + * @ORM\ManyToMany(targetEntity="Wallabag\UserBundle\Entity\User", mappedBy="groups", cascade={"persist"}) + */ + protected $users; + + public function getUsers() + { + return $this->users ?: $this->users = new ArrayCollection(); + } + + public function addUser(User $user) + { + if (!$this->getUsers()->contains($user)) { + $this->getUsers()->add($user); + } + + return $this; + } + + /** + * {@inheritdoc} + */ + public function removeUser(User $user) + { + if ($this->getUsers()->contains($user)) { + $this->getUsers()->removeElement($user); + } + + return $this; + } + + public function __toString() + { + return $this->getName(); + } } -- cgit v1.2.3