User Manager Hooking and Functions

 

The User Manager module houses all Users that are not part of device/user mode but are still linked to extensions. These users are used around FreePBX to get or set data. They are used in iSymphony, User Control Panel, XMPP and RestAPI but any module can be extended to utilized Users without revealing any compromising information.

 

 

First Steps

Inside any module simply these lines of code to be able to utilize User Manager Functions:

if(function_exists('setup_userman')){     $userman = setup_userman();

The setup_userman() function returns a static object, so it can be called more than once without having to worry about class reconstruction. You can also use the above code to detect if User Manager support is available in your instance.

GUI Hooks

This function will allow you to put html code into the user manager page. When the page has submitted this function will also be executed so as to pass any submitted data to it.

function <modulerawname>_hook_userman() {     return 'foo' }

Hooking Functions

Hooking functions are calls that User Manager makes when users are added or removed from either the User Manager configuration page or from the Extensions page, they are also called when user settings are changed/updated from within User Manager.

These must be placed inside of functions.inc.php to do anything useful

Add Hook

This hook is called when a user is added, either through the Device/Users, Extensions or User Manager Page

setup_userman()->registerHook('addUser','myFunctionName'); /**  * @param int $id The User Manager ID  * @param string $display The page in FreePBX that initiated this function  * @param array $data an array of all relevant data returned from User Manager  * @return bool  */ myFunctionName($id,$display,$data) {}

Update Hook

This hook is called when a user is updated. Usually through the User manager page, however it can happen where a default extension is redefined through the Device/Users or Extensions page

Delete Hook

This hook is called when a user is deleted. The most useful data returned from here is $id, since User Manager deletes the user and relevant attached data prior to this you don't have to do anything if you stored all of your module's data inside of User Manager

User Manager Global Functions

Get All Users

This function will get all users and their information (top level data only). It will return false if no users can be found

Get User By Default Extension

This function will get user information (top level data only) by which user has said extension or user (device/user mode) assigned as it's default. It will return false if no user can be found

Get User By Username

This function will get user information by username. It will return false if no user can be found

Get User By User ID

This function will get user information by the User Manager User ID. It will return false if no user can be found

Get Assigned Devices By User ID

Get all the devices (Extensions or (device/user mode) Users) that are attached to this User Manager User

Set Assigned Devices By User ID

Set all the devices (Extensions or (device/user mode) Users) that are attached to this User Manager User

Get All Global Settings By User ID

Gets all global settings by User 

Get A Single Global Setting By User ID

Get a single global setting by User 

Set A Single Global Setting By User ID

Set a single global setting by User 

Get All Defined Sub Settings by Module Name and User ID

Get All Defined Sub Settings by Module Name

Get a single setting from a User by Module and User ID

Gets a single Module Defined Sub Setting

Set a Module Sub Setting by Module and User ID

Sets a Module Defined Sub Setting

Return to Documentation Home I Return to Sangoma Support