]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/UserBundle/Entity/User.php
First draft to manage relation between User and Group
[github/wallabag/wallabag.git] / src / Wallabag / UserBundle / Entity / User.php
index 5c75846f85993f8bf677fa0110bee9516400f9bf..dc10f1c44e8fa17939c3c7c798c5f5a61eada32e 100644 (file)
@@ -98,8 +98,16 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
     private $authCode;
 
     /**
-     * @var bool
-     *
+     * @ORM\ManyToMany(targetEntity="Wallabag\GroupBundle\Entity\Group", inversedBy="users")
+     * @ORM\JoinTable(name="user_group",
+     *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
+     *      inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
+     * )
+     */
+    protected $groups;
+
+    /**
+     * @var bool Enabled yes/no
      * @ORM\Column(type="boolean")
      */
     private $twoFactorAuthentication = false;
@@ -110,6 +118,8 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
     private $trusted;
 
     /**
+     * @var ArrayCollection
+     *
      * @ORM\OneToMany(targetEntity="Wallabag\ApiBundle\Entity\Client", mappedBy="user", cascade={"remove"})
      */
     protected $clients;
@@ -306,10 +316,18 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
      */
     public function getFirstClient()
     {
-        if (empty($this->clients)) {
-            return $this->clients;
+        if (!empty($this->clients)) {
+            return $this->clients->first();
         }
 
-        return $this->clients->first();
+    }
+
+    /**
+     * @param string $name
+     * @return bool
+     */
+    public function hasGroup($name = '')
+    {
+        return in_array($name, $this->getGroupNames());
     }
 }