ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $this->setId($this->global_cache->lookCompId($this->getComponentType(), $this->getName()));
66 $this->getComponentType(), $this->getName()));
67
68//
69// echo '<pre>' . print_r($data, 1) . '</pre>';
70//
71//
72// $set = $ilDB->queryF("SELECT * FROM il_component WHERE type = %s ".
73// " AND name = %s", array("text", "text"),
74// array($this->getComponentType(), $this->getName()));
75// $rec = $ilDB->fetchAssoc($set);
76//
77// $this->setId($rec["id"]);
78// $this->setPluginSlots(ilComponent::lookupPluginSlots(
79// $this->getComponentType(), $this->getName()));
80 }
81
87 final function setId($a_id)
88 {
89 $this->id = $a_id;
90 }
91
97 final function getId()
98 {
99 return $this->id;
100 }
101
107 final function setPluginSlots($a_pluginslots)
108 {
109 $this->pluginslots = $a_pluginslots;
110 }
111
117 final function getPluginSlots()
118 {
119 return $this->pluginslots;
120 }
121
128 final static function getComponentObject($a_ctype, $a_cname)
129 {
130 global $ilDB;
131
132 $set = $ilDB->queryF("SELECT * FROM il_component WHERE type = %s ".
133 " AND name = %s", array("text", "text"),
134 array($a_ctype, $a_cname));
135 if (!$ilDB->fetchAssoc($set))
136 {
137 return null;
138 }
139
140 switch ($a_ctype)
141 {
142 case IL_COMP_MODULE:
143 if (is_file("./Modules/".$a_cname."/classes/class.il".$a_cname."Module.php"))
144 {
145 include_once("./Modules/".$a_cname."/classes/class.il".$a_cname."Module.php");
146 $class = "il".$a_cname."Module";
147 $comp = new $class();
148 return $comp;
149 }
150 break;
151
152 case IL_COMP_SERVICE:
153 if (is_file("./Services/".$a_cname."/classes/class.il".$a_cname."Service.php"))
154 {
155 include_once("./Services/".$a_cname."/classes/class.il".$a_cname."Service.php");
156 $class = "il".$a_cname."Service";
157 $comp = new $class();
158 return $comp;
159 }
160 break;
161 }
162
163 return null;
164 }
165
171 function setSubDirectory($a_subdirectory)
172 {
173 $this->subdirectory = $a_subdirectory;
174 }
175
182 {
183 return $this->subdirectory;
184 }
185
189 static function lookupPluginSlots($a_type, $a_name)
190 {
191// global $ilDB;
192
193 $cached_component = ilCachedComponentData::getInstance();
194 $recs = $cached_component->lookupPluginSlotByComponent($a_type."/".$a_name);
195
196 //$set = $ilDB->query("SELECT * FROM il_pluginslot WHERE component = ".
197 // $ilDB->quote($a_type."/".$a_name, "text"));
198 $ps = array();
199//echo "<br>".$a_type."/".$a_name;
200 //while($rec = $ilDB->fetchAssoc($set))
201 foreach($recs as $rec)
202 {
203 $rec["dir"] = "Customizing/global/plugins/".$a_type."/".$a_name."/".$rec["name"];
204 $rec["dir_pres"] = "Customizing/global/plugins/<br />".$a_type."/".$a_name."/".$rec["name"];
205 $rec["lang_prefix"] = ilComponent::lookupId($a_type,$a_name)."_".$rec["id"]."_";
206 $ps[$rec["id"]] = $rec;
207 }
208 return $ps;
209 }
210
216 function getPluginSlotName($a_id)
217 {
218 $slots = $this->getPluginSlots();
219
220 return $slots[$a_id]["name"];
221 }
222
229 {
230 $slots = $this->getPluginSlots();
231
232 return "Customizing/global/plugins/".$this->getComponentType()."/".
233 $this->getName()."/".$slots[$a_id]["name"];
234 }
235
242 {
243 $slots = $this->getPluginSlots();
244 return $this->getId()."_".$slots[$a_id]["id"]."_";
245 }
246
250 static function lookupId($a_type, $a_name)
251 {
253
254 return $global_cache->lookCompId($a_type, $a_name);
255
256 //global $ilDB;
257
258 //$set = $ilDB->queryF("SELECT * FROM il_component WHERE type = %s ".
259 // " AND name = %s", array("text", "text"),
260 // array($a_type, $a_name));
261 //$rec = $ilDB->fetchAssoc($set);
262
263 //return $rec["id"];
264 }
265
272 public static function getComponentInfo($a_type, $a_name){
274
275 return $global_cache->lookupCompInfo($a_type, $a_name);
276 }
277
281 static final function checkVersionNumber($a_ver)
282 {
283 global $lng;
284
285 $parts = explode(".", $a_ver);
286
287 if (count($parts) != 3)
288 {
289 return "Version Number does not conform to format a.b.c";
290 }
291
292 if (!is_numeric($parts[0]) || !is_numeric($parts[1]) || !is_numeric($parts[2]))
293 {
294 return "Not all version number parts a.b.c are numeric.";
295 }
296
297 return $parts;
298 }
299
300 static final function isVersionGreaterString($a_ver1, $a_ver2)
301 {
302 $a_arr1 = ilComponent::checkVersionNumber($a_ver1);
303 $a_arr2 = ilComponent::checkVersionNumber($a_ver2);
304 if (is_array($a_arr1) && is_array($a_arr2))
305 {
306 return ilComponent::isVersionGreater($a_arr1, $a_arr2);
307 }
308 else
309 {
310 return false;
311 }
312 }
313
322 static final function isVersionGreater($a_ver1, $a_ver2)
323 {
324 if ($a_ver1[0] > $a_ver2[0])
325 {
326 return true;
327 }
328 else if ($a_ver1[0] < $a_ver2[0])
329 {
330 return false;
331 }
332 else if ($a_ver1[1] > $a_ver2[1])
333 {
334 return true;
335 }
336 else if ($a_ver1[1] < $a_ver2[1])
337 {
338 return false;
339 }
340 else if ($a_ver1[2] > $a_ver2[2])
341 {
342 return true;
343 }
344
345 return false;
346 }
347
354 public static function lookupComponentName($a_component_id)
355 {
356 global $ilDB;
357
358 $query = 'SELECT name from il_component '.
359 'WHERE id = '.$ilDB->quote($a_component_id,'text');
360
361 $res = $ilDB->query($query);
362 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
363 {
364 return $row->name;
365 }
366 }
367
368
369}
370?>
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 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:17
global $ilDB
$a_type
Definition: workflow.php:93