1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file contains functionality relating to permissions that roles have |
4
|
|
|
* |
5
|
|
|
* @package BZiON\Models |
6
|
|
|
* @license https://github.com/allejo/bzion/blob/master/LICENSE.md GNU General Public License Version 3 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* A permission that is assigned to a role |
11
|
|
|
* @package BZiON\Models |
12
|
|
|
*/ |
13
|
|
|
class Permission extends Model |
14
|
|
|
{ |
15
|
|
|
const ADD_BAN = "add_ban"; |
16
|
|
|
const ADD_MAP = "add_map"; |
17
|
|
|
const ADD_SERVER = "add_server"; |
18
|
|
|
const CREATE_NEWS = "add_news"; |
19
|
|
|
const CREATE_PAGE = "add_page"; |
20
|
|
|
const CREATE_ROLE = "add_role"; |
21
|
|
|
const CREATE_TEAM = "add_team"; |
22
|
|
|
const CREATE_USER = "add_user"; |
23
|
|
|
const EDIT_BAN = "edit_ban"; |
24
|
|
|
const EDIT_MAP = "edit_map"; |
25
|
|
|
const EDIT_MATCH = "edit_match"; |
26
|
|
|
const EDIT_NEWS = "edit_news"; |
27
|
|
|
const EDIT_PAGE = "edit_page"; |
28
|
|
|
const EDIT_ROLE = "edit_role"; |
29
|
|
|
const EDIT_SERVER = "edit_server"; |
30
|
|
|
const EDIT_TEAM = "edit_team"; |
31
|
|
|
const EDIT_USER = "edit_user"; |
32
|
|
|
const ENTER_MATCH = "add_match"; |
33
|
|
|
const HARD_DELETE_BAN = "wipe_ban"; |
34
|
|
|
const HARD_DELETE_MAP = "wipe_map"; |
35
|
|
|
const HARD_DELETE_MATCH = "wipe_match"; |
36
|
|
|
const HARD_DELETE_NEWS = "wipe_news"; |
37
|
|
|
const HARD_DELETE_PAGE = "wipe_page"; |
38
|
|
|
const HARD_DELETE_ROLE = "wipe_role"; |
39
|
|
|
const HARD_DELETE_SERVER = "wipe_server"; |
40
|
|
|
const HARD_DELETE_TEAM = "wipe_team"; |
41
|
|
|
const HARD_DELETE_USER = "wipe_user"; |
42
|
|
|
const PUBLISH_NEWS = "publish_news"; |
43
|
|
|
const PUBLISH_PAGE = "publish_page"; |
44
|
|
|
const SEND_PRIVATE_MSG = "send_pm"; |
45
|
|
|
const SOFT_DELETE_BAN = "del_ban"; |
46
|
|
|
const SOFT_DELETE_MATCH = "del_match"; |
47
|
|
|
const SOFT_DELETE_MAP = "del_map"; |
48
|
|
|
const SOFT_DELETE_NEWS = "del_news"; |
49
|
|
|
const SOFT_DELETE_PAGE = "del_page"; |
50
|
|
|
const SOFT_DELETE_ROLE = "del_role"; |
51
|
|
|
const SOFT_DELETE_SERVER = "del_server"; |
52
|
|
|
const SOFT_DELETE_TEAM = "del_team"; |
53
|
|
|
const SOFT_DELETE_USER = "del_user"; |
54
|
|
|
const VIEW_SERVER_LIST = "view_server_list"; |
55
|
|
|
const VIEW_VISITOR_LOG = "view_visitor_log"; |
56
|
|
|
const BYPASS_MAINTENANCE = "bypass_maintenance"; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* The name of the permission |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
protected $name; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* The description of the permission |
66
|
|
|
* @var string |
67
|
|
|
*/ |
68
|
|
|
protected $description; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* The name of the database table used for queries |
72
|
|
|
*/ |
73
|
|
|
const TABLE = "permissions"; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
1 |
|
protected function assignResult($permission) |
79
|
|
|
{ |
80
|
1 |
|
$this->name = $permission['name']; |
81
|
1 |
|
$this->description = $permission['description']; |
82
|
1 |
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get the description of the permission |
86
|
|
|
* @return string The description of the permission |
87
|
|
|
*/ |
88
|
|
|
public function getDescription() |
89
|
|
|
{ |
90
|
|
|
return $this->description; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Get the name of the permission |
95
|
|
|
* @return string The name of the permission |
96
|
|
|
*/ |
97
|
|
|
public function getName() |
98
|
|
|
{ |
99
|
|
|
return $this->name; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Get all of the existing permissions in the database |
104
|
|
|
* @return Permission[] An array of permissions |
105
|
|
|
*/ |
106
|
|
|
public static function getPerms() |
107
|
|
|
{ |
108
|
|
|
return parent::arrayIdToModel( |
|
|
|
|
109
|
|
|
self::fetchIds() |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param string|Permission $perm_name |
115
|
|
|
* @return Permission |
116
|
|
|
*/ |
117
|
1 |
|
public static function getPermissionFromName($perm_name) |
118
|
|
|
{ |
119
|
1 |
|
if ($perm_name instanceof self) { |
120
|
|
|
return $perm_name; |
121
|
|
|
} |
122
|
|
|
|
123
|
1 |
|
return self::get( |
124
|
1 |
|
self::fetchIdFrom($perm_name, "name") |
125
|
|
|
); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public static function getQueryBuilder() |
129
|
|
|
{ |
130
|
|
|
return new QueryBuilder("Permission", array( |
131
|
|
|
'columns' => array( |
132
|
|
|
'name' => 'name' |
133
|
|
|
), |
134
|
|
|
'name' => 'name' |
135
|
|
|
)); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.