ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilComponent.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3require_once('class.ilCachedComponentData.php');
4
5define("IL_COMP_MODULE", "Modules");
6define("IL_COMP_SERVICE", "Services");
7define("IL_COMP_PLUGIN", "Plugins");
8define("IL_COMP_SLOTS", "Slots");
9
23abstract class ilComponent
24{
40 abstract public function getVersion();
41
42 abstract public function isCore();
43
47 abstract public function getComponentType() : string;
48
54 abstract public function getName();
55
56
60 protected $global_cache;
61
62 public function __construct()
63 {
64 $this->global_cache = ilCachedComponentData::getInstance();
65
66 $this->setId($this->global_cache->lookCompId($this->getComponentType(), $this->getName()));
68 $this->getComponentType(),
69 $this->getName()
70 ));
71 }
72
78 final public function setId($a_id)
79 {
80 $this->id = $a_id;
81 }
82
88 final public function getId()
89 {
90 return $this->id;
91 }
92
98 final public function setPluginSlots($a_pluginslots)
99 {
100 $this->pluginslots = $a_pluginslots;
101 }
102
108 final public function getPluginSlots()
109 {
110 return $this->pluginslots;
111 }
112
119 final public static function getComponentObject($a_ctype, $a_cname)
120 {
121 global $DIC;
122 $ilDB = $DIC->database();
123
124 $set = $ilDB->queryF(
125 "SELECT * FROM il_component WHERE type = %s " .
126 " AND name = %s",
127 array("text", "text"),
128 array($a_ctype, $a_cname)
129 );
130 if (!$ilDB->fetchAssoc($set)) {
131 return null;
132 }
133
134 switch ($a_ctype) {
135 case IL_COMP_MODULE:
136 if (is_file("./Modules/" . $a_cname . "/classes/class.il" . $a_cname . "Module.php")) {
137 include_once("./Modules/" . $a_cname . "/classes/class.il" . $a_cname . "Module.php");
138 $class = "il" . $a_cname . "Module";
139 $comp = new $class();
140 return $comp;
141 }
142 break;
143
144 case IL_COMP_SERVICE:
145 if (is_file("./Services/" . $a_cname . "/classes/class.il" . $a_cname . "Service.php")) {
146 include_once("./Services/" . $a_cname . "/classes/class.il" . $a_cname . "Service.php");
147 $class = "il" . $a_cname . "Service";
148 $comp = new $class();
149 return $comp;
150 }
151 break;
152 }
153
154 return null;
155 }
156
162 public function setSubDirectory($a_subdirectory)
163 {
164 $this->subdirectory = $a_subdirectory;
165 }
166
172 public function getSubDirectory()
173 {
174 return $this->subdirectory;
175 }
176
180 public static function lookupPluginSlots($a_type, $a_name)
181 {
182 $cached_component = ilCachedComponentData::getInstance();
183 $recs = $cached_component->lookupPluginSlotByComponent($a_type . "/" . $a_name);
184
185 $ps = array();
186 foreach ($recs as $rec) {
187 $rec["dir"] = "Customizing/global/plugins/" . $a_type . "/" . $a_name . "/" . $rec["name"];
188 $rec["dir_pres"] = "Customizing/global/plugins/<br />" . $a_type . "/" . $a_name . "/" . $rec["name"];
189 $rec["lang_prefix"] = ilComponent::lookupId($a_type, $a_name) . "_" . $rec["id"] . "_";
190 $ps[$rec["id"]] = $rec;
191 }
192 return $ps;
193 }
194
200 public function getPluginSlotName($a_id)
201 {
202 $slots = $this->getPluginSlots();
203
204 return $slots[$a_id]["name"];
205 }
206
212 public function getPluginSlotDirectory($a_id)
213 {
214 $slots = $this->getPluginSlots();
215
216 return "Customizing/global/plugins/" . $this->getComponentType() . "/" .
217 $this->getName() . "/" . $slots[$a_id]["name"];
218 }
219
225 public function getPluginSlotLanguagePrefix($a_id)
226 {
227 $slots = $this->getPluginSlots();
228 return $this->getId() . "_" . $slots[$a_id]["id"] . "_";
229 }
230
234 public static function lookupId($a_type, $a_name)
235 {
237
238 return $global_cache->lookCompId($a_type, $a_name);
239 }
240
247 public static function getComponentInfo($a_type, $a_name)
248 {
250
251 return $global_cache->lookupCompInfo($a_type, $a_name);
252 }
253
257 final public static function checkVersionNumber($a_ver)
258 {
259 $parts = explode(".", $a_ver);
260
261 if (count($parts) < 2 || count($parts) > 3) {
262 return "Version number does not conform to format a.b or a.b.c";
263 }
264
265 if (!is_numeric($parts[0]) || !is_numeric($parts[1])) {
266 return "Not all version number parts a.b or a.b.c are numeric.";
267 }
268
269 if (isset($parts[2]) && !is_numeric($parts[2])) {
270 return "Not all version number parts a.b.c are numeric.";
271 }
272
273 return $parts;
274 }
275
276 final public static function isVersionGreaterString($a_ver1, $a_ver2)
277 {
278 $a_arr1 = ilComponent::checkVersionNumber($a_ver1);
279 $a_arr2 = ilComponent::checkVersionNumber($a_ver2);
280
281 if (is_array($a_arr1) && is_array($a_arr2)) {
282 return ilComponent::isVersionGreater($a_ver1, $a_ver2);
283 } else {
284 return false;
285 }
286 }
287
293 final public static function isVersionGreater(string $version1, string $version2) : bool
294 {
295 return version_compare($version1, $version2, '>');
296 }
297
304 public static function lookupComponentName($a_component_id)
305 {
306 global $DIC;
307 $ilDB = $DIC->database();
308
309 $query = 'SELECT name from il_component ' .
310 'WHERE id = ' . $ilDB->quote($a_component_id, 'text');
311
312 $res = $ilDB->query($query);
313 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
314 return $row->name;
315 }
316 }
317
322 public static function getAll()
323 {
324 global $DIC;
325 $ilDB = $DIC->database();
326
327 $set = $ilDB->query("SELECT * FROM il_component");
328 $comps = [];
329 while ($rec = $ilDB->fetchAssoc($set)) {
330 $comps[$rec["id"]] = $rec;
331 }
332 return $comps;
333 }
334}
An exception for terminatinating execution or to throw for unit testing.
const IL_COMP_SERVICE
const IL_COMP_MODULE
static isVersionGreaterString($a_ver1, $a_ver2)
static checkVersionNumber($a_ver)
Check version number.
static lookupComponentName($a_component_id)
lookup component name @global type $ilDB
getPluginSlots()
Get Plugin Slots.
setPluginSlots($a_pluginslots)
Set Plugin Slots.
setSubDirectory($a_subdirectory)
Set Sub Directory.
getName()
Get Name.
setId($a_id)
Set Id.
getPluginSlotDirectory($a_id)
Get directory of plugin slot.
static getComponentInfo($a_type, $a_name)
static lookupId($a_type, $a_name)
Lookup ID of a component.
static getComponentObject($a_ctype, $a_cname)
Get component object.
getVersion()
Get Version Number of Component.
static lookupPluginSlots($a_type, $a_name)
Lookup all plugin slots of a component.
static isVersionGreater(string $version1, string $version2)
getPluginSlotName($a_id)
Get name of plugin slot.
getSubDirectory()
Get Sub Directory.
getPluginSlotLanguagePrefix($a_id)
Get language prefix for plugin slot.
static getAll()
Get all.
global $DIC
Definition: goto.php:24
$query
foreach($_POST as $key=> $value) $res
global $ilDB