ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjDefReader.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
16 {
17  protected $readers = array(
18  "copage" => array("class" => "ilCOPageDefReader")
19  );
20  protected $current_reader = null;
21 
22  function ilObjDefReader($a_path, $a_name, $a_type)
23  {
24  // init specialized readers
25  foreach ($this->readers as $k => $reader)
26  {
27  $class = $reader["class"];
28  $class_path = "./setup/classes/class.".$class.".php";
29  include_once($class_path);
30  $this->readers[$k]["reader"] = new $class();
31  }
32 
33  $this->name = $a_name;
34  $this->type = $a_type;
35 //echo "<br>-".$a_path."-".$this->name."-".$this->type."-";
36  parent::ilSaxParser($a_path);
37  }
38 
39  function setHandlers($a_xml_parser)
40  {
41  xml_set_object($a_xml_parser,$this);
42  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
43  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
44  }
45 
49  function clearTables()
50  {
51  global $ilDB;
52 
53  $ilDB->manipulate("DELETE FROM il_object_def");
54 
55  $ilDB->manipulate("DELETE FROM il_object_subobj");
56 
57  $ilDB->manipulate("DELETE FROM il_object_group");
58 
59  $ilDB->manipulate("DELETE FROM il_pluginslot");
60 
61  $ilDB->manipulate("DELETE FROM il_component");
62 
63  $ilDB->manipulate("DELETE FROM il_event_handling");
64 
65  $ilDB->manipulate("DELETE FROM il_object_sub_type");
66 
67  foreach ($this->readers as $k => $reader)
68  {
69  $this->readers[$k]["reader"]->clearTables();
70  }
71  }
72 
76  static function deleteObjectDefinition($a_id)
77  {
78  global $ilDB;
79 
80  $ilDB->manipulateF("DELETE FROM il_object_def WHERE id = %s",
81  array("text"), array($a_id));
82 
83  $ilDB->manipulateF("DELETE FROM il_object_subobj WHERE parent = %s OR subobj = %s",
84  array("text", "text"), array($a_id, $a_id));
85  }
86 
94  function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
95  {
96  global $ilDB;
97 
98  $this->current_tag = $a_name;
99 
100  // check if a special reader needs to be activated
101  if (isset($this->readers[$a_name]))
102  {
103  $this->current_reader = $a_name;
104  }
105 
106  // call special reader
107  if ($this->current_reader != "")
108  {
109  $this->readers[$this->current_reader]["reader"]->handlerBeginTag($a_xml_parser,$a_name,$a_attribs,
110  $this->current_component);
111  }
112  else
113  {
114  // default handling
115  switch ($a_name)
116  {
117  case 'object':
118 
119  // if attributes are not given, set default (repository only)
120  if($a_attribs["repository"] === NULL)
121  {
122  $a_attribs["repository"] = true;
123  }
124  if($a_attribs["workspace"] === NULL)
125  {
126  $a_attribs["workspace"] = false;
127  }
128 
129  $this->current_object = $a_attribs["id"];
130  $ilDB->manipulateF("INSERT INTO il_object_def (id, class_name, component,location,".
131  "checkbox,inherit,translate,devmode,allow_link,allow_copy,rbac,default_pos,".
132  "default_pres_pos,sideblock,grp,system,export,repository,workspace,administration,amet) VALUES ".
133  "(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
134  array("text", "text", "text", "text", "integer", "integer", "text", "integer","integer","integer",
135  "integer","integer","integer","integer", "text", "integer", "integer", "integer", "integer",'integer','integer'),
136  array(
137  $a_attribs["id"],
138  $a_attribs["class_name"],
139  $this->current_component,
140  $this->current_component."/".$a_attribs["dir"],
141  (int) $a_attribs["checkbox"],
142  (int) $a_attribs["inherit"],
143  $a_attribs["translate"],
144  (int) $a_attribs["devmode"],
145  (int) $a_attribs["allow_link"],
146  (int) $a_attribs["allow_copy"],
147  (int) $a_attribs["rbac"],
148  (int) $a_attribs["default_pos"],
149  (int) $a_attribs["default_pres_pos"],
150  (int) $a_attribs["sideblock"],
151  $a_attribs["group"],
152  (int) $a_attribs["system"],
153  (int) $a_attribs["export"],
154  (int) $a_attribs["repository"],
155  (int) $a_attribs["workspace"],
156  (int) $a_attribs['administration'],
157  (int) $a_attribs['amet']
158  ));
159  break;
160 
161  case "subobj":
162  $ilDB->manipulateF("INSERT INTO il_object_subobj (parent, subobj, mmax) VALUES (%s,%s,%s)",
163  array("text", "text", "integer"),
164  array($this->current_object, $a_attribs["id"], (int) $a_attribs["max"]));
165  break;
166 
167  case "parent":
168  $ilDB->manipulateF("INSERT INTO il_object_subobj (parent, subobj, mmax) VALUES (%s,%s,%s)",
169  array("text", "text", "integer"),
170  array($a_attribs["id"], $this->current_object, (int) $a_attribs["max"]));
171  break;
172 
173  case "objectgroup":
174  $ilDB->manipulateF("INSERT INTO il_object_group (id, name, default_pres_pos) VALUES (%s,%s,%s)",
175  array("text", "text", "integer"),
176  array($a_attribs["id"], $a_attribs["name"], $a_attribs["default_pres_pos"]));
177  break;
178 
179  case "pluginslot":
180  $this->current_object = $a_attribs["id"];
181  $q = "INSERT INTO il_pluginslot (component, id, name) VALUES (".
182  $ilDB->quote($this->current_component, "text").",".
183  $ilDB->quote($a_attribs["id"], "text").",".
184  $ilDB->quote($a_attribs["name"], "text").")";
185  $ilDB->manipulate($q);
186  break;
187 
188  case "event":
189  $component = $a_attribs["component"];
190  if(!$component)
191  {
192  $component = $this->current_component;
193  }
194  $q = "INSERT INTO il_event_handling (component, type, id) VALUES (".
195  $ilDB->quote($component, "text").",".
196  $ilDB->quote($a_attribs["type"], "text").",".
197  $ilDB->quote($a_attribs["id"], "text").")";
198  $ilDB->manipulate($q);
199  break;
200 
201  case "cron":
202  $component = $a_attribs["component"];
203  if(!$component)
204  {
205  $component = $this->current_component;
206  }
207  include_once "Services/Cron/classes/class.ilCronManager.php";
208  ilCronManager::updateFromXML($component, $a_attribs["id"], $a_attribs["class"], $a_attribs["path"]);
209  $this->has_cron[$component][] = $a_attribs["id"];
210  break;
211 
212  case "sub_type":
213  $ilDB->manipulate("INSERT INTO il_object_sub_type ".
214  "(obj_type, sub_type, amet) VALUES (".
215  $ilDB->quote($this->current_object, "text").",".
216  $ilDB->quote($a_attribs["id"], "text").",".
217  $ilDB->quote($a_attribs["amet"], "integer").
218  ")");
219  break;
220  }
221  }
222  }
223 
230  function handlerEndTag($a_xml_parser,$a_name)
231  {
232  // call special reader
233  if ($this->current_reader != "")
234  {
235  $this->readers[$this->current_reader]["reader"]->handlerEndTag($a_xml_parser,$a_name);
236  }
237  else
238  {
239  // cron
240  if($a_name == "module" || $a_name == "service")
241  {
242  include_once "Services/Cron/classes/class.ilCronManager.php";
243  ilCronManager::clearFromXML($this->current_component,
244  (array)$this->has_cron[$this->current_component]);
245  }
246  }
247 
248  // check if a special reader needs to be activated
249  if (isset($this->readers[$a_name]))
250  {
251  $this->current_reader = null;
252  }
253  }
254 
255 
263  function handlerCharacterData($a_xml_parser,$a_data)
264  {
265  // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
266  $a_data = preg_replace("/\n/","",$a_data);
267  $a_data = preg_replace("/\t+/","",$a_data);
268 
269  if (!empty($a_data))
270  {
271  switch ($this->current_tag)
272  {
273  case '':
274  }
275  }
276  }
277 
278 }