ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilStructureObject.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2009 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 require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
25 
37 {
38  var $is_alias;
40  var $tree;
41 
46  function ilStructureObject(&$a_content_obj, $a_id = 0)
47  {
48  $this->setType("st");
49  parent::ilLMObject($a_content_obj, $a_id);
50  }
51 
52  function create($a_upload = false)
53  {
54  parent::create($a_upload);
55  }
56 
60  function delete($a_delete_meta_data = true)
61  {
62  $this->tree = new ilTree($this->getLmId());
63  $this->tree->setTableNames('lm_tree', 'lm_data');
64  $this->tree->setTreeTablePK("lm_id");
65  $node_data = $this->tree->getNodeData($this->getId());
66  $this->delete_rec($this->tree, $a_delete_meta_data);
67  $this->tree->deleteTree($node_data);
68  }
69 
73  private function delete_rec(&$a_tree, $a_delete_meta_data = true)
74  {
75  $childs = $a_tree->getChilds($this->getId());
76  foreach ($childs as $child)
77  {
78  $obj =& ilLMObjectFactory::getInstance($this->content_object, $child["obj_id"], false);
79  if (is_object($obj))
80  {
81  if($obj->getType() == "st")
82  {
83  $obj->delete_rec($a_tree, $a_delete_meta_data);
84  }
85  if($obj->getType() == "pg")
86  {
87  $obj->delete($a_delete_meta_data);
88  }
89  }
90  unset($obj);
91  }
92  parent::delete($a_delete_meta_data);
93  }
94 
98  function copy($a_target_lm)
99  {
100  $chap = new ilStructureObject($a_target_lm);
101  $chap->setTitle($this->getTitle());
102  if ($this->getLMId() != $a_target_lm->getId())
103  {
104  $chap->setImportId("il__st_".$this->getId());
105  }
106  $chap->setLMId($a_target_lm->getId());
107  $chap->setType($this->getType());
108  $chap->setDescription($this->getDescription());
109  $chap->create(true);
110  $a_copied_nodes[$this->getId()] = $chap->getId();
111 
112  // copy meta data
113  include_once("Services/MetaData/classes/class.ilMD.php");
114  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
115  $new_md =& $md->cloneMD($a_target_lm->getId(), $chap->getId(), $this->getType());
116 
117  return $chap;
118  }
119 
126  function exportXML(&$a_xml_writer, $a_inst, &$expLog)
127  {
128  global $ilBench;
129 
130  $expLog->write(date("[y-m-d H:i:s] ")."Structure Object ".$this->getId());
131  $attrs = array();
132  $a_xml_writer->xmlStartTag("StructureObject", $attrs);
133 
134  // MetaData
135  $ilBench->start("ContentObjectExport", "exportStructureObject_exportMeta");
136  $this->exportXMLMetaData($a_xml_writer);
137  $ilBench->stop("ContentObjectExport", "exportStructureObject_exportMeta");
138 
139  // StructureObjects
140  $ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjects");
141  $this->exportXMLPageObjects($a_xml_writer, $a_inst);
142  $ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjects");
143 
144  // PageObjects
145  $this->exportXMLStructureObjects($a_xml_writer, $a_inst, $expLog);
146 
147  // Layout
148  // not implemented
149 
150  $a_xml_writer->xmlEndTag("StructureObject");
151  }
152 
153 
160  function exportXMLMetaData(&$a_xml_writer)
161  {
162  include_once("Services/MetaData/classes/class.ilMD2XML.php");
163  $md2xml = new ilMD2XML($this->getLMId(), $this->getId(), $this->getType());
164  $md2xml->setExportMode(true);
165  $md2xml->startExport();
166  $a_xml_writer->appendXML($md2xml->getXML());
167  }
168 
169  function modifyExportIdentifier($a_tag, $a_param, $a_value)
170  {
171  if ($a_tag == "Identifier" && $a_param == "Entry")
172  {
173  $a_value = "il_".IL_INST_ID."_st_".$this->getId();
174  }
175 
176  return $a_value;
177  }
178 
183  function _getPresentationTitle($a_st_id, $a_include_numbers = false,
184  $a_time_scheduled_activation = false)
185  {
186  global $ilDB;
187 
188  // get chapter data
189  $query = "SELECT * FROM lm_data WHERE obj_id = ".
190  $ilDB->quote($a_st_id, "integer");
191  $st_set = $ilDB->query($query);
192  $st_rec = $ilDB->fetchAssoc($st_set);
193 
194  $tree = new ilTree($st_rec["lm_id"]);
195  $tree->setTableNames('lm_tree','lm_data');
196  $tree->setTreeTablePK("lm_id");
197 
198  if ($a_include_numbers)
199  {
200  if ($tree->isInTree($st_rec["obj_id"]))
201  {
202  // get chapter tree node
203  $query = "SELECT * FROM lm_tree WHERE child = ".
204  $ilDB->quote($a_st_id, "integer")." AND lm_id = ".
205  $ilDB->quote($st_rec["lm_id"], "integer");
206  $tree_set = $ilDB->query($query);
207  $tree_node = $tree_set->fetchRow(DB_FETCHMODE_ASSOC);
208  $depth = $tree_node["depth"];
209 
210  $nr = $tree->getChildSequenceNumber($tree_node, "st")." ";
211  for ($i = $depth - 1; $i > 1; $i --)
212  {
213  // get next parent tree node
214  $query = "SELECT * FROM lm_tree WHERE child = ".
215  $ilDB->quote($tree_node["parent"], "integer")." AND lm_id = ".
216  $ilDB->quote($st_rec["lm_id"], "integer");
217  $tree_set = $ilDB->query($query);
218  $tree_node = $tree_set->fetchRow(DB_FETCHMODE_ASSOC);
219  $seq = $tree->getChildSequenceNumber($tree_node, "st");
220 
221  $nr = $seq.".".$nr;
222  }
223  }
224  }
225 
226  return $nr.$st_rec["title"];
227  }
228 
229 
230 
237  function exportXMLPageObjects(&$a_xml_writer, $a_inst = 0)
238  {
239  include_once './Modules/LearningModule/classes/class.ilLMPageObject.php';
240 
241  global $ilBench;
242 
243  $this->tree = new ilTree($this->getLmId());
244  $this->tree->setTableNames('lm_tree', 'lm_data');
245  $this->tree->setTreeTablePK("lm_id");
246 
247  $childs = $this->tree->getChilds($this->getId());
248  foreach ($childs as $child)
249  {
250  if($child["type"] != "pg")
251  {
252  continue;
253  }
254 
255  // export xml to writer object
256  $ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
257  //$ilBench->start("ContentObjectExport", "exportStructureObject_getLMPageObject");
258  //$page_obj = new ilLMPageObject($this->getContentObject(), $child["obj_id"]);
259  //$ilBench->stop("ContentObjectExport", "exportStructureObject_getLMPageObject");
260  ilLMPageObject::_exportXMLAlias($a_xml_writer, $child["obj_id"], $a_inst);
261  //$page_obj->exportXML($a_xml_writer, "alias", $a_inst);
262  //unset($page_obj);
263  $ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
264  }
265  }
266 
267 
274  function exportXMLStructureObjects(&$a_xml_writer, $a_inst, &$expLog)
275  {
276  $this->tree = new ilTree($this->getLmId());
277  $this->tree->setTableNames('lm_tree', 'lm_data');
278  $this->tree->setTreeTablePK("lm_id");
279 
280  $childs = $this->tree->getChilds($this->getId());
281  foreach ($childs as $child)
282  {
283  if($child["type"] != "st")
284  {
285  continue;
286  }
287 
288  // export xml to writer object
289  $structure_obj = new ilStructureObject($this->getContentObject(),
290  $child["obj_id"]);
291  $structure_obj->exportXML($a_xml_writer, $a_inst, $expLog);
292  unset($structure_obj);
293  }
294  }
295 
302  function exportFO(&$a_xml_writer)
303  {
304  global $ilBench;
305 
306  //$expLog->write(date("[y-m-d H:i:s] ")."Structure Object ".$this->getId());
307 
308  // fo:block (complete)
309  $attrs = array();
310  $attrs["font-family"] = "Times";
311  $attrs["font-size"] = "14pt";
312  $a_xml_writer->xmlElement("fo:block", $attrs, $this->getTitle());
313 
314  // page objects
315  //$ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjects");
316  $this->exportFOPageObjects($a_xml_writer);
317  //$ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjects");
318 
319  // structure objects
320  //$this->exportFOStructureObjects($a_xml_writer);
321 
322  }
323 
330  function exportFOPageObjects(&$a_xml_writer)
331  {
332  global $ilBench;
333 
334  $this->tree = new ilTree($this->getLmId());
335  $this->tree->setTableNames('lm_tree', 'lm_data');
336  $this->tree->setTreeTablePK("lm_id");
337 
338  $childs = $this->tree->getChilds($this->getId());
339  foreach ($childs as $child)
340  {
341  if($child["type"] != "pg")
342  {
343  continue;
344  }
345 
346  // export xml to writer object
347  //$ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
348 
349  $page_obj = new ilLMPageObject($this->getContentObject(), $child["obj_id"]);
350  $page_obj->exportFO($a_xml_writer);
351 
352  //$ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
353  }
354  }
355 
356 }
357 ?>