Development Guide

Listening To Events

This documentation is only relevant for IILIAS 4.3.x and above. This is a work in progress.

Several modules and services in ILIAS raise events. This is mainly done to enable decoupling of components. As a component does not need to know about every dependent service or module it just notifies the event handler about a new event and the handler in turn alerts the registered listeners.
 
The typical scenarios of events are:

  • decoupling of dependent components
  • propagation of events in hierarchical structures
  • separation of generic and specific data types

To register a component as a listener for an event add the following code to your service.xml or module.xml:

1
2
3
4
5
6
7
8
<?php xml version = "1.0" encoding = "UTF-8"?>
<module ...>
...
<events>
<event type="listen" id="Services/Tracking" />
</events>
...
</module>

The example above will register a module for all events issued by Services/Tracking.
 
There is currently no way to register for certain events of a component only, this has to be done in your EventListener class.

If necessary you can set the id of the component to register manually:

1
2
3
4
5
6
7
8
<?php xml version = "1.0" encoding = "UTF-8"?>
<module ...>
...
<events>
<event type="listen" id="Services/Tracking" component="Module/Course" />
</events>
...
</module>

To process events add the following class to your module or service in a file called class.il<Module>AppEventListener.php:

1
2
3
4
5
6
7
8
9
10
11
<?php

class il<Module>AppEventListener
{
static function handleEvent($a_component, $a_event, $a_parameter)
{
...
}
}

?>

Implement the method handleEvent to your liking. All necessary information of the event should be available in $a_parameter. Please do not forget to check $a_component and $a_event if they have the correct values for your purpose.

All supported events can be found in table il_event_handling.

As event handling is part of the application layer, please do not issue redirects or error messages. As return values are ignored you should use log entries if needed.