ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilStructureObject.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
6 
18 {
19  var $is_alias;
21  var $tree;
22 
27  function ilStructureObject(&$a_content_obj, $a_id = 0)
28  {
29  $this->setType("st");
30  parent::ilLMObject($a_content_obj, $a_id);
31  }
32 
33  function create($a_upload = false)
34  {
35  parent::create($a_upload);
36  }
37 
41  function delete($a_delete_meta_data = true)
42  {
43  // only relevant for online help authoring
44  include_once("./Services/Help/classes/class.ilHelpMapping.php");
46 
47  $this->tree = new ilTree($this->getLmId());
48  $this->tree->setTableNames('lm_tree', 'lm_data');
49  $this->tree->setTreeTablePK("lm_id");
50  $node_data = $this->tree->getNodeData($this->getId());
51  $this->delete_rec($this->tree, $a_delete_meta_data);
52  $this->tree->deleteTree($node_data);
53  }
54 
58  private function delete_rec(&$a_tree, $a_delete_meta_data = true)
59  {
60  $childs = $a_tree->getChilds($this->getId());
61  foreach ($childs as $child)
62  {
63  $obj =& ilLMObjectFactory::getInstance($this->content_object, $child["obj_id"], false);
64  if (is_object($obj))
65  {
66  if($obj->getType() == "st")
67  {
68  $obj->delete_rec($a_tree, $a_delete_meta_data);
69  }
70  if($obj->getType() == "pg")
71  {
72  $obj->delete($a_delete_meta_data);
73  }
74  }
75  unset($obj);
76  }
77  parent::delete($a_delete_meta_data);
78  }
79 
83  function copy($a_target_lm)
84  {
85  $chap = new ilStructureObject($a_target_lm);
86  $chap->setTitle($this->getTitle());
87  if ($this->getLMId() != $a_target_lm->getId())
88  {
89  $chap->setImportId("il__st_".$this->getId());
90  }
91  $chap->setLMId($a_target_lm->getId());
92  $chap->setType($this->getType());
93  $chap->setDescription($this->getDescription());
94  $chap->create(true);
95  $a_copied_nodes[$this->getId()] = $chap->getId();
96 
97  // copy meta data
98  include_once("Services/MetaData/classes/class.ilMD.php");
99  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
100  $new_md =& $md->cloneMD($a_target_lm->getId(), $chap->getId(), $this->getType());
101 
102  return $chap;
103  }
104 
111  function exportXML(&$a_xml_writer, $a_inst, &$expLog)
112  {
113  global $ilBench;
114 
115  $expLog->write(date("[y-m-d H:i:s] ")."Structure Object ".$this->getId());
116  $attrs = array();
117  $a_xml_writer->xmlStartTag("StructureObject", $attrs);
118 
119  // MetaData
120  $ilBench->start("ContentObjectExport", "exportStructureObject_exportMeta");
121  $this->exportXMLMetaData($a_xml_writer);
122  $ilBench->stop("ContentObjectExport", "exportStructureObject_exportMeta");
123 
124  // StructureObjects
125  $ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjects");
126  $this->exportXMLPageObjects($a_xml_writer, $a_inst);
127  $ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjects");
128 
129  // PageObjects
130  $this->exportXMLStructureObjects($a_xml_writer, $a_inst, $expLog);
131 
132  // Layout
133  // not implemented
134 
135  $a_xml_writer->xmlEndTag("StructureObject");
136  }
137 
138 
145  function exportXMLMetaData(&$a_xml_writer)
146  {
147  include_once("Services/MetaData/classes/class.ilMD2XML.php");
148  $md2xml = new ilMD2XML($this->getLMId(), $this->getId(), $this->getType());
149  $md2xml->setExportMode(true);
150  $md2xml->startExport();
151  $a_xml_writer->appendXML($md2xml->getXML());
152  }
153 
154  function modifyExportIdentifier($a_tag, $a_param, $a_value)
155  {
156  if ($a_tag == "Identifier" && $a_param == "Entry")
157  {
158  $a_value = "il_".IL_INST_ID."_st_".$this->getId();
159  }
160 
161  return $a_value;
162  }
163 
168  function _getPresentationTitle($a_st_id, $a_include_numbers = false,
169  $a_time_scheduled_activation = false)
170  {
171  global $ilDB;
172 
173  // get chapter data
174  $query = "SELECT * FROM lm_data WHERE obj_id = ".
175  $ilDB->quote($a_st_id, "integer");
176  $st_set = $ilDB->query($query);
177  $st_rec = $ilDB->fetchAssoc($st_set);
178 
179  $tree = new ilTree($st_rec["lm_id"]);
180  $tree->setTableNames('lm_tree','lm_data');
181  $tree->setTreeTablePK("lm_id");
182 
183  if ($a_include_numbers)
184  {
185  if ($tree->isInTree($st_rec["obj_id"]))
186  {
187  // get chapter tree node
188  $query = "SELECT * FROM lm_tree WHERE child = ".
189  $ilDB->quote($a_st_id, "integer")." AND lm_id = ".
190  $ilDB->quote($st_rec["lm_id"], "integer");
191  $tree_set = $ilDB->query($query);
192  $tree_node = $tree_set->fetchRow(DB_FETCHMODE_ASSOC);
193  $depth = $tree_node["depth"];
194 
195  $nr = $tree->getChildSequenceNumber($tree_node, "st")." ";
196  for ($i = $depth - 1; $i > 1; $i --)
197  {
198  // get next parent tree node
199  $query = "SELECT * FROM lm_tree WHERE child = ".
200  $ilDB->quote($tree_node["parent"], "integer")." AND lm_id = ".
201  $ilDB->quote($st_rec["lm_id"], "integer");
202  $tree_set = $ilDB->query($query);
203  $tree_node = $tree_set->fetchRow(DB_FETCHMODE_ASSOC);
204  $seq = $tree->getChildSequenceNumber($tree_node, "st");
205 
206  $nr = $seq.".".$nr;
207  }
208  }
209  }
210 
211  return $nr.$st_rec["title"];
212  }
213 
214 
215 
222  function exportXMLPageObjects(&$a_xml_writer, $a_inst = 0)
223  {
224  include_once './Modules/LearningModule/classes/class.ilLMPageObject.php';
225 
226  global $ilBench;
227 
228  $this->tree = new ilTree($this->getLmId());
229  $this->tree->setTableNames('lm_tree', 'lm_data');
230  $this->tree->setTreeTablePK("lm_id");
231 
232  $childs = $this->tree->getChilds($this->getId());
233  foreach ($childs as $child)
234  {
235  if($child["type"] != "pg")
236  {
237  continue;
238  }
239 
240  // export xml to writer object
241  $ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
242  //$ilBench->start("ContentObjectExport", "exportStructureObject_getLMPageObject");
243  //$page_obj = new ilLMPageObject($this->getContentObject(), $child["obj_id"]);
244  //$ilBench->stop("ContentObjectExport", "exportStructureObject_getLMPageObject");
245  ilLMPageObject::_exportXMLAlias($a_xml_writer, $child["obj_id"], $a_inst);
246  //$page_obj->exportXML($a_xml_writer, "alias", $a_inst);
247  //unset($page_obj);
248  $ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
249  }
250  }
251 
252 
259  function exportXMLStructureObjects(&$a_xml_writer, $a_inst, &$expLog)
260  {
261  $this->tree = new ilTree($this->getLmId());
262  $this->tree->setTableNames('lm_tree', 'lm_data');
263  $this->tree->setTreeTablePK("lm_id");
264 
265  $childs = $this->tree->getChilds($this->getId());
266  foreach ($childs as $child)
267  {
268  if($child["type"] != "st")
269  {
270  continue;
271  }
272 
273  // export xml to writer object
274  $structure_obj = new ilStructureObject($this->getContentObject(),
275  $child["obj_id"]);
276  $structure_obj->exportXML($a_xml_writer, $a_inst, $expLog);
277  unset($structure_obj);
278  }
279  }
280 
287  function exportFO(&$a_xml_writer)
288  {
289  global $ilBench;
290 
291  //$expLog->write(date("[y-m-d H:i:s] ")."Structure Object ".$this->getId());
292 
293  // fo:block (complete)
294  $attrs = array();
295  $attrs["font-family"] = "Times";
296  $attrs["font-size"] = "14pt";
297  $a_xml_writer->xmlElement("fo:block", $attrs, $this->getTitle());
298 
299  // page objects
300  //$ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjects");
301  $this->exportFOPageObjects($a_xml_writer);
302  //$ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjects");
303 
304  // structure objects
305  //$this->exportFOStructureObjects($a_xml_writer);
306 
307  }
308 
315  function exportFOPageObjects(&$a_xml_writer)
316  {
317  global $ilBench;
318 
319  $this->tree = new ilTree($this->getLmId());
320  $this->tree->setTableNames('lm_tree', 'lm_data');
321  $this->tree->setTreeTablePK("lm_id");
322 
323  $childs = $this->tree->getChilds($this->getId());
324  foreach ($childs as $child)
325  {
326  if($child["type"] != "pg")
327  {
328  continue;
329  }
330 
331  // export xml to writer object
332  //$ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
333 
334  $page_obj = new ilLMPageObject($this->getContentObject(), $child["obj_id"]);
335  $page_obj->exportFO($a_xml_writer);
336 
337  //$ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
338  }
339  }
340 
347  static function getChapterList($a_lm_id)
348  {
349  $tree = new ilTree($a_lm_id);
350  $tree->setTableNames('lm_tree', 'lm_data');
351  $tree->setTreeTablePK("lm_id");
352 
353  $chapters = array();
354  $ndata = $tree->getNodeData($tree->readRootId());
355  $childs = $tree->getSubtree($ndata);
356  foreach ($childs as $child)
357  {
358  if($child["type"] == "st")
359  {
360  $chapters[] = $child;
361  }
362 
363  }
364  return $chapters;
365  }
366 
367 }
368 ?>