ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 58 of file class.ilAppEventHandler.php.

Constructor & Destructor Documentation

◆ __construct()

ilAppEventHandler::__construct ( )

Constructor.

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

References initListeners().

66  {
67  $this->initListeners();
68  }
+ Here is the call graph for this function:

Member Function Documentation

◆ initListeners()

ilAppEventHandler::initListeners ( )
protected

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

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

Referenced by __construct().

71  {
72  require_once('./Services/GlobalCache/classes/class.ilGlobalCache.php');
74  $cached_listeners = $ilGlobalCache->get('listeners');
75  if (is_array($cached_listeners)) {
76  $this->listener = $cached_listeners;
77 
78  return;
79  }
80 
81  global $ilDB;
82 
83  $this->listener = array();
84 
85  $sql = "SELECT * FROM il_event_handling".
86  " WHERE type = ".$ilDB->quote("listen", "text");
87  $res = $ilDB->query($sql);
88  while($row = $ilDB->fetchAssoc($res))
89  {
90  $this->listener[$row["id"]][] = $row["component"];
91  }
92 
93  $ilGlobalCache->set('listeners', $this->listener);
94  }
static getInstance($component)
Create styles array
The data for the language used.
global $ilDB
+ 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 105 of file class.ilAppEventHandler.php.

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

106  {
107  if (is_array($this->listener[$a_component]))
108  {
109  foreach ($this->listener[$a_component] as $listener)
110  {
111  // Allow listeners like Services/WebServices/ECS
112  $last_slash = strripos($listener,'/');
113  $comp = substr($listener,0,$last_slash);
114  $class = 'il'.substr($listener,$last_slash + 1).'AppEventListener';
115  $file = "./".$listener."/classes/class.".$class.".php";
116 
117  // detemine class and file
118  #$comp = explode("/", $listener);
119  #$class = "il".$comp[1]."AppEventListener";
120  #$file = "./".$listener."/classes/class.".$class.".php";
121 
122  // if file exists, call listener
123  if (is_file($file))
124  {
125  include_once($file);
126  call_user_func(array($class, 'handleEvent'), $a_component, $a_event, $a_parameter);
127  }
128  }
129  }
130 
131  // get all event hook plugins and forward the event to them
132  include_once("./Services/Component/classes/class.ilPluginAdmin.php");
133  $plugins = ilPluginAdmin::getActivePluginsForSlot("Services", "EventHandling", "evhk");
134  foreach ($plugins as $pl)
135  {
136  $plugin = ilPluginAdmin::getPluginObject("Services", "EventHandling",
137  "evhk", $pl);
138  $plugin->handleEvent($a_component, $a_event, $a_parameter);
139  }
140 
141  $workflow_engine = new ilWorkflowEngine(false);
142  $workflow_engine->handleEvent($a_component, $a_event, $a_parameter);
143  }
static getActivePluginsForSlot($a_ctype, $a_cname, $a_slot_id)
Get all active plugins for a slot.
ilWorkflowEngine is part of the petri net based workflow engine.
static getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get Plugin Object.
Create styles array
The data for the language used.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the call graph for this function:

Field Documentation

◆ $listener

ilAppEventHandler::$listener
protected

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

Referenced by raise().


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