]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/GroupBundle/Entity/UserGroup.php
WIP
[github/wallabag/wallabag.git] / src / Wallabag / GroupBundle / Entity / UserGroup.php
diff --git a/src/Wallabag/GroupBundle/Entity/UserGroup.php b/src/Wallabag/GroupBundle/Entity/UserGroup.php
new file mode 100644 (file)
index 0000000..22d1400
--- /dev/null
@@ -0,0 +1,126 @@
+<?php
+
+namespace Wallabag\GroupBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+use FOS\UserBundle\Model\GroupInterface;
+use Symfony\Component\Validator\Constraints as Assert;
+use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
+use Wallabag\UserBundle\Entity\User;
+
+/**
+ * @ORM\Entity(repositoryClass="Wallabag\GroupBundle\Repository\UserGroupRepository")
+ * @UniqueEntity({"user_id", "group_id"})
+ * @ORM\Table(name="fos_user_group")
+ */
+class UserGroup
+{
+    /**
+     * @ORM\Column(name="id", type="integer")
+     * @ORM\Id
+     * @ORM\GeneratedValue(strategy="AUTO")
+     */
+    private $id;
+
+    /**
+     * @ORM\Column(name="role", type="integer")
+     */
+    private $role;
+
+    /**
+     * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="userGroups")
+     * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
+     */
+    private $user;
+
+    /**
+     * @ORM\ManyToOne(targetEntity="Wallabag\GroupBundle\Entity\Group", inversedBy="users")
+     * @ORM\JoinColumn(name="group_id", referencedColumnName="id")
+     */
+    private $group;
+
+    /**
+     * @ORM\Column(name="accepted", type="boolean", options={"default" : false})
+     */
+    private $accepted;
+
+    /**
+     * @ORM\OneToOne(targetEntity="Wallabag\GroupBundle\Entity\Invitation", inversedBy="userGroup", cascade={"persist", "remove"})
+     * @ORM\JoinColumn(name="invitation", referencedColumnName="code")
+     */
+    protected $invitation;
+
+    /**
+     * UserGroup constructor.
+     * @param User $user
+     * @param Group $group
+     * @param $role
+     */
+    public function __construct(User $user, Group $group, $role, $request = false)
+    {
+        $this->user = $user;
+        $this->group = $group;
+        $this->role = $role;
+        $this->accepted = $request;
+    }
+
+    /**
+     * @return Group
+     */
+    public function getGroup()
+    {
+        return $this->group;
+    }
+
+    /**
+     * @return int
+     */
+    public function getRole()
+    {
+        return $this->role;
+    }
+
+    /**
+     * @return User
+     */
+    public function getUser()
+    {
+        return $this->user;
+    }
+
+    /**
+     * @param int $role
+     * @return UserGroup
+     */
+    public function setRole($role)
+    {
+        $this->role = $role;
+        return $this;
+    }
+
+    /**
+     * @param bool $accepted
+     */
+    public function setAccepted($accepted)
+    {
+        $this->accepted = $accepted;
+    }
+
+    /**
+     * @return bool
+     */
+    public function isAccepted()
+    {
+        return $this->accepted;
+    }
+
+    public function setInvitation($invitation)
+    {
+        $this->invitation = $invitation;
+    }
+
+    public function getInvitation()
+    {
+        return $this->invitation;
+    }
+}