ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
57 {
58  protected $listener; // [array]
59 
63  public function __construct()
64  {
65  $this->initListeners();
66  }
67 
68  protected function initListeners()
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  }
93 
94 
95 
103  function raise($a_component, $a_event, $a_parameter = "")
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  }
140 }
141 ?>