This manual is deprecated. Please visit https://groupoffice.readthedocs.io for the latest documentation.

Event handling

From Group-Office Groupware and CRM Documentation
Revision as of 14:22, 25 March 2009 by Admin (Talk | contribs)

Jump to: navigation, search

Group-Office modules can interact with eachother with event handling. For example you might want to do something in a custom module when a particular thing happens in another module.

Some practical examples:

  1. The IMAP authentication module checks access when a user logs in.
  2. When an order status changes in the webshop of group-office.com, an event handler enables the download for the customer
  3. When a password is change in Group-Office. A system account can be updated.
  4. etc.

How does it work? I'll explain the IMAP authentication example.

When a user logs in, an event is fired in classes/base/auth.class.inc.php:

$GO_EVENTS->fire_event('before_login', array($username, $password));

The event 'before_login' is fired and event listeners functions are called with the parameters $username and $password

Adding event listeners

To do something you must add event listeners. You can do this in a special function that must be in the file "module/<module_id>/classes/<module_id>.class.inc.php". At login time this function is called and you can add the listeners. Listeners are static functions.

The add_listener function takes four arguments:

  1. Event name
  2. The class file where the function is in
  3. The class name where the function is in
  4. The class method to call statically

In the following code we add a listener for the "before_login" event.

class imapauth
{
	var $config;
	
	public function __on_load_listeners($events){
		$events->add_listener('before_login', __FILE__, 'imapauth', 'before_login');
	}

	public static function before_login($username, $password)
	{
	
	...

	}
}

So now just before a user is loggin in this function is called. The function connects to the IMAP server using the supplied password. If it succeeds it will add a user account and e-mail account or update the password if necessary.

The same could be done with any application/protocol like Joomla, PhpBB, LDAP etc. You'll just have to write it!


Defined events

Module Event name Parameters Description
Framework before_login username, password Fires just before a user logins. Useful for authentication bridges.
Framework update_user user: array with all db fields Fires when a user is updated.
Framework before_add_user user: array with all db fields Fires just before a user is added.
Framework add_user user: array with all db fields Fires after a user is added.
Framework user_delete user: array with all db fields Fires after a user is deleted.
Framework install_module module: array with module db fields Fires when a module is installed. Eg. You could enable extra functionality in another module when a module is installed
Framework save_settings None, but you can use the $_POST array. Fires when a the user settings are updated. Each module can add it's own panels to the settings dialog. Through this event you can update the module settings.
Framework load_settings response: The JSON response to the client. Useful for adding settings to the array. Fires when a the user settings are loaded. Each module can add it's own panels to the settings dialog. Through this event you can update the module settings.
Framework reminder_dismissed reminder: array with reminder db fields Fires when a reminder is dismised. Eg. When a reminder of a recurring event is dismissed, a new reminder is created for the next occurrence.
Tools check_database none Perform a database check on your module.
Billing order_status_change order, new_status, old_status Fires when an order changes to another status