diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-11-05 09:08:18 +0100 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2017-06-23 09:23:49 +0200 |
commit | 56c81a2f433eaba98f8cf0bfdd3672bc517ae266 (patch) | |
tree | 804d9f8bc459ac6d67d41d75e56774c272f22216 /src/Wallabag/GroupBundle/Entity/Group.php | |
parent | 36f30fa31e0d2373f5c39851ea9138493fbde341 (diff) | |
download | wallabag-56c81a2f433eaba98f8cf0bfdd3672bc517ae266.tar.gz wallabag-56c81a2f433eaba98f8cf0bfdd3672bc517ae266.tar.zst wallabag-56c81a2f433eaba98f8cf0bfdd3672bc517ae266.zip |
First draft to manage relation between User and Group
Diffstat (limited to 'src/Wallabag/GroupBundle/Entity/Group.php')
-rw-r--r-- | src/Wallabag/GroupBundle/Entity/Group.php | 37 |
1 files changed, 37 insertions, 0 deletions
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; | |||
4 | 4 | ||
5 | use FOS\UserBundle\Model\Group as BaseGroup; | 5 | use FOS\UserBundle\Model\Group as BaseGroup; |
6 | use Doctrine\ORM\Mapping as ORM; | 6 | use Doctrine\ORM\Mapping as ORM; |
7 | use Wallabag\UserBundle\Entity\User; | ||
7 | 8 | ||
8 | /** | 9 | /** |
9 | * @ORM\Entity | 10 | * @ORM\Entity |
@@ -17,4 +18,40 @@ class Group extends BaseGroup | |||
17 | * @ORM\GeneratedValue(strategy="AUTO") | 18 | * @ORM\GeneratedValue(strategy="AUTO") |
18 | */ | 19 | */ |
19 | protected $id; | 20 | protected $id; |
21 | |||
22 | /** | ||
23 | * @ORM\ManyToMany(targetEntity="Wallabag\UserBundle\Entity\User", mappedBy="groups", cascade={"persist"}) | ||
24 | */ | ||
25 | protected $users; | ||
26 | |||
27 | public function getUsers() | ||
28 | { | ||
29 | return $this->users ?: $this->users = new ArrayCollection(); | ||
30 | } | ||
31 | |||
32 | public function addUser(User $user) | ||
33 | { | ||
34 | if (!$this->getUsers()->contains($user)) { | ||
35 | $this->getUsers()->add($user); | ||
36 | } | ||
37 | |||
38 | return $this; | ||
39 | } | ||
40 | |||
41 | /** | ||
42 | * {@inheritdoc} | ||
43 | */ | ||
44 | public function removeUser(User $user) | ||
45 | { | ||
46 | if ($this->getUsers()->contains($user)) { | ||
47 | $this->getUsers()->removeElement($user); | ||
48 | } | ||
49 | |||
50 | return $this; | ||
51 | } | ||
52 | |||
53 | public function __toString() | ||
54 | { | ||
55 | return $this->getName(); | ||
56 | } | ||
20 | } | 57 | } |