Interface to manage LiveUser areas

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

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

There are a few methods for areas management:

  • addArea: to add an area to the list of areas
  • updateArea: to modify an area in the list of areas
  • removeArea: to remove an area from the list of areas
  • getAreas: to retrieve a list of areas

We'll start by adding an area, then updating it. We can then list all areas in the table before deleting an area.

Here is the full example :

Download «LUA_test_area.php»

Add an Area (addArea)

function addArea($data)

Parameter(s)

This method takes 1 parameter:

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

In the easiest way, you may just provide the area name and the application id it is related to. In this case, the method will automatically allocate an area id (using the «liveuser_areas_seq» table).

Otherwise, you may provide the area name, the area id and the application id it is related to.

Return value

This method returns:

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

Example

To add an area name:

Code
   ...
    $data = array('application_id' => $application_id,
                  'area_define_name' => $area_name);
    $areaId = $LUA->perm->addArea($data);
   ...

To add an area name and an area id

Code
   ...
    $data = array('application_id' => $application_id,
                  'area_id' => $area_id,
                  'area_define_name' => $area_name);
    $areaId = $LUA->perm->addArea($data);
   ...

This gives the following result:

Add an Area

Update an Area (updateArea)

function updateArea($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 areas will be modified.

Return value

This method returns:

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

Example

Code
   ...
    $new_area_name = 'Another area';
    $area_id = 5;
    $data = array('area_define_name' => $new_area_name);
    $filter = array('area_id' => $area_id);
    $updateArea = $LUA->perm->updateArea($data, $filter);
   ...

This gives the following result:

Update an Area

List Areas (getAreas)

function getAreas($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 areas:

Code
   ...
    $areas = $LUA->perm->getAreas();
   ...

Get a filtered list of areas:

Code
   ...
    $area_id = 5;
    $filter = array('filters' => array('area_id' => $area_id));
    $areas = $LUA->perm->getAreas($filter);
   ...

This gives the following result:

Get an Area

Remove an Area (removeArea)

function removeArea($filter)

This method will remove the area and all associated rights. All area admin for this area are removed 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 areas will be removed.

Return value

This method returns:

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

Example

Code
   ...
    $area_id = 5;
    $filter = array('area_id' => $area_id);
    $removeArea = $LUA->perm->removeArea($filter);
   ...

This gives the following result:

Remove an Area

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('application_id' => $application_id,
                  'area_id' => $area_id,
                  'area_define_name' => $area_name);
    $areaId = $LUA->perm->addArea($data);

    if ($areaId == false)
      {
      echo 'Add_area: error on line: '.__LINE__;
      print_r($LUA->getErrors());
      }
    else
      {
      echo 'Area with id ' . $areaId . ' 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