-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoleModel.php
More file actions
129 lines (108 loc) · 2.79 KB
/
RoleModel.php
File metadata and controls
129 lines (108 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php // vim:ts=3:sts=3:sw=3:et:
/**
* Role model
*
* PHP Version 5
*
* @category PHP
* @package MindFrame2
* @author Bryan C. Geraghty <bryan@ravensight.org>
* @copyright 2005-2011 Bryan C. Geraghty
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU LGPL
* @link https://github.com/archwisp/MindFrame2
*/
/**
* Role model
*
* @category PHP
* @package MindFrame2
* @author Bryan C. Geraghty <bryan@ravensight.org>
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU LGPL
* @link https://github.com/archwisp/MindFrame2
*/
class MindFrame2_RoleModel
implements MindFrame2_Dbms_Record_Interface,
MindFrame2_Authorization_RoleInterface
{
private $_role_id;
private $_label;
private $_permissions = array();
private $_organization;
public function __construct($role_id, $label,
MindFrame2_Authorization_OrganizationInterface $organization)
{
$this->setLabel($label);
$this->setOrganization($organization);
$this->setRoleId($role_id);
}
public function addPermission(MindFrame2_Authorization_PermissionInterface $permission)
{
$this->_permissions[$permission->getPermissionId()] = $permission;
}
public function getRoleId()
{
return $this->_role_id;
}
public function getLabel()
{
return $this->_label;
}
public function getOrganization()
{
return $this->_organization;
}
public function getPermissions()
{
return $this->_permissions;
}
public function getPermissionIds()
{
return array_keys($this->getPermissions());
}
public function getPermissionById($permission_id)
{
if (array_key_exists($permission_id, $this->_permissions))
{
return $this->_permissions[$permission_id];
}
return FALSE;
}
public function getPermissionByLabel($label)
{
$permissions = $this->getPermissions();
foreach ($permissions as $permission)
{
if ($permission->getLabel() == $label)
{
return $permission;
}
}
return FALSE;
}
public function getPrimaryKey()
{
return $this->getRoleId();
}
public function removePermission(MindFrame2_Authorization_PermissionInterface $permission)
{
unset($this->_permissions[$permission->getPermissionId()]);
}
public function setLabel($label)
{
MindFrame2_Core::assertArgumentIsNotBlank($label, 1, 'label');
$this->_label = $label;
}
public function setOrganization(
MindFrame2_Authorization_OrganizationInterface $organization)
{
$this->_organization = $organization;
}
public function setPrimaryKey($role_id)
{
return $this->setRoleId($role_id);
}
public function setRoleId($role_id)
{
$this->_role_id = $role_id;
}
}