Interface to manage LiveUser groups

The LiveUser_Admin package allows you to manage groups to be used within LiveUser. It provides a series of methods to interact with the «liveuser_groups» table.

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

There are a few methods for groups management:

  • addGroup: to add a group to the list of groups
  • updateGroup: to modify a group in the list of groups
  • removeGroup: to remove a group from the list of groups
  • getGroups: to retrieve a list of groups

Prerequisite: you need to set the permission management level to, at least, «Medium» in the configuration file.

Download «conf_admin.php»

We'll start by adding a group, then updating it. We can then list all groups in the table before deleting a group

Here is the full example :

Download «LUA_test_group.php»

Add a Group (addGroup)

function addGroup($data)

Parameter(s)

This method takes 1 parameter:

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

In the easiest way, you may just provide the group name. In this case, the method will automatically allocate an group id (using the «liveuser_groups_seq» table).

Otherwise, you may provide the group name and the group id.

Return value

This method returns:

  • «false» in case of error
  • the new group id in case of success

Example

To add a group name:

Code
   ...
    $group_name = 'A group';
    $data = array('group_define_name' => $group_name);
    $groupId = $LUA->perm->addGroup($data);
   ...

To add a group name and a group id

Code
   ...
    $group_id = 5;
    $group_name = 'A group';
    $data = array('group_id' => $group_id,
                  'group_define_name' => $group_name);
    $groupId = $LUA->perm->addGroup($data);
   ...

This gives the following result:

Add a group

Update a Group (updateGroup)

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

Attention: if no parameter is passed, all groups will be modified.

Return value

This method returns:

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

Example

Code
   ...
    $new_group_name = 'Another group';
    $group_id = 5;
    $data = array('group_define_name' => $new_group_name);
    $filters = array('group_id' => $group_id);
    $updateGroup = $LUA->perm->updateGroup($data, $filters);
   ...

This gives the following result:

Update a group

List Groups (getGroups)

function getGroups($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 groups:

Code
   ...
    $groups = $LUA->perm->getGroups();
   ...

This gives the following result:

Get all groups

Get a filtered list of groups:

Code
   ...
    $group_id = 5;
    $filter = array('filters' => array('group_id' => $group_id));
    $groups = $LUA->perm->getGroups($filter);
   ...

This gives the following result:

Get all groups

Remove a Group (removeGroup)

function removeGroup($filters)

All associated sub-groups 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 groups will be removed.

Return value

This method returns:

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

Example

Code
   ...
    $group_id = 5;
    $filter = array('group_id' => $group_id);
    $removed = $LUA->perm->removeGroup($filter);
   ...

This gives the following result:

Remove a group

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
   ...
    $data = array('group_id' => $group_id,
                  'group_define_name' => $group_name);
    $groupId = $LUA->perm->addGroup($data);

    if ($groupId == false)
      {
      echo 'Add_group: error on line: '.__LINE__;
      print_r($LUA->getErrors());
      }
    else
      {
      echo 'Group with id ' . $groupId . ' created';
      }
   ...

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