ILIAS  release_7 Revision v7.30-3-g800a261c036
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
5include_once("./Services/Component/classes/class.ilPlugin.php");
6
20{
21 protected $prefix = "";
22
26 public function __construct($a_c_type, $a_c_name, $a_slot_id)
27 {
28 $this->setComponentType($a_c_type);
29 $this->setComponentName($a_c_name);
30 $this->setSlotId($a_slot_id);
31
32 if ($a_slot_id != "") {
33 $this->read();
34 }
35 }
36
40 public function read()
41 {
42 $cached_component = ilCachedComponentData::getInstance();
43 $rec = $cached_component->lookupPluginSlotById($this->getSlotId());
44 $this->setSlotName($rec["name"]);
45 }
46
52 public function setComponentType($a_componenttype)
53 {
54 $this->componenttype = $a_componenttype;
55 }
56
62 public function getComponentType()
63 {
64 return $this->componenttype;
65 }
66
72 public function setComponentName($a_componentname)
73 {
74 $this->componentname = $a_componentname;
75 }
76
82 public function getComponentName()
83 {
84 return $this->componentname;
85 }
86
92 public function setSlotId($a_slotid)
93 {
94 $this->slotid = $a_slotid;
95 }
96
102 public function getSlotId()
103 {
104 return $this->slotid;
105 }
106
112 public function setSlotName($a_slotname)
113 {
114 $this->slotname = $a_slotname;
115 }
116
122 public function getSlotName()
123 {
124 return $this->slotname;
125 }
126
130 public function getPluginsDirectory()
131 {
132 return "./Customizing/global/plugins/" . $this->getComponentType() .
133 "/" . $this->getComponentName() . "/" . $this->getSlotName();
134 }
135
139 public static function _getPluginsDirectory($a_ctype, $a_cname, $a_slot_id)
140 {
141 return "./Customizing/global/plugins/" . $a_ctype .
142 "/" . $a_cname . "/" . ilPluginSlot::lookupSlotName($a_ctype, $a_cname, $a_slot_id);
143 }
144
145
149 public function getPluginPhpFileName($a_plugin_name)
150 {
151 return $this->getPluginsDirectory() . "/" .
152 $a_plugin_name . "/plugin.php";
153 }
154
158 public function checkPluginPhpFileAvailability($a_plugin_name)
159 {
160 if (@is_file($this->getPluginPhpFileName($a_plugin_name))) {
161 return true;
162 }
163
164 return false;
165 }
166
170 public function getPluginClassFileName($a_plugin_name)
171 {
172 return $this->getPluginsDirectory() . "/" .
173 $a_plugin_name . "/classes/class.il" . $a_plugin_name . "Plugin.php";
174 }
175
179 public function checkClassFileAvailability($a_plugin_name)
180 {
181 if (@is_file($this->getPluginClassFileName($a_plugin_name))) {
182 return true;
183 }
184
185 return false;
186 }
187
192 public function getPrefix()
193 {
194 if ($this->prefix == "") {
195 $this->prefix =
197 $this->getComponentType(),
198 $this->getComponentName()
199 ) . "_" . $this->getSlotId();
200 }
201
202 return $this->prefix;
203 }
204
208 public function getPluginsInformation()
209 {
210 // read plugins directory
211 $pl_dir = $this->getPluginsDirectory();
212
213 if (!@is_dir($pl_dir)) {
214 return array();
215 }
216
217 $dir = opendir($pl_dir);
218
219 $plugins = array();
220 while ($file = readdir($dir)) {
221 if ($file != "." and
222 $file != "..") {
223 // directories
224 $plugin = $this->readPluginInformation($pl_dir, $file);
225 if (!is_null($plugin)) {
226 $plugins[] = $plugin;
227 }
228 }
229 }
230
231 return $plugins;
232 }
233
234 public function getPluginInformationFor(string $name) : ?array
235 {
236 $pl_dir = $this->getPluginsDirectory();
237
238 return $this->readPluginInformation($pl_dir, $name);
239 }
240
241 protected function readPluginInformation(string $pl_dir, string $file) : ?array
242 {
243 global $DIC;
244 $ilPluginAdmin = $DIC['ilPluginAdmin'];
245
246 if (@is_dir($pl_dir . "/" . $file) && substr($file, 0, 1) != "." &&
248 ) {
250 $this->getComponentType(),
251 $this->getComponentName(),
252 $this->getSlotId(),
253 $file
254 );
255
256 // create record in il_plugin table (if not existing)
257 if (count($plugin) == 0) {
259 $this->getComponentType(),
260 $this->getComponentName(),
261 $this->getSlotId(),
262 $file
263 );
264
266 $this->getComponentType(),
267 $this->getComponentName(),
268 $this->getSlotId(),
269 $file
270 );
271 }
272
273 $pdata = $ilPluginAdmin->getAllData(
274 $this->getComponentType(),
275 $this->getComponentName(),
276 $this->getSlotId(),
277 $file
278 );
279
280 $plugin = array_merge($plugin, $pdata);
281
282 $plugin["name"] = $file;
283 $plugin["plugin_php_file_status"] = $this->checkPluginPhpFileAvailability($file);
284 $plugin["class_file_status"] = $this->checkClassFileAvailability($file);
285 $plugin["class_file"] = $this->getPluginClassFileName($file);
286
287 return $plugin;
288 }
289 return null;
290 }
291
295 public static function lookupSlotId($a_ctype, $a_cname, $a_slot_name)
296 {
297 $cached_component = ilCachedComponentData::getInstance();
298 $rec = $cached_component->lookupPluginSlotByName($a_slot_name);
299
300 return $rec['id'];
301 }
302
306 public static function lookupSlotName($a_ctype, $a_cname, $a_slot_id)
307 {
308 $cached_component = ilCachedComponentData::getInstance();
309 $rec = $cached_component->lookupPluginSlotById($a_slot_id);
310
311 return $rec['name'];
312 }
313
317 public function getActivePlugins()
318 {
319 global $DIC;
320 $ilPluginAdmin = $DIC['ilPluginAdmin'];
321
322 return $ilPluginAdmin->getActivePluginsForSlot(
323 $this->getComponentType(),
324 $this->getComponentName(),
325 $this->getSlotId()
326 );
327 }
328
329
333 public static function getAllSlots()
334 {
335 $cached_component = ilCachedComponentData::getInstance();
336 $recs = $cached_component->getIlPluginslotById();
337
338 foreach ($recs as $rec) {
339 $pos = strpos($rec["component"], "/");
340 $slots[] = array(
341 "component_type" => substr($rec["component"], 0, $pos),
342 "component_name" => substr($rec["component"], $pos + 1),
343 "slot_id" => $rec["id"],
344 "slot_name" => $rec["name"]
345 );
346 }
347
348 return $slots;
349 }
350
355 public static function getAvailableSlots() : array
356 {
357 $cached_component = ilCachedComponentData::getInstance();
358 $recs = $cached_component->getIlPluginslotById();
359 $slots = array();
360 foreach ($recs as $rec) {
361 if($cached_component->lookupPluginsBySlotId($rec["id"])) {
362 $pos = strpos($rec["component"], "/");
363 $slots[] = array(
364 "component_type" => substr($rec["component"], 0, $pos),
365 "component_name" => substr($rec["component"], $pos + 1),
366 "slot_id" => $rec["id"],
367 "slot_name" => $rec["name"]
368 );
369 }
370 }
371 return $slots;
372 }
373}
An exception for terminatinating execution or to throw for unit testing.
static lookupId($a_type, $a_name)
Lookup ID of a component.
getSlotId()
Get Slot ID.
getPluginInformationFor(string $name)
checkClassFileAvailability($a_plugin_name)
Check whether Plugin class file is available for plugin or not.
setComponentName($a_componentname)
Set Component Name.
__construct($a_c_type, $a_c_name, $a_slot_id)
Constructor.
getActivePlugins()
Get active plugins of slot.
static lookupSlotName($a_ctype, $a_cname, $a_slot_id)
Lookup slot name for component and slot id.
read()
Read properties from DB.
setSlotId($a_slotid)
Set Slot ID.
static getAllSlots()
Get all plugin slots.
getPluginPhpFileName($a_plugin_name)
Get File name for plugin.php.
readPluginInformation(string $pl_dir, string $file)
getComponentType()
Get Component Type.
getPrefix()
Get slot prefix, used for lang vars and db tables.
getPluginsInformation()
Get information an all plugins and their status.
getComponentName()
Get Component Name.
setSlotName($a_slotname)
Set Slot Name.
getPluginClassFileName($a_plugin_name)
Get Class File name for plugin.
checkPluginPhpFileAvailability($a_plugin_name)
Check whether plugin.php file is available for plugin or not.
getPluginsDirectory()
Get directory of.
static getAvailableSlots()
Get all plugin slots where plugins are available.
static _getPluginsDirectory($a_ctype, $a_cname, $a_slot_id)
Get plugins directory.
setComponentType($a_componenttype)
Set Component Type.
static lookupSlotId($a_ctype, $a_cname, $a_slot_name)
Lookup slot ID for component and slot name.
getSlotName()
Get Slot Name.
static lookupStoredData(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
Lookup information data in il_plugin.
static createPluginRecord(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
global $DIC
Definition: goto.php:24
if($format !==null) $name
Definition: metadata.php:230