ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilAppEventHandler.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once './Services/WorkflowEngine/classes/class.ilWorkflowEngine.php';
25 
59 {
63  protected $db;
64 
65  protected $listener; // [array]
66 
70  public function __construct()
71  {
72  global $DIC;
73 
74  $this->db = $DIC->database();
75  $this->initListeners();
76  }
77 
78  protected function initListeners()
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 
89  $ilDB = $this->db;
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  }
102 
103 
104 
112  public function raise($a_component, $a_event, $a_parameter = "")
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  }
165 }
Global event handler.
static getActivePluginsForSlot($a_ctype, $a_cname, $a_slot_id)
Get all active plugins for a slot.
global $DIC
Definition: saml.php:7
static getInstance($component)
static getActivePlugins()
Get info for all active plugins.
if($format !==null) $name
Definition: metadata.php:146
ilWorkflowEngine is part of the petri net based workflow engine.
foreach($_POST as $key=> $value) $res
static getPluginObject($a_ctype, $a_cname, $a_slot_id, $a_pname)
Get Plugin Object.
Create styles array
The data for the language used.
global $ilDB
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file