ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $ilPluginAdmin;
210 
211  // read plugins directory
212  $pl_dir = $this->getPluginsDirectory();
213 
214  if (!@is_dir($pl_dir)) {
215  return array();
216  }
217 
218  $dir = opendir($pl_dir);
219 
220  $plugins = array();
221  while ($file = readdir($dir)) {
222  if ($file != "." and
223  $file != "..") {
224  // directories
225  if (@is_dir($pl_dir . "/" . $file) && substr($file, 0, 1) != "." &&
226  $this->checkPluginPhpFileAvailability($file)
227  ) {
228  $plugin = array();
229 
230  $plugin = ilPlugin::lookupStoredData(
231  $this->getComponentType(),
232  $this->getComponentName(),
233  $this->getSlotId(),
234  $file
235  );
236 
237  // create record in il_plugin table (if not existing)
238  if (count($plugin) == 0) {
240  $this->getComponentType(),
241  $this->getComponentName(),
242  $this->getSlotId(),
243  $file
244  );
245  }
246 
247  $pdata = $ilPluginAdmin->getAllData(
248  $this->getComponentType(),
249  $this->getComponentName(),
250  $this->getSlotId(),
251  $file
252  );
253 
254  $plugin = array_merge($plugin, $pdata);
255 
256  $plugin["name"] = $file;
257  $plugin["plugin_php_file_status"] = $this->checkPluginPhpFileAvailability($file);
258  $plugin["class_file_status"] = $this->checkClassFileAvailability($file);
259  $plugin["class_file"] = $this->getPluginClassFileName($file);
260 
261  $plugins[] = $plugin;
262  }
263  }
264  }
265 
266  return $plugins;
267  }
268 
272  public static function lookupSlotId($a_ctype, $a_cname, $a_slot_name)
273  {
274  $cached_component = ilCachedComponentData::getInstance();
275  $rec = $cached_component->lookupPluginSlotByName($a_slot_name);
276 
277  return $rec['id'];
278  }
279 
283  public static function lookupSlotName($a_ctype, $a_cname, $a_slot_id)
284  {
285  $cached_component = ilCachedComponentData::getInstance();
286  $rec = $cached_component->lookupPluginSlotById($a_slot_id);
287 
288  return $rec['name'];
289  }
290 
294  public function getActivePlugins()
295  {
296  global $ilPluginAdmin;
297 
298  return $ilPluginAdmin->getActivePluginsForSlot(
299  $this->getComponentType(),
300  $this->getComponentName(),
301  $this->getSlotId()
302  );
303  }
304 
305 
309  public static function getAllSlots()
310  {
311  $cached_component = ilCachedComponentData::getInstance();
312  $recs = $cached_component->getIlPluginslotById();
313 
314  foreach ($recs as $rec) {
315  $pos = strpos($rec["component"], "/");
316  $slots[] = array(
317  "component_type" => substr($rec["component"], 0, $pos),
318  "component_name" => substr($rec["component"], $pos + 1),
319  "slot_id" => $rec["id"],
320  "slot_name" => $rec["name"]
321  );
322  }
323 
324  return $slots;
325  }
326 }
__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.
static lookupStoredData($a_ctype, $a_cname, $a_slot_id, $a_pname)
Lookup information data in il_plugin.
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.
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.
Create styles array
The data for the language used.
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.
static createPluginRecord($a_ctype, $a_cname, $a_slot_id, $a_pname)
getComponentType()
Get Component Type.
getPluginsDirectory()
Get directory of.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
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.