ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilPluginSlot.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
5 include_once("./Services/Component/classes/class.ilPlugin.php");
6 
20 {
21 
25  public function __construct($a_c_type, $a_c_name, $a_slot_id)
26  {
27  $this->setComponentType($a_c_type);
28  $this->setComponentName($a_c_name);
29  $this->setSlotId($a_slot_id);
30 
31  if ($a_slot_id != "") {
32  $this->read();
33  }
34  }
35 
39  public function read()
40  {
41  $cached_component = ilCachedComponentData::getInstance();
42  $rec = $cached_component->lookupPluginSlotById($this->getSlotId());
43  $this->setSlotName($rec["name"]);
44  }
45 
51  public function setComponentType($a_componenttype)
52  {
53  $this->componenttype = $a_componenttype;
54  }
55 
61  public function getComponentType()
62  {
63  return $this->componenttype;
64  }
65 
71  public function setComponentName($a_componentname)
72  {
73  $this->componentname = $a_componentname;
74  }
75 
81  public function getComponentName()
82  {
83  return $this->componentname;
84  }
85 
91  public function setSlotId($a_slotid)
92  {
93  $this->slotid = $a_slotid;
94  }
95 
101  public function getSlotId()
102  {
103  return $this->slotid;
104  }
105 
111  public function setSlotName($a_slotname)
112  {
113  $this->slotname = $a_slotname;
114  }
115 
121  public function getSlotName()
122  {
123  return $this->slotname;
124  }
125 
129  public function getPluginsDirectory()
130  {
131  return "./Customizing/global/plugins/" . $this->getComponentType() .
132  "/" . $this->getComponentName() . "/" . $this->getSlotName();
133  }
134 
138  public static function _getPluginsDirectory($a_ctype, $a_cname, $a_slot_id)
139  {
140  return "./Customizing/global/plugins/" . $a_ctype .
141  "/" . $a_cname . "/" . ilPluginSlot::lookupSlotName($a_ctype, $a_cname, $a_slot_id);
142  }
143 
144 
148  public function getPluginPhpFileName($a_plugin_name)
149  {
150  return $this->getPluginsDirectory() . "/" .
151  $a_plugin_name . "/plugin.php";
152  }
153 
157  public function checkPluginPhpFileAvailability($a_plugin_name)
158  {
159  if (@is_file($this->getPluginPhpFileName($a_plugin_name))) {
160  return true;
161  }
162 
163  return false;
164  }
165 
169  public function getPluginClassFileName($a_plugin_name)
170  {
171  return $this->getPluginsDirectory() . "/" .
172  $a_plugin_name . "/classes/class.il" . $a_plugin_name . "Plugin.php";
173  }
174 
178  public function checkClassFileAvailability($a_plugin_name)
179  {
180  if (@is_file($this->getPluginClassFileName($a_plugin_name))) {
181  return true;
182  }
183 
184  return false;
185  }
186 
191  public function getPrefix()
192  {
193  if ($this->prefix == "") {
194  $this->prefix =
196  $this->getComponentType(),
197  $this->getComponentName()
198  ) . "_" . $this->getSlotId();
199  }
200 
201  return $this->prefix;
202  }
203 
207  public function getPluginsInformation()
208  {
209  global $DIC;
210  $ilPluginAdmin = $DIC['ilPluginAdmin'];
211 
212  // read plugins directory
213  $pl_dir = $this->getPluginsDirectory();
214 
215  if (!@is_dir($pl_dir)) {
216  return array();
217  }
218 
219  $dir = opendir($pl_dir);
220 
221  $plugins = array();
222  while ($file = readdir($dir)) {
223  if ($file != "." and
224  $file != "..") {
225  // directories
226  if (@is_dir($pl_dir . "/" . $file) && substr($file, 0, 1) != "." &&
227  $this->checkPluginPhpFileAvailability($file)
228  ) {
229  $plugin = ilPlugin::lookupStoredData(
230  $this->getComponentType(),
231  $this->getComponentName(),
232  $this->getSlotId(),
233  $file
234  );
235 
236  // create record in il_plugin table (if not existing)
237  if (count($plugin) == 0) {
239  $this->getComponentType(),
240  $this->getComponentName(),
241  $this->getSlotId(),
242  $file
243  );
244 
245  $plugin = ilPlugin::lookupStoredData(
246  $this->getComponentType(),
247  $this->getComponentName(),
248  $this->getSlotId(),
249  $file
250  );
251  }
252 
253  $pdata = $ilPluginAdmin->getAllData(
254  $this->getComponentType(),
255  $this->getComponentName(),
256  $this->getSlotId(),
257  $file
258  );
259 
260  $plugin = array_merge($plugin, $pdata);
261 
262  $plugin["name"] = $file;
263  $plugin["plugin_php_file_status"] = $this->checkPluginPhpFileAvailability($file);
264  $plugin["class_file_status"] = $this->checkClassFileAvailability($file);
265  $plugin["class_file"] = $this->getPluginClassFileName($file);
266 
267  $plugins[] = $plugin;
268  }
269  }
270  }
271 
272  return $plugins;
273  }
274 
278  public static function lookupSlotId($a_ctype, $a_cname, $a_slot_name)
279  {
280  $cached_component = ilCachedComponentData::getInstance();
281  $rec = $cached_component->lookupPluginSlotByName($a_slot_name);
282 
283  return $rec['id'];
284  }
285 
289  public static function lookupSlotName($a_ctype, $a_cname, $a_slot_id)
290  {
291  $cached_component = ilCachedComponentData::getInstance();
292  $rec = $cached_component->lookupPluginSlotById($a_slot_id);
293 
294  return $rec['name'];
295  }
296 
300  public function getActivePlugins()
301  {
302  global $DIC;
303  $ilPluginAdmin = $DIC['ilPluginAdmin'];
304 
305  return $ilPluginAdmin->getActivePluginsForSlot(
306  $this->getComponentType(),
307  $this->getComponentName(),
308  $this->getSlotId()
309  );
310  }
311 
312 
316  public static function getAllSlots()
317  {
318  $cached_component = ilCachedComponentData::getInstance();
319  $recs = $cached_component->getIlPluginslotById();
320 
321  foreach ($recs as $rec) {
322  $pos = strpos($rec["component"], "/");
323  $slots[] = array(
324  "component_type" => substr($rec["component"], 0, $pos),
325  "component_name" => substr($rec["component"], $pos + 1),
326  "slot_id" => $rec["id"],
327  "slot_name" => $rec["name"]
328  );
329  }
330 
331  return $slots;
332  }
333 }
__construct($a_c_type, $a_c_name, $a_slot_id)
Constructor.
getPluginsInformation()
Get information an all plugins and their status.
getPrefix()
Get slot prefix, used for lang vars and db tables.
getSlotName()
Get Slot Name.
static lookupId($a_type, $a_name)
Lookup ID of a component.
global $DIC
Definition: saml.php:7
checkPluginPhpFileAvailability($a_plugin_name)
Check whether plugin.php file is available for plugin or not.
static lookupSlotName($a_ctype, $a_cname, $a_slot_id)
Lookup slot name for component and slot id.
setComponentName($a_componentname)
Set Component Name.
static createPluginRecord(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
static lookupStoredData(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
Lookup information data in il_plugin.
getPluginPhpFileName($a_plugin_name)
Get File name for plugin.php.
getActivePlugins()
Get active plugins of slot.
Plugin Slot.
getSlotId()
Get Slot ID.
checkClassFileAvailability($a_plugin_name)
Check whether Plugin class file is available for plugin or not.
setSlotName($a_slotname)
Set Slot Name.
setSlotId($a_slotid)
Set Slot ID.
static _getPluginsDirectory($a_ctype, $a_cname, $a_slot_id)
Get plugins directory.
setComponentType($a_componenttype)
Set Component Type.
getComponentName()
Get Component Name.
read()
Read properties from DB.
getComponentType()
Get Component Type.
getPluginsDirectory()
Get directory of.
static lookupSlotId($a_ctype, $a_cname, $a_slot_name)
Lookup slot ID for component and slot name.
getPluginClassFileName($a_plugin_name)
Get Class File name for plugin.
static getAllSlots()
Get all plugin slots.