Interface to export rights from LiveUser

The LiveUser_Admin package allows you to manage rights granted directly to users. This corresponds to the Simple Level permission management. It provides a series of methods to interact with the «liveuser_userrights» table.

The example 1 provided with this PEAR package should help you starting quite quickly.

There are a few methods for user rights management:

We'll start by adding a user right, then updating it and finally deleting a user right.

Here is the full example :

Download «LUA_test_userright.php»

Add a user right (grantUserRight)

function grantUserRight($data)

Parameter(s)

This method takes 1 parameter:

  • an array with a pair key/value of all fields in the «liveuser_userrights»

Return value

This method returns:

  • «false» in case of error
  • «true» otherwise

Example

To add a user right:

Code
   ...
    $data = array(
        'perm_user_id' => $users[0]['perm_user_id'],
        'right_id' => 5,
        'right_level' => 3,
       );
    $granted = $LUA->perm->grantUserRight($data);
   ...

This gives the following result:

Grant a User Right

Update a user right (updateUserRight)

function updateUserRight($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

Code
   ...
    $new_right_level = 2;
    $right_id = 5;

    $handle = 'test user';
    $filter = array('handle' => $handle);
    $users = ('auth', $filter);

    $data = array('right_level' => $new_right_level);
    $filter = array('perm_user_id' => $users[0]['perm_user_id'],
                    'right_id' => $right_id);
    $updatedUserRight = $LUA->perm->updateUserRight($data, $filter);
   ...

This gives the following result:

Update a User Right

Remove a user right (revokeUserRight)

function revokeUserRight($filter)

This method will remove a right granted to a user.

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 user rights will be removed.

Return value

This method returns:

  • «false» in case of error
  • «true» otherwise

Example

Code
   ...
    $right_id = 5;

    $handle = 'test user';
    $filter = array('handle' => $handle);
    $users = $LUA->getUsers('auth', $filter);

    $filter = array(
        'perm_user_id' => $users[0]['perm_user_id'],
        'right_id' => $right_id
       );
    $revoked = $LUA->perm->revokeUserRight($filter);
   ...

This gives the following result:

Revoke a User Right

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

Code
   ...
    $granted = $LUA->perm->grantUserRight($data);
    if ($granted == false)
      {
      echo 'Add_userright: error on line: '.__LINE__;
      print_r($LUA->getErrors());
      }
    else
      {
      echo 'User Right added';
      }
   ...

Get in touch!

We'd love to hear from you, what you think about this page or what we can do for you.

Contact Us

View this page with IE8+, Mozilla Firefox, Safari, Chrome and Mobiles

Last modificaton on 21 May 2015 by St├ęphane Van Nerom

© 2006-2014 - GVN - All rights reserved
v2.0.14