Exporting Rights
The LiveUser_Admin package allows you to extract the list of rights in different formats. The method interacts with the «liveuser_rights» table.
This is the method for extracting rights:
We'll use the method with various parameters to get the list in different formats.
Here is the full example :
Download «LUA_test_outputrights.php»
Extract rights (outputRightsConstants)
function outputRightsConstants($type, $options = array(), $mode = null)
Parameter(s)
This method takes 3 parameter:
- the type may be: «array», «php» or remain empty
- an array with a pair key/value of all option parameters
- the mode may be «file» or remain empty
Return value
This method returns:
- «false» in case of error
- «true» or an array otherwise
Example 1
To define the constants in an array:
...
$type = 'array';
$options = array();
$output = $LUA->perm->outputRightsConstants($type, $options);
...
This example will generate an array with all rights of the «liveuser_rights» table. In the array, the key will be the right name and the value will be the right id.
The array will contain, for instance: array['EVE_CREATE' => 2]
To limit the extraction to one area only, specify the filter criterion in the «$options» array:
...
$type = 'array';
$options = array('area' => 1);
$output = $LUA->perm->outputRightsConstants($type, $options);
...
In this case, only rights related to the area id=1 (Events) will be retrieved.
To prefix the rights with the area name, add a new parameter to the «$options» array:
...
$type = 'array';
$options = array('area' => 1,
'naming' => LIVEUSER_SECTION_AREA
);
$output = $LUA->perm->outputRightsConstants($type, $options);
...
The array will then contain array['EVENT_EVE_CREATE' => 2]
To prefix the rights with the application name, followed by the area names, change the parameter in the «$options» array:
...
$type = 'array';
$options = array('area' => 1,
'naming' => LIVEUSER_SECTION_APPLICATION
);
$output = $LUA->perm->outputRightsConstants($type, $options);
...
The array will then contain array['TEST_EVENT_EVE_CREATE' => 2]
To prefix the rights with an additional prefix, add a new parameter to the «$options» array:
...
$type = 'array';
$options = array('area' => 1,
'prefix' => 'prefix',
'naming' => LIVEUSER_SECTION_APPLICATION
);
$output = $LUA->perm->outputRightsConstants($type, $options);
...
The array will then contain array['prefix_TEST_EVENT_EVE_CREATE' => 2]
The «prefix» parameter may used with or without the «naming» parameter.
This gives the following result:

Example 2
To define the constants in php:
...
$type = 'php';
$options = array();
$output = $LUA->perm->outputRightsConstants($type, $options);
...
This example will define the corresponding constant(s) in php. Refer to the example 1 for the use of options.
So after the call, the «EVE_VIEW» constant will be defined and available for use.
This gives the following result:

Example 3
To generate a file containing the rights in an array:
...
$type = 'array';
$options = array('area' => 1,
'filename' => 'list_rights1.php',
'varname' => 'the_list');
$mode = 'file';
$output = $LUA->perm->outputRightsConstants($type, $options, );
...
Note: when $type is set to «array» and $mode is set to «file», the name of the variable ('varname' key) is mandatory.
This gives the following result:

The resulting file contains:
$the_list = array ( 'EVE_CREATE' => 2, 'EVE_DELETE' => 4, 'EVE_EDIT' => 3, 'EVE_VIEW' => 1, );
Example 4
To generate a file containing the rights as defined constants:
...
$type = '';
$options = array('area' => 1,
'filename' => 'list_rights2.php',
'varname' => 'the_list');
$mode = 'file';
$output = $LUA->perm->outputRightsConstants($type, $options, );
...
This gives the following result:

The resulting file contains:
define('EVE_CREATE', 2); define('EVE_DELETE', 4); define('EVE_EDIT', 3); define('EVE_VIEW', 1);
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
...
$output = $LUA->perm->outputRightsConstants($type, $options);
if ($output === false)
{
echo 'List_php: error on line: '.__LINE__;
print_r($LUA->getErrors());
}
else
{
echo 'List_array: OK';
}
...



