Permissions Management - Medium Level
The LiveUser_Admin package allows you to assign rights to groups to be used within LiveUser. It provides a series of methods to interact with the «liveuser_grouprights» table.
The example 1 provided with this PEAR package should help you starting quite quickly.
There are a few methods for group rights management:
- grantGroupRight: to grant a right to a group
- updateGroupRight: to update a right granted to a group
- revokeGroupRight: to remove a right granted to 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_groupright.php»
Add a Right to a Group (grantGroupRight)
function grantGroupRight($data)
Parameter(s)
This method takes 1 parameter:
- an array with a pair key/value of all fields in the «liveuser_grouprights»
You must provide the group id and the right id. Unless you provide another value, a right level of 3 will be set by default.
Return value
This method returns:
- «false» in case of error
- «true» otherwise
Example
To grant a right to a group:
...
$data = array('right_id' => 5,
'group_id' => 6
);
$added = $LUA->perm->grantGroupRight($data);
...
This gives the following result:

Update a Right granted to a Group (updateGroupRight)
function updateGroupRight($data, $filter)
Parameter(s)
This method takes 2 parameters:
- an array with key/value containing the updated values
- an array with key/value to select the record to be updated
Return value
This method returns:
- «false» in case of error
- «true» otherwise
Example
To update a right granted to a group:
...
$new_right_level = 1;
$right_id = 5;
$group_id = 6;
$data = array('right_level' => $new_right_level);
$filters = array('right_id' => $right_id,
'group_id' => $group_id);
$updated = $LUA->perm->updateGroupRight($data, $filters);
...
This gives the following result:

Remove a Right granted to a Group (revokeGroupRight)
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 rights will be removed.
Return value
This method returns:
- «false» in case of error
- «true» otherwise
Example
...
$filter = array(
'group_id' => $group_id
);
$removed = $LUA->perm->revokeGroupRight($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->grantGroupRight($data);
if ($added == false)
{
echo 'Add_groupright: error on line: '.__LINE__;
print_r($LUA->getErrors());
}
else
{
echo 'Group with id ' . $data['group_id'];
echo ' has been granted right id ' . $data['right_id'];
}
...



