|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Entity Group. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP Version 7 |
|
6
|
|
|
* |
|
7
|
|
|
* @author Quétier Laurent <[email protected]> |
|
8
|
|
|
* @copyright 2014 Dev-Int GLSR |
|
9
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
10
|
|
|
* |
|
11
|
|
|
* @version GIT: <git_id> |
|
12
|
|
|
* |
|
13
|
|
|
* @link https://github.com/Dev-Int/glsr |
|
14
|
|
|
*/ |
|
15
|
|
|
namespace App\Entity\Staff; |
|
16
|
|
|
|
|
17
|
|
|
use FOS\UserBundle\Model\Group as BaseGroup; |
|
18
|
|
|
use App\Entity\Staff\User; |
|
19
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Group Entity. |
|
23
|
|
|
* |
|
24
|
|
|
* @category Entity |
|
25
|
|
|
* |
|
26
|
|
|
* @ORM\Entity |
|
27
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\Staff\GroupRepository") |
|
28
|
|
|
* @ORM\Table(name="fos_group") |
|
29
|
|
|
*/ |
|
30
|
|
|
class Group extends BaseGroup |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @var int $grpId Group id |
|
34
|
|
|
* |
|
35
|
|
|
* @ORM\Id |
|
36
|
|
|
* @ORM\Column(name="id", type="integer") |
|
37
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $grpId; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $name; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var array |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $roles; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @var array $users Array of users |
|
53
|
|
|
* @ORM\ManyToMany(targetEntity="App\Entity\Staff\User", mappedBy="groups") |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $users; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Get id. |
|
59
|
|
|
* |
|
60
|
|
|
* @return int |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getId() |
|
63
|
|
|
{ |
|
64
|
|
|
return $this->grpId; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Get Users |
|
69
|
|
|
* |
|
70
|
|
|
* @return App\Entity\Staff\User |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getUsers() |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->users; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Add users |
|
79
|
|
|
* |
|
80
|
|
|
* @param \App\Entity\Staff\User $users |
|
81
|
|
|
* @return Group |
|
82
|
|
|
*/ |
|
83
|
|
|
public function addUser(User $users) |
|
84
|
|
|
{ |
|
85
|
|
|
$this->users[] = $users; |
|
86
|
|
|
|
|
87
|
|
|
return $this; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function hasRole($role) |
|
91
|
|
|
{ |
|
92
|
|
|
if (is_array($this->roles)) { |
|
93
|
|
|
$return = in_array(strtoupper($role), $this->roles, true); |
|
94
|
|
|
} else { |
|
95
|
|
|
$return = false; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return $return; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Remove users |
|
103
|
|
|
* |
|
104
|
|
|
* @param \App\Entity\Staff\User $users |
|
105
|
|
|
*/ |
|
106
|
|
|
public function removeUser(User $users) |
|
107
|
|
|
{ |
|
108
|
|
|
$this->users->removeElement($users); |
|
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* This method allows to do "echo $group". |
|
113
|
|
|
* <p> So, to "show" $group, |
|
114
|
|
|
* PHP will actually show the return of this method. <br /> |
|
115
|
|
|
* Here, the name, so "echo $group" |
|
116
|
|
|
* is equivalent to "echo $unit->getName()" </ p>. |
|
117
|
|
|
* @return string name |
|
118
|
|
|
*/ |
|
119
|
|
|
public function __toString() |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->getName(); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.