1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Stinger Soft Platform package. |
5
|
|
|
* |
6
|
|
|
* (c) Oliver Kotte <[email protected]> |
7
|
|
|
* (c) Florian Meyer <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
namespace StingerSoft\PlatformBundle\Entity; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
15
|
|
|
use FOS\UserBundle\Model\Group as BaseGroup; |
16
|
|
|
use StingerSoft\PlatformBundle\Model\Identifiable; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* |
20
|
|
|
* $LastChangedBy: $ |
21
|
|
|
* $LastChangedDate: $ |
22
|
|
|
* |
23
|
|
|
* Class Group |
24
|
|
|
* |
25
|
|
|
* @package StingerSoft\PlatformBundle\Entity |
26
|
|
|
*/ |
27
|
|
|
class Group extends BaseGroup implements Identifiable { |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* |
31
|
|
|
* @var \Doctrine\Common\Collections\Collection |
32
|
|
|
*/ |
33
|
|
|
protected $users; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Constructor |
37
|
|
|
* |
38
|
|
|
* @param |
39
|
|
|
* $name |
40
|
|
|
* @param array $roles |
41
|
|
|
*/ |
42
|
|
|
public function __construct($name, $roles = array()) { |
43
|
|
|
$this->users = new ArrayCollection(); |
44
|
|
|
parent::__construct($name, $roles); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function addRoles(array $roles) { |
48
|
|
|
foreach($roles as $role) { |
49
|
|
|
$this->addRole($role); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function removeRoles(array $roles) { |
54
|
|
|
foreach($roles as $role) { |
55
|
|
|
$this->removeRole($role); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Add user |
61
|
|
|
* |
62
|
|
|
* @param User $user |
63
|
|
|
* |
64
|
|
|
* @return Group |
65
|
|
|
*/ |
66
|
|
|
public function addUser(User $user) { |
67
|
|
|
$this->users[] = $user; |
68
|
|
|
|
69
|
|
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Remove user |
74
|
|
|
* |
75
|
|
|
* @param User $user |
76
|
|
|
*/ |
77
|
|
|
public function removeUser(User $user) { |
78
|
|
|
$this->users->removeElement($user); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Get users |
83
|
|
|
* |
84
|
|
|
* @return \Doctrine\Common\Collections\Collection |
85
|
|
|
*/ |
86
|
|
|
public function getUsers() { |
87
|
|
|
return $this->users; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getUsersCount() { |
91
|
|
|
return $this->users->count(); |
92
|
|
|
} |
93
|
|
|
} |