3 * Container for role properties.
5 * Copyright 2003 Mark O'Sullivan
6 * This file is part of Lussumo's Software Library.
7 * Lussumo's Software Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
8 * Lussumo's Software Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
9 * You should have received a copy of the GNU General Public License along with Vanilla; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
10 * The latest source code is available at www.lussumo.com
11 * Contact Mark O'Sullivan at mark [at] lussumo [dot] com
13 * @author Mark O'Sullivan
14 * @copyright 2003 Mark O'Sullivan
15 * @license http://lussumo.com/community/gpl.txt GPL 2
22 * Container for role properties.
25 class Role
extends Delegation
{
31 var $PERMISSION_SIGN_IN;
32 var $PERMISSION_HTML_ALLOWED;
33 var $PERMISSION_RECEIVE_APPLICATION_NOTIFICATION;
40 $this->Description
= '';
41 $this->PERMISSION_SIGN_IN
= 0;
42 $this->PERMISSION_HTML_ALLOWED
= 0;
43 $this->PERMISSION_RECEIVE_APPLICATION_NOTIFICATION
= 0;
44 $this->Permissions
= array();
45 $this->Unauthenticated
= 0;
47 // Loop through the configuration array looking for permission declarations
48 while (list($ConfigurationKey, $ConfigurationValue) = each($this->Context
->Configuration
)) {
49 if (substr($ConfigurationKey, 0, 11) == 'PERMISSION_') {
50 $this->AddPermission($ConfigurationKey);
54 // Call a delegate here so that others can add new role permissions
55 $this->CallDelegate('DefineRolePermissions');
58 function FormatPropertiesForDatabaseInput() {
59 $this->RoleName
= FormatStringForDatabaseInput($this->RoleName
, 1);
60 $this->Icon
= FormatStringForDatabaseInput($this->Icon
, 1);
61 $this->Description
= FormatStringForDatabaseInput($this->Description
, 1);
62 if (is_array($this->Permissions
)) {
63 // Make sure to remove the hard-coded permissions from the array before saving
64 if (array_key_exists('PERMISSION_SIGN_IN', $this->Permissions
)) unset($this->Permissions
['PERMISSION_SIGN_IN']);
65 if (array_key_exists('PERMISSION_HTML_ALLOWED', $this->Permissions
)) unset($this->Permissions
['PERMISSION_HTML_ALLOWED']);
66 if (array_key_exists('PERMISSION_RECEIVE_APPLICATION_NOTIFICATION', $this->Permissions
)) unset($this->Permissions
['PERMISSION_RECEIVE_APPLICATION_NOTIFICATION']);
67 // Now serialize the array
68 $this->Permissions
= SerializeArray($this->Permissions
);
72 function FormatPropertiesForDisplay() {
73 $this->RoleName
= FormatStringForDisplay($this->RoleName
, 0);
74 $this->Description
= FormatStringForDisplay($this->Description
, 0);
77 function GetPropertiesFromDataSet($DataSet) {
78 $this->RoleID
= ForceInt(@$DataSet['RoleID'], 0);
79 $this->RoleName
= ForceString(@$DataSet['Name'],'');
80 $this->Icon
= ForceString(@$DataSet['Icon'],'');
81 $this->Description
= ForceString(@$DataSet['Description'],'');
82 $this->PERMISSION_SIGN_IN
= ForceBool(@$DataSet['PERMISSION_SIGN_IN'], 0);
83 $this->PERMISSION_HTML_ALLOWED
= ForceBool(@$DataSet['PERMISSION_HTML_ALLOWED'], 0);
84 $this->PERMISSION_RECEIVE_APPLICATION_NOTIFICATION
= ForceBool(@$DataSet['PERMISSION_RECEIVE_APPLICATION_NOTIFICATION'], 0);
85 $this->Unauthenticated
= ForceBool(@$DataSet['Unauthenticated'], 0);
86 $TempPermissions = '';
87 $TempPermissions = ForceString(@$DataSet['Permissions'], '');
88 $TempPermissions = UnserializeAssociativeArray($TempPermissions);
89 $this->Permissions
['PERMISSION_SIGN_IN'] = $this->PERMISSION_SIGN_IN
;
90 $this->Permissions
['PERMISSION_HTML_ALLOWED'] = $this->PERMISSION_HTML_ALLOWED
;
91 $this->Permissions
['PERMISSION_RECEIVE_APPLICATION_NOTIFICATION'] = $this->PERMISSION_RECEIVE_APPLICATION_NOTIFICATION
;
92 while (list($TempKey, $TempValue) = each($TempPermissions)) {
93 $this->Permissions
[$TempKey] = $TempValue;
95 unset($TempPermissions);
98 function GetPropertiesFromForm($Configuration) {
99 $this->RoleID
= ForceIncomingInt('RoleID', 0);
100 $this->RoleName
= ForceIncomingString('RoleName', '');
101 $this->Icon
= ForceIncomingString('Icon', '');
102 $this->Description
= ForceIncomingString('Description', '');
103 $this->Unauthenticated
= ForceIncomingBool('Unauthenticated', 0);
104 $this->PERMISSION_SIGN_IN
= ForceIncomingBool('PERMISSION_SIGN_IN', 0);
105 $this->PERMISSION_HTML_ALLOWED
= ForceIncomingBool('PERMISSION_HTML_ALLOWED', 0);
106 $this->PERMISSION_RECEIVE_APPLICATION_NOTIFICATION
= ForceIncomingBool('PERMISSION_RECEIVE_APPLICATION_NOTIFICATION', 0);
107 while (list($Key, $Permission) = each($this->Permissions
)) {
108 $this->Permissions
[$Key] = ForceIncomingBool($Key, 0);
112 function AddPermission($PermissionKey) {
113 if (!array_key_exists($PermissionKey, $this->Permissions
)) {
114 $this->Permissions
[$PermissionKey] = $this->Context
->Configuration
[$PermissionKey];
118 function Role(&$Context) {
119 $this->Name
= 'Role';
120 $this->Delegation($Context);