Interface to manage LiveUser filters

The LiveUser_Admin package allows you to extract the list of applications, areas, rights, etc. with a series of «get...» methods: getApplications, getAreas, getRights, etc.

While using the «get...» methods, a series of options and filters are available:

For each parameter examined hereafter, we will first see the result of the «get...» without the parameter. Then we will then examine the impact of the parameter in one or more additional example(s).

Here is the full example :

Download «LUA_test_filters.php»

Select fields to be displayed in the query results (fields)

The parameter fields is an array containing all fields to be part of the query results. It corresponds to the list of fields in the SELECT clause of an SQL query.

If this parameter is not set, you'll get all fields from the 1st table specified in the selectable_tables property:

  • getUsers: liveuser_perm_users
  • getRights: liveuser_rights
  • getAreas: liveuser_areas
  • getApplications: liveuser_applications
  • getTranslations: liveuser_translations
  • getGroups: liveuser_groups

Example 1

Code
   ...
    echo 'List of all areas - No parameter';
    $groups = $LUA->perm->getAreas();
   ...

When you request the list of all areas using the getAreas method with no parameters, you will have all fields of the «liveuser_areas» table:

  • area_id
  • application_id
  • area_define_name

This gives the following result:

No parameter for the 'get...' methods

Example 2

If you are only interested in the «area_id» and the «area_define_name» fields, use the fields parameter:

Code
   ...
    echo 'List of all areas - Only fewer fields';
    $params = array('fields' => array('area_id', 'area_define_name'));
    \areas = $LUA->perm->getAreas($params);
   ...

This gives the following result:

Fields parameter - fewer fields

Example 3

If at the opposite, you are interested in fields logically related to areas but located in linked tables, you can extend your selection. You know that the «liveuser_translations» table may contain translations of areas names. So to retrieve the «description» field of the «liveuser_translations» table:

Code
   ...
    echo 'List of all areas - Additional fields';
    $params = array('fields' => array('area_id', 'area_define_name', 'description'));
    \areas = $LUA->perm->getAreas($params);
   ...

Fields parameter - Additional fields

selectable_tables

However, to have your selection working properly, you'll have to keep in mind the permission level used (simple, medium or complex) and the corresponding value of the selectable_tables property:

Simple Level of permission management

  • getUsers: liveuser_perm_users, liveuser_userrights, liveuser_rights
  • getRights: liveuser_rights, liveuser_userrights, liveuser_areas, liveuser_applications, liveuser_translations
  • getAreas: liveuser_areas, liveuser_applications, liveuser_translations
  • getApplications: liveuser_applications, liveuser_translations
  • getTranslations: liveuser_translations

Medium Level of permission management

  • getUsers: liveuser_perm_users, liveuser_userrights, liveuser_rights, liveuser_groupusers
  • getGroups: liveuser_groups, liveuser_groupusers, liveuser_grouprights, liveuser_rights
  • getRights: liveuser_rights, liveuser_userrights, liveuser_areas, liveuser_applications, liveuser_translations
  • getAreas: liveuser_areas, liveuser_applications, liveuser_translations
  • getApplications: liveuser_applications, liveuser_translations
  • getTranslations: liveuser_translations

Complex Level of permission management

  • getUsers: liveuser_perm_users, liveuser_userrights, liveuser_rights, liveuser_groupusers
  • getGroups: liveuser_groups, liveuser_groupusers, liveuser_grouprights, liveuser_rights, liveuser_group_subgroups
  • getRights: liveuser_rights, liveuser_userrights, liveuser_areas, liveuser_applications, liveuser_translations, liveuser_right_implied
  • getAreas: liveuser_areas, liveuser_applications, liveuser_translations, liveuser_area_admin_areas
  • getApplications: liveuser_applications, liveuser_translations
  • getTranslations: liveuser_translations

Select records (filters)

The parameter «filter» is an array containing all search criteria. It corresponds to the WHERE clause of an SQL query.

If this parameter is not set, all records will be retrieved.

Note: the field names specified in the «filters» parameter affect the tables used in the JOIN.

Example 1

Code
   ...
    echo 'List of all groups - No parameter';
    $groups = $LUA->perm->getGroups();
   ...

When you request the list of all groups using the getGroups method with no parameters, you will have all fields of the «liveuser_groups» table.

This gives the following result:

No parameter for the 'get...' methods

Example 2

If you only need the record with group_id = 1, use the filter parameter:

Code
   ...
    echo 'List of all groups - only group_id=1';
    $params = array('filters' => array('group_id' => 1));
    $groups = $LUA->perm->getGroups($params);
   ...

This gives the following result:

Filter parameter - 1 criterion

Example 3

In your search criterion, you want to select records having a NULL value:

Code
   ...
    echo 'List of all groups - where owner_user_id is NULL';
    $params = array('filters' => array('owner_user_id' => NULL));
    $groups = $LUA->perm->getGroups($params);
   ...

This gives the following result:

Filter parameter - Filter on NULL value

Example 4

This example retrieves all records where the group_in is 1, 2 or 9

Code
   ...
    echo 'List of all groups - group_id IN (1, 2, 9)';
    $params = array('filters' => array('group_id' => array(1, 2, 9)));
    $groups = $LUA->perm->getGroups($params);
   ...

This gives the following result:

Filter parameter - group_id IN (1,2,9)

Example 5

This example retrieves all records where the group_in is not equal to 9

Code
   ...
    echo 'List of all groups - group_id not equal to 9';
    $params = array('filters' => array('group_id' => array('value' => 9, 'op' => '!=')));
    $groups = $LUA->perm->getGroups($params);
   ...

This gives the following result:

Filter parameter - group_id not equal to 9

The following operators are available:

  • =
  • !=
  • >
  • >=
  • <
  • <=

Sort records on some fields in ascending or descending order (orders)

The parameter orders is an array containing information on sorting data: field name(s) and sorting order (ascending or descending). This corresponds to the ORDER BY clause and the ASC/DESC keyword of a SQL query.

If this parameter is not set, records will be retrieved in no specific order.

Note: the field names specified in the «orders» parameter affect the tables used in the JOIN.

Example 1

Code
   ...
    echo 'List of all groups - No parameter';
    $groups = $LUA->perm->getGroups();
   ...

When you request the list of all groups using the getGroups method with no parameters, you will have all fields of the «liveuser_groups» table.

This gives the following result:

No parameter for the 'get...' methods

Example 2

This example retrieves all groups. Records are sorted in ascending order on group_define_name.

Code
   ...
    echo 'List of all groups - Ascending order on group_define_name';
    $params = array('orders' => array('group_define_name' => 'ASC'));
    $groups = $LUA->perm->getGroups();
   ...

This gives the following result:

Groups in ascending order on group_define_name

Example 3

This example retrieves all groups. Records are sorted in descending order on group_define_name.

Code
   ...
    echo 'List of all groups - Descending order on group_define_name';
    $params = array('orders' => array('group_define_name' => 'DESC'));
    $groups = $LUA->perm->getGroups();
   ...

This gives the following result:

Groups in descending order on group_define_name

Get additional information from another table (with)

The parameter with is an array containing the kind of additional information you want.

It will first do the main «get...» call. For each record of the result, it does a 2nd «get...» call based on the field specified in the «with» parameter.

Example 1

Code
   ...
    echo 'List of all users - Only 3 fields';
    $params = array('fields' => array('perm_user_id',
                                      'auth_user_id',
                                      'group_id'));
    $users = $LUA->perm->getUsers($params);
   ...

This gives the following result:

No parameter for the 'get...' methods

Example 2

This example retrieves all users. The 3 requested fields are displayed. Then for each user, another call is done to get all related group information. If needed, you may also specify admin filters for this second call ($with_params variable in this example).

Make sure the field name given for the «groups» parameter is also included in the «fields» parameter list.

Code
   ...
    echo 'List of all users - 3 fields and the With parameter';
    $with_params = '';
    $params = array('fields' => array('perm_user_id',
                                      'auth_user_id',
                                      'group_id'),
                    'with' => array('group_id'=> $with_params));
    $users = $LUA->perm->getUsers($params);
   ...

This gives the following result:

Only the 1st column

Get only a column or a row or both (select)

The parameter select is an array containing the kind of selection you want.

If this parameter is not set, all columns and all rows will be retrieved.

Example 1

Code
   ...
    echo 'List of all groups - No parameter';
    $groups = $LUA->perm->getGroups();
   ...

When you request the list of all groups using the getGroups method with no parameters, you will have all fields of the «liveuser_groups» table.

This gives the following result:

No parameter for the 'get...' methods

Example 2

This example retrieves all groups but gets only the 1st column of data, i.e. the group_id.

Code
   ...
    echo 'List of all groups - only the 1st column';
    $params = array ('select' => 'col');
    $groups = $LUA->perm->getGroups($params);
   ...

This gives the following result:

Only the 1st column

Example 3

This example retrieves all groups but gets only the 1st row of data, i.e. the 1st record.

Code
   ...
    echo 'List of all groups - only the 1st row';
    $params = array ('select' => 'row');
    $groups = $LUA->perm->getGroups($params);
   ...

This gives the following result:

Only the 1st row

Example 4

This example retrieves all groups but gets only the 1st column of the 1st row of data. Instead of an array, you only get a scalar value.

Code
   ...
    echo 'List of all groups - 1st column of 1st row';
    $params = array ('select' => 'one');
    $groups = $LUA->perm->getGroups($params);
   ...

This gives the following result:

Only the 1st column of the 1st row

Use the 1st column of the result as key (rekey)

The parameter rekey may be set to true or false.

By default, it is set to false. In this case, the resulting array contains a key with an incremental number.

If this parameter is set to true, the key contains the data of the 1st column.

Example 1

Code
   ...
    echo 'List of all groups - No parameter';
    $groups = $LUA->perm->getGroups();
   ...

When you request the list of all groups using the getGroups method with no parameters, you will have all fields of the «liveuser_groups» table.

This gives the following result:

No parameter for the 'get...' methods

Example 2

With this example, you get the 1st column of data (i.e. the group_id) in the key of the resulting array.

Code
   ...
    echo 'List of all groups - 1st column of data as key';
    $params = array('rekey' => true);
    $groups = $LUA->perm->getGroups($params);
   ...

This gives the following result:

The 1st column as the key

Use the 1st column of the result as key and group them (group)

The parameter group may be set to true or false. By default, it is set to false.

If this parameter is set to true, all records with the same value in the key are grouped in an array. It is to be used with the «rekey» parameter.

Example 1

We start by catching 2 fields about the users: the 'perm_user_id' and the 'group_id'.

Code
   ...
    echo 'List of all users - 2 fields';
    $params = array('fields' => array('perm_user_id', 'group_id'));
    $users = $LUA->perm->getUsers($params);
   ...

This gives the following result:

All users - 3 fields

Example 2

In this second version, the «rekey» parameter is introduced.

Code
   ...
    echo 'List of all users - 1st column of data as key';
    $params = array('fields' => array('perm_user_id', 'group_id'),
                    'rekey' => true);
    $users = $LUA->perm->getUsers($params);
   ...

This gives the following result:

The 1st column as the key

Example 3

Now the «group» parameter is added. All records having the same group_id are regrouped in an array.

Code
   ...
    echo 'List of all users - 1st column of data as key and grouped';
    $params = array('fields' => array('perm_user_id', 'group_id'),
                    'rekey' => true,
                    'group' => true);
    $users = $LUA->perm->getUsers($params);
   ...

This gives the following result:

The 1st column as the key

Limit the result to a certain number of records (limit)

The parameter limit may be set to the number of records to retrieve. It corresponds to part of the LIMIT clause in a SQL query.

Example 1

Code
   ...
    echo 'List of all groups - No parameter';
    $groups = $LUA->perm->getGroups();
   ...

When you request the list of all groups using the getGroups method with no parameters, you will have all fields of the «liveuser_groups» table.

This gives the following result:

No parameter for the 'get...' methods

Example 2

With this example, you get the 1st column of data (i.e. the group_id) in the key of the resulting array.

Code
   ...
    echo 'List of all groups - Limited to 3 records';
    $params = array('limit' => 3);
    $groups = $LUA->perm->getGroups($params);
   ...

This gives the following result:

Only 3 records

Get records starting at record #xxx (offset)

The parameter offset may be set to the number of records to skip. It corresponds to part of the LIMIT clause in a SQL query.

Example 1

Code
   ...
    echo 'List of all groups - No parameter';
    $groups = $LUA->perm->getGroups();
   ...

When you request the list of all groups using the getGroups method with no parameters, you will have all fields of the «liveuser_groups» table.

This gives the following result:

No parameter for the 'get...' methods

Example 2

With this example, the first 4 records will be skipped. Then we'll take the next 3 records.

Code
   ...
    echo 'List of all groups - Limited to 3 records starting with record #5';
    $params = array('limit' => 3,
                    'offset' => 4);
    $groups = $LUA->perm->getGroups($params);
   ...

This gives the following result:

Only 3 records starting with record nr 5

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