Rights Management
The LiveUser_Admin package allows you to manage rights to be used within LiveUser. It provides a series of methods to interact with the «liveuser_rights» table.
The example 1 provided with this PEAR package should help you starting quite quickly.
There are a few methods for rights management:
- addRight: to add a right to the list of rights
- updateRight: to modify a right in the list of rights
- removeRight: to remove a right from the list of rights
- getRights: to retrieve a list of rights
We'll start by adding a right, then updating it. We can then list all rights in the table before deleting a right.
Here is the full example :
Add a right (addRight)
function addRight($data)
Parameter(s)
This method takes 1 parameter:
- an array with a pair key/value of all fields in the «liveuser_rights»
In the easiest way, you may just provide the right name and the area id it is related to. In this case, the method will automatically allocate a right id (using the «liveuser_rights_seq» table).
Otherwise, you may provide the right name, the right id and the area id it is related to.
Return value
This method returns:
- «false» in case of error
- the new right id in case of success
Example
To add a right name:
...
$area_id = 5;
$right_name = 'A right';
$has_implied = 0;
$data = array('area_id' => $area_id,
'right_define_name' => $right_name,
'has_implied' => $has_implied);
$rightId = $LUA->perm->addRight($data);
...
To add a right name and a right id
...
$area_id = 5;
$right_id = 5;
$right_name = 'A right';
$has_implied = 0;
$data = array('area_id' => $area_id,
'right_id' => $right_id,
'right_define_name' => $right_name,
'has_implied' => $has_implied);
$rightId = $LUA->perm->addRight($data);
...
This gives the following result:

Update a right (updateRight)
function updateRight($data, $filter)
Parameter(s)
This method takes 2 parameters:
- an array with key/value containing the new value(s)
- an array with key/value to select the record to be updated
Attention: if no parameter is passed, all rights will be modified.
Return value
This method returns:
- «false» in case of error
- «true» otherwise
Example
...
$new_right_name = 'Another right';
$right_id = 5;
$data = array('right_define_name' => $new_right_name);
$filter = array('right_id' => $right_id);
$updateRight = $LUA->perm->updateRight($data, $filter);
...
This gives the following result:

List rights (getRights)
function getRights($params = array())
Parameter(s)
This method takes 1 parameter, i.e. an array with some possible parameters for the selection:
- «filter»: an array with key/value in order to apply the selection criterion
Return value
This method returns:
- «false» in case of error
- an array with selected data in case of success
Example
Get the list of all rights:
...
$rights = $LUA->perm->getRights();
...
Get a filtered list of rights:
...
$right_id = 5;
$filter = array('filters' => array('right_id' => $right_id));
$rights = $LUA->perm->getRights($filter);
...
This gives the following result:

Remove a right (removeRight)
function removeRight($filter)
This method will remove the right and all associated rights granted to users and groups. Associated implied rights are deleted as well.
Parameter(s)
This method takes 1 parameter:
- an array with key/value to select the record to be deleted.
Attention: if no parameter is passed, all rights will be removed.
Return value
This method returns:
- «false» in case of error
- «true» otherwise
Example
...
$right_id = 5;
$filter = array('right_id' => $right_id);
$removeRight = $LUA->perm->removeRight($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
...
$data = array('area_id' => $area_id,
'right_id' => $right_id,
'right_define_name' => $right_name,
'has_implied' => $has_implied);
$rightId = $LUA->perm->addRight($data);
if ($rightId == false)
{
echo 'Add_right: error on line: '.__LINE__;
print_r($LUA->getErrors());
}
else
{
echo 'Right with id ' . $rightId . ' created';
}
...



