Sep
8
Joomla add Custom User Groups
September 8, 2008 |
Joomla! come with default user groups, but sometimes to build a specific site, you may want to have
custom user groups (user roles) within Joomla 1.5. For example under the registered users group, you may want to have several subgroups:
myproject
customers
customer A admin
product manager
product manager admin
etc…
To use these groups within your extension to set the permissions, when you add the groups into the jos_core_acl_aro_groups database table and set the relations correctly, the groups in the user management will not be displayed correctly (e.g. the administrator groups disappear). To display the groups correctly you must change the code of : /administrator/components/com_users/admin.users.php line 285:
if ( $userGroupName == $myGroupName && $myGroupName == 'administrator' )
{
// administrators can't change each other
$lists['gid'] = '<input type="hidden" name="gid" value="'. $user->get('gid') .'" /><strong>'. JText::_( 'Administrator' ) .'</strong>';
}
else
{
$gtree = $acl->get_group_children_tree( null, 'USERS', false );
to:
if ( $userGroupName == $myGroupName && $myGroupName == 'administrator' )
{
// administrators can't change each other
$lists['gid'] = '<input type="hidden" name="gid" value="'. $user->get('gid') .'" /><strong>'. JText::_( 'Administrator' ) .'</strong>';
}
else
{
$gtree = $acl->get_group_children_tree( null, 'USERS', true);
If you like to add your self custom groups do the following:
Edit the jos_core_acl_aro_groups table and add your custom groups (e.g. with phpMyAdmin). When you add a new group make sure that you assign the correct parent to the added group. For instance: the joomla registered group has the ID 19, when you assign a subgroup to it make sure that the parent_id is 19. Don’t assign the lft and rght fields yet but use the code below to rebuild the groups tree correctly:
<?php
mysql_connect("localhost", "xxxx", "xxxxx") or
die("Could not connect: " . mysql_error());
mysql_select_db("joomla15");
// 0-> parent_id in Joomla this is the value of the parent_id field of the Root record
// 1-> start the left tree at 1
rebuild_tree ( 0 , 1);
function rebuild_tree($parent_id, $left) {
// the right value of this node is the left value + 1
$right = $left+1;
// get all children of this node
$result = mysql_query('SELECT id FROM jos_core_acl_aro_groups '.
'WHERE parent_id="'.$parent_id.'";');
while ($row = mysql_fetch_array($result)) {
// recursive execution of this function for each
// child of this node
// $right is the current right value, which is
// incremented by the rebuild_tree function
$right = rebuild_tree($row['id'], $right);
}
// we've got the left value, and now that we've processed
// the children of this node we also know the right value
mysql_query('UPDATE jos_core_acl_aro_groups SET lft='.$left.', rgt='.
$right.' WHERE id="'.$parent_id.'";');
// return the right value of this node + 1
return $right+1;
}
?>
If you want to use the custom groups to assign to your articles so that, for example, only the customers can view specific articles, you need to add these groups into the jos_groups, just assign the ID + name of the group whereby the name must be equal to the group name you added into the jos_core_acl_aro_groups database table.
Similar Posts
- Joomla Retrieve Admin Password
- Remove Mootools From Joomla Header
- Joomla! - Make Latest News Module Display Date
- Joomla Loads Position Module within Content
- Joomla PDF Display Problem in IE7 Fix
- Make Joomla localhost Email Work
- Joomla Manually Setup Enable SEF URL
- Install and Run Joomla on Ubuntu
- Proper Way to Use Joomla getNumRows
- Joomla - Use loadObjectList and foreach to get list
- Way to use Joomla loadAssoc
- Joomla - Link Excerpt Article Title to Full Article
Comments
2 Comments so far



































Thanks this is a great help. I have been scratching my head on how to do this.
Very good article and i’m trying to use it. Using Joomla 1.5.7. I could not find the path to /administrator/components/com_users/admin.users.php line 285
No file called admin.users.php
can only find users.php but nothing similar to what we need to change