CMS  Version 3.9
RoleManager Class Reference

Public Member Functions

 RoleManager ()
 

Static Public Member Functions

static deleteRoleFromString (&$items, $del_role, $field="")
 
static addRoleToAccessList ($items, $role, $field="role")
 Adds the specified role to the access list field in each of the supplied DataItems. More...
 
static removeRoleFromAccessList ($items, $role, $field="role")
 Removes the specified role from the access list field in each of the supplied DataItems. More...
 
static registerSerializationHandler ()
 
static upgradeComponent ($version)
 

Detailed Description

Definition at line 41 of file role_manager.inc.

Member Function Documentation

◆ addRoleToAccessList()

static RoleManager::addRoleToAccessList (   $items,
  $role,
  $field = "role" 
)
static

Adds the specified role to the access list field in each of the supplied DataItems.

Parameters
mixed$itemsthe DataItem or array of DataItems to be updated
string$rolethe role to add to the access list field
string$fieldthe name of the field (default is 'role')

Definition at line 93 of file role_manager.inc.

94  {
95  if (count($items) == 0) return;
96  if (is_object($items))
97  {
98  if (!$items instanceof DataItem) return;
99  $items = array( $items );
100  }
101 
102  foreach($items as $item)
103  {
104  if (!$item->hasField($field)) continue;
105 
106  $roles = explode(",", $item->get($field));
107  $found = false;
108  foreach($roles as $r)
109  {
110  if ($r == $role)
111  {
112  $found = true;
113  break;
114  }
115  }
116 
117  if (!$found)
118  {
119  $roles[] = $role;
120  $oldFilter = $item->filter;
121  $item->filter = new InclusionFilter($field);
122  $item->set($field, implode(",", $roles));
123  $item->save();
124  $item->filter = $oldFilter;
125  }
126  }
127  }
$role
Definition: role_form.inc:41

◆ deleteRoleFromString()

static RoleManager::deleteRoleFromString ( $items,
  $del_role,
  $field = "" 
)
static
Deprecated:
Called by ComponentManager, PageManager, UserManager, and MenuItemManager

Definition at line 53 of file role_manager.inc.

54  {
55  if(count($items) == 0)
56  return;
57 
58  if(!$field)
59  $field = "role";
60 
61  foreach($items as $item)
62  {
63  if(!$item->$field)
64  continue;
65 
66  $newRoles = array();
67 
68  $roles = explode(",", $item->$field);
69  foreach($roles as $role)
70  {
71  if(!preg_match("/$del_role/", $role))
72  $newRoles[] = $role;
73  }
74 
75  if(count($newRoles) > 0)
76  $newRole = implode(",", $newRoles);
77  else
78  $newRole = "";
79 
80  $item->$field = $newRole;
81  $item->filter = new InclusionFilter($field);
82  $item->save();
83  }
84  }

◆ registerSerializationHandler()

static RoleManager::registerSerializationHandler ( )
static

Definition at line 175 of file role_manager.inc.

176  {
178  }
registerHandler($component, $title, $handler)
Registers a serialization handler for a component.
Provides a simple implementation of a SerializationHandler that can serialize a single DataItem class...

◆ removeRoleFromAccessList()

static RoleManager::removeRoleFromAccessList (   $items,
  $role,
  $field = "role" 
)
static

Removes the specified role from the access list field in each of the supplied DataItems.

Parameters
mixed$itemsthe DataItem or array of DataItems to be updated
string$rolethe role to add to the access list field
string$fieldthe name of the field (default is 'role')

Definition at line 136 of file role_manager.inc.

137  {
138  if (count($items) == 0) return;
139  if (is_object($items))
140  {
141  if (!$items instanceof DataItem) return;
142  $items = array( $items );
143  }
144 
145  foreach($items as $item)
146  {
147  if (!$item->hasField($field)) continue;
148 
149  $roles = explode(",", $item->get($field));
150  $newRoles =array();
151  $found = false;
152  foreach($roles as $r)
153  {
154  if ($r == $role)
155  {
156  $found = true;
157  }
158  else
159  {
160  $newRoles[] = $r;
161  }
162  }
163 
164  if ($found)
165  {
166  $oldFilter = $item->filter;
167  $item->filter = new InclusionFilter($field);
168  $item->set($field, implode(",", $newRoles));
169  $item->save();
170  $item->filter = $oldFilter;
171  }
172  }
173  }

◆ RoleManager()

RoleManager::RoleManager ( )

Definition at line 43 of file role_manager.inc.

44  {
45 
46  }

◆ upgradeComponent()

static RoleManager::upgradeComponent (   $version)
static

Definition at line 180 of file role_manager.inc.

181  {
182  $mgr = new RoleUpgradeManager();
183  $mgr->upgrade($version);
184  }

The documentation for this class was generated from the following file: