Add a User to a Group
The LiveUser_Admin package allows you to manage users within groups to be used within LiveUser. It provides a series of methods to interact with the «liveuser_groupusers» table.
The example 1 provided with this PEAR package should help you starting quite quickly.
There are a few methods for user groups management:
- addUserToGroup: to add a user to a group
- removeUserFromGroup: to remove a user from a group
Prerequisite: you need to set the permission management level to, at least, «Medium» in the configuration file.
We'll start by adding a user to a group, then deleting the user from the group
Here is the full example :
Download «LUA_test_groupuser.php»
Add a User to a Group (addGroup)
function addUserToGroup($data)
Parameter(s)
This method takes 1 parameter:
- an array with a pair key/value of all fields in the «liveuser_groupusers»
You must provide the group id and the user id at permission level (perm_user_id).
Return value
This method returns:
- «false» in case of error
- «true» otherwise
Example
To add a user to a group:
...
$data = array(
'perm_user_id' => $users[0]['perm_user_id'],
'group_id' => 5
);
$added = $LUA->perm->addUserToGroup($data);
...
This gives the following result:

Remove a User from a Group (removeUserFromGroup)
function removeUserFromGroup($filters)
Parameter(s)
This method takes 1 parameter:
- an array with key/value to select the record(s) to be deleted.
Attention: if no parameter is passed, all group users will be removed.
Return value
This method returns:
- «false» in case of error
- «true» otherwise
Example
...
$filter = array(
'perm_user_id' => $users[0]['perm_user_id'],
'group_id' => $group_id
);
$removed = $LUA->perm->removeUserFromGroup($filter);
...
This gives the following result:

Getting Information on the last Error (getErrors)
function getErrors()
In case a function returns «false», it means that it has encountered a problem. You can get information on this error by calling this method.
Parameter(s)
This method takes no parameter.
Return value
This method returns:
- the error information
Example
...
$added = $LUA->perm->addUserToGroup($data);
if ($added == false)
{
echo 'Add_groupuser: error on line: '.__LINE__;
print_r($LUA->getErrors());
}
else
{
echo 'User with id ' . $data['perm_user_id'] . ' added to group id ' . $data['group_id'];
}
...



