ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilComponent.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
25 define ("IL_COMP_MODULE", "Modules");
26 define ("IL_COMP_SERVICE", "Services");
27 define ("IL_COMP_PLUGIN", "Plugins");
28 
42 abstract class ilComponent
43 {
59  abstract function getVersion();
60 
61  abstract function isCore();
62 
63  abstract static function getComponentType();
64 
70  abstract function getName();
71 
72  function __construct()
73  {
74  global $ilDB;
75 
76  $set = $ilDB->query("SELECT * FROM il_component WHERE type = ".
77  $ilDB->quote($this->getComponentType())." AND name = ".
78  $ilDB->quote($this->getName()));
79 
80  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
81 
82  $this->setId($rec["id"]);
84  $this->getComponentType(), $this->getName()));
85  }
86 
92  final function setId($a_id)
93  {
94  $this->id = $a_id;
95  }
96 
102  final function getId()
103  {
104  return $this->id;
105  }
106 
112  final function setPluginSlots($a_pluginslots)
113  {
114  $this->pluginslots = $a_pluginslots;
115  }
116 
122  final function getPluginSlots()
123  {
124  return $this->pluginslots;
125  }
126 
133  final static function getComponentObject($a_ctype, $a_cname)
134  {
135  global $ilDB;
136 
137  // this check is done due to security reasons
138  $set = $ilDB->query("SELECT * FROM il_component WHERE type = ".
139  $ilDB->quote($a_ctype)." AND name = ".$ilDB->quote($a_cname));
140  if ($set->numRows() == 0)
141  {
142  return null;
143  }
144 
145  switch ($a_ctype)
146  {
147  case IL_COMP_MODULE:
148  if (is_file("./Modules/".$a_cname."/classes/class.il".$a_cname."Module.php"))
149  {
150  include_once("./Modules/".$a_cname."/classes/class.il".$a_cname."Module.php");
151  $class = "il".$a_cname."Module";
152  $comp = new $class();
153  return $comp;
154  }
155  break;
156 
157  case IL_COMP_SERVICE:
158  if (is_file("./Services/".$a_cname."/classes/class.il".$a_cname."Service.php"))
159  {
160  include_once("./Services/".$a_cname."/classes/class.il".$a_cname."Service.php");
161  $class = "il".$a_cname."Service";
162  $comp = new $class();
163  return $comp;
164  }
165  break;
166  }
167 
168  return null;
169  }
170 
176  function setSubDirectory($a_subdirectory)
177  {
178  $this->subdirectory = $a_subdirectory;
179  }
180 
186  function getSubDirectory()
187  {
188  return $this->subdirectory;
189  }
190 
194  static function lookupPluginSlots($a_type, $a_name)
195  {
196  global $ilDB;
197 
198  $set = $ilDB->query("SELECT * FROM il_pluginslot WHERE component = ".
199  $ilDB->quote($a_type."/".$a_name));
200  $ps = array();
201 //echo "<br>".$a_type."/".$a_name;
202  while($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
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 
229  function getPluginSlotDirectory($a_id)
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  {
253  global $ilDB;
254 
255  $set = $ilDB->query("SELECT * FROM il_component WHERE type = ".
256  $ilDB->quote($a_type)." AND name = ".$ilDB->quote($a_name));
257  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
258 
259  return $rec["id"];
260  }
261 
265  static final function checkVersionNumber($a_ver)
266  {
267  global $lng;
268 
269  $lng->loadLanguageModule("cmps");
270 
271  $parts = explode(".", $a_ver);
272 
273  if (count($parts) != 3)
274  {
275  return $lng->txt("cmps_version_nr_format_error");
276  }
277 
278  if (!is_numeric($parts[0]) || !is_numeric($parts[1]) || !is_numeric($parts[2]))
279  {
280  return $lng->txt("cmps_version_nr_parts_not_numeric");
281  }
282 
283  return $parts;
284  }
285 
286  static final function isVersionGreaterString($a_ver1, $a_ver2)
287  {
288  $a_arr1 = ilComponent::checkVersionNumber($a_ver1);
289  $a_arr2 = ilComponent::checkVersionNumber($a_ver2);
290  if (is_array($a_arr1) && is_array($a_arr2))
291  {
292  return ilComponent::isVersionGreater($a_arr1, $a_arr2);
293  }
294  else
295  {
296  return false;
297  }
298  }
299 
308  static final function isVersionGreater($a_ver1, $a_ver2)
309  {
310  if ($a_ver1[0] > $a_ver2[0])
311  {
312  return true;
313  }
314  else if ($a_ver1[0] < $a_ver2[0])
315  {
316  return false;
317  }
318  else if ($a_ver1[1] > $a_ver2[1])
319  {
320  return true;
321  }
322  else if ($a_ver1[1] < $a_ver2[1])
323  {
324  return false;
325  }
326  else if ($a_ver1[2] > $a_ver2[2])
327  {
328  return true;
329  }
330 
331  return false;
332  }
333 
334 }
335 ?>