CMS
Version 3.9
role.inc
Go to the documentation of this file.
1
<?php
7
/**************************************************************
8
9
Copyright (c) 2010 Sonjara, Inc
10
11
Permission is hereby granted, free of charge, to any person
12
obtaining a copy of this software and associated documentation
13
files (the "Software"), to deal in the Software without
14
restriction, including without limitation the rights to use,
15
copy, modify, merge, publish, distribute, sublicense, and/or sell
16
copies of the Software, and to permit persons to whom the
17
Software is furnished to do so, subject to the following
18
conditions:
19
20
The above copyright notice and this permission notice shall be
21
included in all copies or substantial portions of the Software.
22
23
Except as contained in this notice, the name(s) of the above
24
copyright holders shall not be used in advertising or otherwise
25
to promote the sale, use or other dealings in this Software
26
without prior written authorization.
27
28
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
32
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35
OTHER DEALINGS IN THE SOFTWARE.
36
37
*****************************************************************/
38
39
$siteUserRoles
= array(
"admin"
=>
"Administrator"
,
40
"member"
=>
"Site Member"
);
41
42
class
SiteRole
extends
DataItem
43
{
44
// Fields
45
46
var
$fields
= array(
"role_id"
=> Number,
47
"role"
=> String,
48
"name"
=> String,
49
"description"
=> Text,
50
"priority"
=> Number,
51
"home_page"
=> String);
52
53
54
// Relations
55
var
$relations
= array(
"Site"
=>
Site
);
56
57
function
Site
()
58
{
59
return
$this->getRelated(
Site
);
60
}
61
62
function
SiteRole
()
63
{
64
$this->table =
"site_role"
;
65
$this->primary_key =
"role_id"
;
66
$this->default_format =
"{name}"
;
67
68
$this->DataItem(func_get_args());
69
}
70
75
static
function
getRolesArray
()
76
{
77
$roles
= query(
SiteRole
,
"WHERE role!='super' ORDER BY priority, name"
);
78
79
$rarr = array();
80
81
foreach
(
$roles
as
$role
)
82
{
83
$rarr[
$role
->role] =
$role
->name;
84
}
85
86
return
$rarr;
87
}
88
89
// Given a role code, return the record
90
static
function
getRole
(
$role
)
91
{
92
$names = query(
SiteRole
,
"WHERE role='$role'"
);
93
if
(count($names) > 0)
94
return
$names[0];
95
}
96
97
static
function
getRoleLookup
()
98
{
99
return
IndexedQuery::create(
SiteRole
,
"ORDER by priority, name"
,
"role"
)->execute();
100
}
101
102
static
function
getHomePage
($account =
null
)
103
{
104
$roles
=
SiteRole::getRoleLookup
();
105
foreach
(
$roles
as
$role
=> $details)
106
{
107
if
(checkRole(
$role
, $account))
return
$details->home_page;
108
}
109
110
return
""
;
111
}
112
113
/*
114
* Given a comma delimited list of roles (as role is stored
115
* in the user role field, return the list of corresponding
116
* role names.
117
*/
118
static
function
getRoleNames
(
$role
)
119
{
120
$roles
= explode(
","
,
$role
);
121
if
(count(
$roles
) > 0)
122
{
123
foreach
(
$roles
as
$role
)
124
{
125
$name
=
SiteRole::getRole
(
$role
);
126
if
(
$name
)
127
$names[] =
$name
->name;
128
}
129
}
130
131
return
implode(
", "
, array_values($names));
132
}
133
}
134
?>
$name
$name
Definition:
upload.inc:54
Site
Definition:
site.inc:40
SiteRole
Definition:
role.inc:43
SiteRole\getRoleNames
static getRoleNames($role)
Definition:
role.inc:118
SiteRole\getRolesArray
static getRolesArray()
Retrieves the array of roles and their names for the current site for use in a CMS form.
Definition:
role.inc:75
SiteRole\getRole
static getRole($role)
Definition:
role.inc:90
SiteRole\$relations
$relations
Definition:
role.inc:55
SiteRole\$fields
$fields
Definition:
role.inc:46
SiteRole\Site
Site()
Definition:
role.inc:57
SiteRole\getRoleLookup
static getRoleLookup()
Definition:
role.inc:97
SiteRole\SiteRole
SiteRole()
Definition:
role.inc:62
SiteRole\getHomePage
static getHomePage($account=null)
Definition:
role.inc:102
$roles
$roles
Definition:
global_permissions_form.inc:56
$siteUserRoles
$siteUserRoles
Definition:
role.inc:39
$role
$role
Definition:
role_form.inc:41
code
cms.sonjara.com
cms
components
role
datamodel
role.inc
Generated on Tue Mar 23 2021 15:36:14 for CMS by
1.9.1