ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilAppEventHandler Class Reference

Global event handler. More...

+ Collaboration diagram for ilAppEventHandler:

Public Member Functions

 __construct ()
 Constructor. More...
 
 raise ($a_component, $a_event, $a_parameter="")
 Raise an event. More...
 

Protected Member Functions

 initListeners ()
 

Protected Attributes

 $db
 
 $listener
 

Detailed Description

Global event handler.

The event handler delegates application events (not gui events) between components that trigger events and components that listen to events. A component is a module or a service.

The component that triggers an event calls the raise function of the event handler through the global instance ilAppEventHandler:

E.g. in ilObjUser->delete(): $ilAppEventHandler->raise("Services/User", "deleteUser", array("id" => ..., ...))

A listener has to subscribe to the events of another component. This currently is done here in the constructor, e.g. if the News service listens to the User service, add a $this->listener["Services/User"] = array("Services/News"); This information will go to xml files in the future.

A component has to implement a listener class that implements Services/EventHandling/interfaces/interface.ilAppEventListener.php

The location must be <component>/classes/class.il<comp_name>AppEventListener.php, e.g. ./Services/News/classes/class.ilNewsAppEventListener.php

The class name must be il<comp_name>AppEventListener.

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Version
$Id$

Definition at line 58 of file class.ilAppEventHandler.php.

Constructor & Destructor Documentation

◆ __construct()

ilAppEventHandler::__construct ( )

Constructor.

Definition at line 70 of file class.ilAppEventHandler.php.

71 {
72 global $DIC;
73
74 $this->db = $DIC->database();
75 $this->initListeners();
76 }
global $DIC
Definition: saml.php:7

References $DIC, and initListeners().

+ Here is the call graph for this function:

Member Function Documentation

◆ initListeners()

ilAppEventHandler::initListeners ( )
protected

Definition at line 78 of file class.ilAppEventHandler.php.

79 {
80 require_once('./Services/GlobalCache/classes/class.ilGlobalCache.php');
82 $cached_listeners = $ilGlobalCache->get('listeners');
83 if (is_array($cached_listeners)) {
84 $this->listener = $cached_listeners;
85
86 return;
87 }
88
90
91 $this->listener = array();
92
93 $sql = "SELECT * FROM il_event_handling" .
94 " WHERE type = " . $ilDB->quote("listen", "text");
95 $res = $ilDB->query($sql);
96 while ($row = $ilDB->fetchAssoc($res)) {
97 $this->listener[$row["id"]][] = $row["component"];
98 }
99
100 $ilGlobalCache->set('listeners', $this->listener);
101 }
static getInstance($component)
foreach($_POST as $key=> $value) $res
global $ilDB

References $db, $ilDB, $res, $row, ilGlobalCache\COMP_EVENTS, and ilGlobalCache\getInstance().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ raise()

ilAppEventHandler::raise (   $a_component,
  $a_event,
  $a_parameter = "" 
)

Raise an event.

The event is passed to all interested listeners.

Parameters
string$a_componentcomponent, e.g. "Modules/Forum" or "Services/User"
string$a_eventevent e.g. "createUser", "updateUser", "deleteUser", ...
array$a_parameterparameter array (assoc), array("name" => ..., "phone_office" => ...)

Definition at line 112 of file class.ilAppEventHandler.php.

113 {
114 if (is_array($this->listener[$a_component])) {
115 foreach ($this->listener[$a_component] as $listener) {
116 // Allow listeners like Services/WebServices/ECS
117 $last_slash = strripos($listener, '/');
118 $comp = substr($listener, 0, $last_slash);
119
120 // any kind of plugins with events in their plugin.xml
121 if ($comp == 'Plugins') {
122 $name = substr($listener, $last_slash + 1);
123
124 foreach (ilPluginAdmin::getActivePlugins() as $pdata) {
125 if ($pdata['name'] == $name) {
127 $pdata['component_type'],
128 $pdata['component_name'],
129 $pdata['slot_id'],
130 $pdata['name']
131 );
132
133 $plugin->handleEvent($a_component, $a_event, $a_parameter);
134 }
135 }
136 } else {
137 $class = 'il' . substr($listener, $last_slash + 1) . 'AppEventListener';
138 $file = "./" . $listener . "/classes/class." . $class . ".php";
139
140 // if file exists, call listener
141 if (is_file($file)) {
142 include_once($file);
143 call_user_func(array($class, 'handleEvent'), $a_component, $a_event, $a_parameter);
144 }
145 }
146 }
147 }
148
149 // get all event hook plugins and forward the event to them
150 include_once("./Services/Component/classes/class.ilPluginAdmin.php");
151 $plugins = ilPluginAdmin::getActivePluginsForSlot("Services", "EventHandling", "evhk");
152 foreach ($plugins as $pl) {
154 "Services",
155 "EventHandling",
156 "evhk",
157 $pl
158 );
159 $plugin->handleEvent($a_component, $a_event, $a_parameter);
160 }
161
162 $workflow_engine = new ilWorkflowEngine(false);
163 $workflow_engine->handleEvent($a_component, $a_event, $a_parameter);
164 }
static getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get Plugin Object.
static getActivePluginsForSlot($a_ctype, $a_cname, $a_slot_id)
Get all active plugins for a slot.
static getActivePlugins()
Get info for all active plugins.
ilWorkflowEngine is part of the petri net based workflow engine.
if($format !==null) $name
Definition: metadata.php:146
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file

References $file, $listener, $name, ilPluginAdmin\getActivePlugins(), ilPluginAdmin\getActivePluginsForSlot(), and ilPluginAdmin\getPluginObject().

+ Here is the call graph for this function:

Field Documentation

◆ $db

ilAppEventHandler::$db
protected

Definition at line 63 of file class.ilAppEventHandler.php.

Referenced by initListeners().

◆ $listener

ilAppEventHandler::$listener
protected

Definition at line 65 of file class.ilAppEventHandler.php.

Referenced by raise().


The documentation for this class was generated from the following file: