]>
Commit | Line | Data |
---|---|---|
f1900b68 NL |
1 | <?php |
2 | ||
b073a0b4 | 3 | namespace Wallabag\GroupBundle\Entity; |
f1900b68 | 4 | |
6a50b4cc | 5 | use Doctrine\Common\Collections\ArrayCollection; |
f1900b68 NL |
6 | use FOS\UserBundle\Model\Group as BaseGroup; |
7 | use Doctrine\ORM\Mapping as ORM; | |
56c81a2f | 8 | use Wallabag\UserBundle\Entity\User; |
f1900b68 NL |
9 | |
10 | /** | |
11 | * @ORM\Entity | |
12 | * @ORM\Table(name="`group`") | |
13 | */ | |
14 | class Group extends BaseGroup | |
15 | { | |
16 | /** | |
17 | * @ORM\Id | |
18 | * @ORM\Column(type="integer") | |
19 | * @ORM\GeneratedValue(strategy="AUTO") | |
20 | */ | |
21 | protected $id; | |
56c81a2f NL |
22 | |
23 | /** | |
24 | * @ORM\ManyToMany(targetEntity="Wallabag\UserBundle\Entity\User", mappedBy="groups", cascade={"persist"}) | |
25 | */ | |
26 | protected $users; | |
27 | ||
28 | public function getUsers() | |
29 | { | |
30 | return $this->users ?: $this->users = new ArrayCollection(); | |
31 | } | |
32 | ||
33 | public function addUser(User $user) | |
34 | { | |
35 | if (!$this->getUsers()->contains($user)) { | |
36 | $this->getUsers()->add($user); | |
37 | } | |
38 | ||
39 | return $this; | |
40 | } | |
41 | ||
42 | /** | |
43 | * {@inheritdoc} | |
44 | */ | |
45 | public function removeUser(User $user) | |
46 | { | |
47 | if ($this->getUsers()->contains($user)) { | |
48 | $this->getUsers()->removeElement($user); | |
49 | } | |
50 | ||
51 | return $this; | |
52 | } | |
53 | ||
54 | public function __toString() | |
55 | { | |
56 | return $this->getName(); | |
57 | } | |
f1900b68 | 58 | } |