Create a User Group

fasenderos 29 Sep, 2012
Hi,
how to create a joomla user group with name entered in the form?

I'm trying with this code, but don't seems to work:


//get group name
$group_name = $form->data['group_name']

// get max right from all the child under parent id
$child_query = "SELECT max(`rgt`) FROM `#__usergroups` WHERE `id` = 2";
$db->setQuery($child_query);
$max_rgt = $db->loadResult();

// calculate left and rgt for new entry
$new_lft = $max_rgt;
$new_rgt = $max_rgt + 1;

// update lft and rgt of all entries having lft , rgt greater than max_rgt
$upd1 = "UPDATE `#__usergroups` SET `lft` = `lft` + 2 WHERE `lft` > ".$max_rgt;
$upd2 = "UPDATE `#__usergroups` SET `rgt` = `rgt` + 2 WHERE `rgt` >= ".$max_rgt;

// insert new  child
$insert = "INSERT INTO `#__usergroups`(`parent_id`,`lft`,`rgt`,`title`) VALUES(10,".$new_lft.",".$new_rgt.",'".$group_name."')";


Thanks in advance
GreyHead 30 Sep, 2012
Hi fasenderos,

I think that this is a question for the Joomla! forums :-( Groups in Joomla! 2.5 are complicated and I don't begin to understand them. I think that the code you need is in administrator/components/com_users/models/group.php in the save() function but having looked at it I can't work out exactly what it does.

Bob
This topic is locked and no more replies can be posted.