1
|
|
|
<?php |
2
|
|
|
namespace Gvera\Models; |
3
|
|
|
|
4
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
5
|
|
|
use Doctrine\Common\Collections\Collection; |
6
|
|
|
use Gvera\Helpers\entities\GvEntityManager; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class UserStatus |
10
|
|
|
* @package Gvera\Models |
11
|
|
|
* @Entity @Table(name="user_roles") |
12
|
|
|
*/ |
13
|
|
|
class UserRole |
14
|
|
|
{ |
15
|
|
|
/** @Id @Column(type="integer") @GeneratedValue */ |
16
|
|
|
protected $id; |
17
|
|
|
/** @Column(type="string", nullable=false, unique=true, length=20) */ |
18
|
|
|
protected $name; |
19
|
|
|
/** @Column(type="integer", unique=true, nullable=false) */ |
20
|
|
|
protected $rolePriority; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Many Users have Many Stores. |
24
|
|
|
* @ManyToMany(targetEntity="UserRoleAction", inversedBy="user_role_actions", fetch="EAGER", cascade={"persist"}) |
25
|
|
|
*/ |
26
|
|
|
protected Collection $userRoleActions; |
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* UserRole constructor. |
30
|
|
|
* @param GvEntityManager $entityManager |
31
|
|
|
*/ |
32
|
|
|
public function __construct() |
33
|
|
|
{ |
34
|
|
|
$this->userRoleActions = new ArrayCollection(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return mixed |
40
|
|
|
*/ |
41
|
|
|
public function getName() |
42
|
|
|
{ |
43
|
|
|
return $this->name; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param mixed $name |
48
|
|
|
*/ |
49
|
|
|
public function setName($name) |
50
|
|
|
{ |
51
|
|
|
$this->name = $name; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return mixed |
56
|
|
|
*/ |
57
|
|
|
public function getRolePriority() |
58
|
|
|
{ |
59
|
|
|
return $this->rolePriority; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param mixed $rolePriority |
64
|
|
|
*/ |
65
|
|
|
public function setRolePriority($rolePriority) |
66
|
|
|
{ |
67
|
|
|
$this->rolePriority = $rolePriority; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return Collection |
72
|
|
|
*/ |
73
|
|
|
public function getUserRoleActions(): Collection |
74
|
|
|
{ |
75
|
|
|
return $this->userRoleActions; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param Collection $userRoleActions |
80
|
|
|
*/ |
81
|
|
|
public function setUserRoleActions(Collection $userRoleActions): void |
82
|
|
|
{ |
83
|
|
|
$this->userRoleActions = $userRoleActions; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function addRoleAction(UserRoleAction $roleAction) |
87
|
|
|
{ |
88
|
|
|
if (null === $roleAction) { |
89
|
|
|
return; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if ($this->userRoleActions->contains($roleAction)) { |
93
|
|
|
return; |
94
|
|
|
} |
95
|
|
|
$this->userRoleActions->add($roleAction); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function removeRoleAction(UserRoleAction $roleAction) |
99
|
|
|
{ |
100
|
|
|
if (!$this->userRoleActions->contains($roleAction)) { |
101
|
|
|
return; |
102
|
|
|
} |
103
|
|
|
$this->userRoleActions->removeElement($roleAction); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|