]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/GroupBundle/Entity/Group.php
First draft to manage relation between User and Group
[github/wallabag/wallabag.git] / src / Wallabag / GroupBundle / Entity / Group.php
index 57dc16d104c9720863f4ddda19db625dee8f58bb..e889f74e0170b9b02f8b241ee37224208beae1cf 100644 (file)
@@ -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();
+    }
 }