]> git.immae.eu Git - github/wallabag/wallabag.git/blame - 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
CommitLineData
f1900b68
NL
1<?php
2
b073a0b4 3namespace Wallabag\GroupBundle\Entity;
f1900b68
NL
4
5use FOS\UserBundle\Model\Group as BaseGroup;
6use Doctrine\ORM\Mapping as ORM;
56c81a2f 7use Wallabag\UserBundle\Entity\User;
f1900b68
NL
8
9/**
10 * @ORM\Entity
11 * @ORM\Table(name="`group`")
12 */
13class Group extends BaseGroup
14{
15 /**
16 * @ORM\Id
17 * @ORM\Column(type="integer")
18 * @ORM\GeneratedValue(strategy="AUTO")
19 */
20 protected $id;
56c81a2f
NL
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 }
f1900b68 57}