]>
Commit | Line | Data |
---|---|---|
2041810a TC |
1 | <?php |
2 | ||
3 | namespace Wallabag\GroupBundle\Entity; | |
4 | ||
5 | use Doctrine\ORM\Mapping as ORM; | |
6 | use FOS\UserBundle\Model\GroupInterface; | |
7 | use Symfony\Component\Validator\Constraints as Assert; | |
8 | use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; | |
9 | use Wallabag\UserBundle\Entity\User; | |
10 | ||
11 | /** | |
12 | * @ORM\Entity(repositoryClass="Wallabag\GroupBundle\Repository\UserGroupRepository") | |
13 | * @UniqueEntity({"user_id", "group_id"}) | |
14 | * @ORM\Table(name="fos_user_group") | |
15 | */ | |
16 | class UserGroup | |
17 | { | |
18 | /** | |
19 | * @ORM\Column(name="id", type="integer") | |
20 | * @ORM\Id | |
21 | * @ORM\GeneratedValue(strategy="AUTO") | |
22 | */ | |
23 | private $id; | |
24 | ||
25 | /** | |
26 | * @ORM\Column(name="role", type="integer") | |
27 | */ | |
28 | private $role; | |
29 | ||
30 | /** | |
31 | * @ORM\ManyToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="userGroups") | |
32 | * @ORM\JoinColumn(name="user_id", referencedColumnName="id") | |
33 | */ | |
34 | private $user; | |
35 | ||
36 | /** | |
37 | * @ORM\ManyToOne(targetEntity="Wallabag\GroupBundle\Entity\Group", inversedBy="users") | |
38 | * @ORM\JoinColumn(name="group_id", referencedColumnName="id") | |
39 | */ | |
40 | private $group; | |
41 | ||
42 | /** | |
43 | * @ORM\Column(name="accepted", type="boolean", options={"default" : false}) | |
44 | */ | |
45 | private $accepted; | |
46 | ||
47 | /** | |
48 | * @ORM\OneToOne(targetEntity="Wallabag\GroupBundle\Entity\Invitation", inversedBy="userGroup", cascade={"persist", "remove"}) | |
49 | * @ORM\JoinColumn(name="invitation", referencedColumnName="code") | |
50 | */ | |
51 | protected $invitation; | |
52 | ||
53 | /** | |
54 | * UserGroup constructor. | |
55 | * @param User $user | |
56 | * @param Group $group | |
57 | * @param $role | |
58 | */ | |
59 | public function __construct(User $user, Group $group, $role, $request = false) | |
60 | { | |
61 | $this->user = $user; | |
62 | $this->group = $group; | |
63 | $this->role = $role; | |
64 | $this->accepted = $request; | |
65 | } | |
66 | ||
67 | /** | |
68 | * @return Group | |
69 | */ | |
70 | public function getGroup() | |
71 | { | |
72 | return $this->group; | |
73 | } | |
74 | ||
75 | /** | |
76 | * @return int | |
77 | */ | |
78 | public function getRole() | |
79 | { | |
80 | return $this->role; | |
81 | } | |
82 | ||
83 | /** | |
84 | * @return User | |
85 | */ | |
86 | public function getUser() | |
87 | { | |
88 | return $this->user; | |
89 | } | |
90 | ||
91 | /** | |
92 | * @param int $role | |
93 | * @return UserGroup | |
94 | */ | |
95 | public function setRole($role) | |
96 | { | |
97 | $this->role = $role; | |
98 | return $this; | |
99 | } | |
100 | ||
101 | /** | |
102 | * @param bool $accepted | |
103 | */ | |
104 | public function setAccepted($accepted) | |
105 | { | |
106 | $this->accepted = $accepted; | |
107 | } | |
108 | ||
109 | /** | |
110 | * @return bool | |
111 | */ | |
112 | public function isAccepted() | |
113 | { | |
114 | return $this->accepted; | |
115 | } | |
116 | ||
117 | public function setInvitation($invitation) | |
118 | { | |
119 | $this->invitation = $invitation; | |
120 | } | |
121 | ||
122 | public function getInvitation() | |
123 | { | |
124 | return $this->invitation; | |
125 | } | |
126 | } |