ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 function getVersion();
41
42 abstract function isCore();
43
44 abstract static function getComponentType();
45
51 abstract function getName();
52
53
57 protected $global_cache;
58
59 function __construct()
60 {
61// global $ilDB;
62 $this->global_cache = ilCachedComponentData::getInstance();
63
64 $rec = $this->global_cache->lookCompId($this->getName(), $this->getComponentType());
65 $this->setId($rec["id"]);
67 $this->getComponentType(), $this->getName()));
68
69//
70// echo '<pre>' . print_r($data, 1) . '</pre>';
71//
72//
73// $set = $ilDB->queryF("SELECT * FROM il_component WHERE type = %s ".
74// " AND name = %s", array("text", "text"),
75// array($this->getComponentType(), $this->getName()));
76// $rec = $ilDB->fetchAssoc($set);
77//
78// $this->setId($rec["id"]);
79// $this->setPluginSlots(ilComponent::lookupPluginSlots(
80// $this->getComponentType(), $this->getName()));
81 }
82
88 final function setId($a_id)
89 {
90 $this->id = $a_id;
91 }
92
98 final function getId()
99 {
100 return $this->id;
101 }
102
108 final function setPluginSlots($a_pluginslots)
109 {
110 $this->pluginslots = $a_pluginslots;
111 }
112
118 final function getPluginSlots()
119 {
120 return $this->pluginslots;
121 }
122
129 final static function getComponentObject($a_ctype, $a_cname)
130 {
131 global $ilDB;
132
133 $set = $ilDB->queryF("SELECT * FROM il_component WHERE type = %s ".
134 " AND name = %s", array("text", "text"),
135 array($a_ctype, $a_cname));
136 if (!$ilDB->fetchAssoc($set))
137 {
138 return null;
139 }
140
141 switch ($a_ctype)
142 {
143 case IL_COMP_MODULE:
144 if (is_file("./Modules/".$a_cname."/classes/class.il".$a_cname."Module.php"))
145 {
146 include_once("./Modules/".$a_cname."/classes/class.il".$a_cname."Module.php");
147 $class = "il".$a_cname."Module";
148 $comp = new $class();
149 return $comp;
150 }
151 break;
152
153 case IL_COMP_SERVICE:
154 if (is_file("./Services/".$a_cname."/classes/class.il".$a_cname."Service.php"))
155 {
156 include_once("./Services/".$a_cname."/classes/class.il".$a_cname."Service.php");
157 $class = "il".$a_cname."Service";
158 $comp = new $class();
159 return $comp;
160 }
161 break;
162 }
163
164 return null;
165 }
166
172 function setSubDirectory($a_subdirectory)
173 {
174 $this->subdirectory = $a_subdirectory;
175 }
176
183 {
184 return $this->subdirectory;
185 }
186
190 static function lookupPluginSlots($a_type, $a_name)
191 {
192// global $ilDB;
193
194 $cached_component = ilCachedComponentData::getInstance();
195 $recs = $cached_component->lookupPluginSlotByComponent($a_type."/".$a_name);
196
197 //$set = $ilDB->query("SELECT * FROM il_pluginslot WHERE component = ".
198 // $ilDB->quote($a_type."/".$a_name, "text"));
199 $ps = array();
200//echo "<br>".$a_type."/".$a_name;
201 //while($rec = $ilDB->fetchAssoc($set))
202 foreach($recs as $rec)
203 {
204 $rec["dir"] = "Customizing/global/plugins/".$a_type."/".$a_name."/".$rec["name"];
205 $rec["dir_pres"] = "Customizing/global/plugins/<br />".$a_type."/".$a_name."/".$rec["name"];
206 $rec["lang_prefix"] = ilComponent::lookupId($a_type,$a_name)."_".$rec["id"]."_";
207 $ps[$rec["id"]] = $rec;
208 }
209 return $ps;
210 }
211
217 function getPluginSlotName($a_id)
218 {
219 $slots = $this->getPluginSlots();
220
221 return $slots[$a_id]["name"];
222 }
223
230 {
231 $slots = $this->getPluginSlots();
232
233 return "Customizing/global/plugins/".$this->getComponentType()."/".
234 $this->getName()."/".$slots[$a_id]["name"];
235 }
236
243 {
244 $slots = $this->getPluginSlots();
245 return $this->getId()."_".$slots[$a_id]["id"]."_";
246 }
247
251 static function lookupId($a_type, $a_name)
252 {
254
255 return $global_cache->lookCompId($a_type, $a_name);
256
257 //global $ilDB;
258
259 //$set = $ilDB->queryF("SELECT * FROM il_component WHERE type = %s ".
260 // " AND name = %s", array("text", "text"),
261 // array($a_type, $a_name));
262 //$rec = $ilDB->fetchAssoc($set);
263
264 //return $rec["id"];
265 }
266
273 public static function getComponentInfo($a_type, $a_name){
275
276 return $global_cache->lookupCompInfo($a_type, $a_name);
277 }
278
282 static final function checkVersionNumber($a_ver)
283 {
284 global $lng;
285
286 $parts = explode(".", $a_ver);
287
288 if (count($parts) != 3)
289 {
290 return "Version Number does not conform to format a.b.c";
291 }
292
293 if (!is_numeric($parts[0]) || !is_numeric($parts[1]) || !is_numeric($parts[2]))
294 {
295 return "Not all version number parts a.b.c are numeric.";
296 }
297
298 return $parts;
299 }
300
301 static final function isVersionGreaterString($a_ver1, $a_ver2)
302 {
303 $a_arr1 = ilComponent::checkVersionNumber($a_ver1);
304 $a_arr2 = ilComponent::checkVersionNumber($a_ver2);
305 if (is_array($a_arr1) && is_array($a_arr2))
306 {
307 return ilComponent::isVersionGreater($a_arr1, $a_arr2);
308 }
309 else
310 {
311 return false;
312 }
313 }
314
323 static final function isVersionGreater($a_ver1, $a_ver2)
324 {
325 if ($a_ver1[0] > $a_ver2[0])
326 {
327 return true;
328 }
329 else if ($a_ver1[0] < $a_ver2[0])
330 {
331 return false;
332 }
333 else if ($a_ver1[1] > $a_ver2[1])
334 {
335 return true;
336 }
337 else if ($a_ver1[1] < $a_ver2[1])
338 {
339 return false;
340 }
341 else if ($a_ver1[2] > $a_ver2[2])
342 {
343 return true;
344 }
345
346 return false;
347 }
348
355 public static function lookupComponentName($a_component_id)
356 {
357 global $ilDB;
358
359 $query = 'SELECT name from il_component '.
360 'WHERE id = '.$ilDB->quote($a_component_id,'text');
361
362 $res = $ilDB->query($query);
363 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
364 {
365 return $row->name;
366 }
367 }
368
369
370}
371?>
const IL_COMP_SERVICE
const IL_COMP_MODULE
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
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 isVersionGreater($a_ver1, $a_ver2)
Check whether version number is greater than another version number.
static lookupId($a_type, $a_name)
Lookup ID of a component.
static getComponentType()
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.
getPluginSlotName($a_id)
Get name of plugin slot.
getSubDirectory()
Get Sub Directory.
getPluginSlotLanguagePrefix($a_id)
Get language prefix for plugin slot.
global $lng
Definition: privfeed.php:40
global $ilDB