ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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

 $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 56 of file class.ilAppEventHandler.php.

Constructor & Destructor Documentation

◆ __construct()

ilAppEventHandler::__construct ( )

Constructor.

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

64 {
65 $this->initListeners();
66 }

References initListeners().

+ Here is the call graph for this function:

Member Function Documentation

◆ initListeners()

ilAppEventHandler::initListeners ( )
protected

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

69 {
70 require_once('./Services/GlobalCache/classes/class.ilGlobalCache.php');
72 $cached_listeners = $ilGlobalCache->get('listeners');
73 if (is_array($cached_listeners)) {
74 $this->listener = $cached_listeners;
75
76 return;
77 }
78
79 global $ilDB;
80
81 $this->listener = array();
82
83 $sql = "SELECT * FROM il_event_handling".
84 " WHERE type = ".$ilDB->quote("listen", "text");
85 $res = $ilDB->query($sql);
86 while($row = $ilDB->fetchAssoc($res))
87 {
88 $this->listener[$row["id"]][] = $row["component"];
89 }
90
91 $ilGlobalCache->set('listeners', $this->listener);
92 }
static getInstance($component)
global $ilDB

References $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 103 of file class.ilAppEventHandler.php.

104 {
105 if (is_array($this->listener[$a_component]))
106 {
107 foreach ($this->listener[$a_component] as $listener)
108 {
109 // Allow listeners like Services/WebServices/ECS
110 $last_slash = strripos($listener,'/');
111 $comp = substr($listener,0,$last_slash);
112 $class = 'il'.substr($listener,$last_slash + 1).'AppEventListener';
113 $file = "./".$listener."/classes/class.".$class.".php";
114
115 // detemine class and file
116 #$comp = explode("/", $listener);
117 #$class = "il".$comp[1]."AppEventListener";
118 #$file = "./".$listener."/classes/class.".$class.".php";
119
120 // if file exists, call listener
121 if (is_file($file))
122 {
123 include_once($file);
124 call_user_func(array($class, 'handleEvent'), $a_component, $a_event, $a_parameter);
125 }
126 }
127 }
128
129 // get all event hook plugins and forward the event to them
130 include_once("./Services/Component/classes/class.ilPluginAdmin.php");
131 $plugins = ilPluginAdmin::getActivePluginsForSlot("Services", "EventHandling", "evhk");
132 foreach ($plugins as $pl)
133 {
134 $plugin = ilPluginAdmin::getPluginObject("Services", "EventHandling",
135 "evhk", $pl);
136 $plugin->handleEvent($a_component, $a_event, $a_parameter);
137 }
138
139 }
print $file
static getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get Plugin Object.
getActivePluginsForSlot($a_ctype, $a_cname, $a_slot_id)
Get all active plugins for a slot.

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

+ Here is the call graph for this function:

Field Documentation

◆ $listener

ilAppEventHandler::$listener
protected

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

Referenced by raise().


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