ILIAS  Release_3_10_x_branch Revision 61812
 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-2006 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  {
185  global $ilDB;
186 
187  // get chapter data
188  $query = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($a_st_id);
189  $st_set = $ilDB->query($query);
190  $st_rec = $st_set->fetchRow(DB_FETCHMODE_ASSOC);
191 
192  $tree = new ilTree($st_rec["lm_id"]);
193  $tree->setTableNames('lm_tree','lm_data');
194  $tree->setTreeTablePK("lm_id");
195 
196  if ($a_include_numbers)
197  {
198  if ($tree->isInTree($st_rec["obj_id"]))
199  {
200  // get chapter tree node
201  $query = "SELECT * FROM lm_tree WHERE child = ".
202  $ilDB->quote($a_st_id)." AND lm_id = ".
203  $ilDB->quote($st_rec["lm_id"]);
204  $tree_set = $ilDB->query($query);
205  $tree_node = $tree_set->fetchRow(DB_FETCHMODE_ASSOC);
206  $depth = $tree_node["depth"];
207 
208  $nr = $tree->getChildSequenceNumber($tree_node, "st")." ";
209  for ($i = $depth - 1; $i > 1; $i --)
210  {
211  // get next parent tree node
212  $query = "SELECT * FROM lm_tree WHERE child = ".
213  $ilDB->quote($tree_node["parent"])." AND lm_id = ".
214  $ilDB->quote($st_rec["lm_id"]);
215  $tree_set = $ilDB->query($query);
216  $tree_node = $tree_set->fetchRow(DB_FETCHMODE_ASSOC);
217  $seq = $tree->getChildSequenceNumber($tree_node, "st");
218 
219  $nr = $seq.".".$nr;
220  }
221  }
222  }
223 
224  return $nr.$st_rec["title"];
225  }
226 
227 
228 
235  function exportXMLPageObjects(&$a_xml_writer, $a_inst = 0)
236  {
237  include_once './Modules/LearningModule/classes/class.ilLMPageObject.php';
238 
239  global $ilBench;
240 
241  $this->tree = new ilTree($this->getLmId());
242  $this->tree->setTableNames('lm_tree', 'lm_data');
243  $this->tree->setTreeTablePK("lm_id");
244 
245  $childs = $this->tree->getChilds($this->getId());
246  foreach ($childs as $child)
247  {
248  if($child["type"] != "pg")
249  {
250  continue;
251  }
252 
253  // export xml to writer object
254  $ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
255  //$ilBench->start("ContentObjectExport", "exportStructureObject_getLMPageObject");
256  //$page_obj = new ilLMPageObject($this->getContentObject(), $child["obj_id"]);
257  //$ilBench->stop("ContentObjectExport", "exportStructureObject_getLMPageObject");
258  ilLMPageObject::_exportXMLAlias($a_xml_writer, $child["obj_id"], $a_inst);
259  //$page_obj->exportXML($a_xml_writer, "alias", $a_inst);
260  //unset($page_obj);
261  $ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
262  }
263  }
264 
265 
272  function exportXMLStructureObjects(&$a_xml_writer, $a_inst, &$expLog)
273  {
274  $this->tree = new ilTree($this->getLmId());
275  $this->tree->setTableNames('lm_tree', 'lm_data');
276  $this->tree->setTreeTablePK("lm_id");
277 
278  $childs = $this->tree->getChilds($this->getId());
279  foreach ($childs as $child)
280  {
281  if($child["type"] != "st")
282  {
283  continue;
284  }
285 
286  // export xml to writer object
287  $structure_obj = new ilStructureObject($this->getContentObject(),
288  $child["obj_id"]);
289  $structure_obj->exportXML($a_xml_writer, $a_inst, $expLog);
290  unset($structure_obj);
291  }
292  }
293 
300  function exportFO(&$a_xml_writer)
301  {
302  global $ilBench;
303 
304  //$expLog->write(date("[y-m-d H:i:s] ")."Structure Object ".$this->getId());
305 
306  // fo:block (complete)
307  $attrs = array();
308  $attrs["font-family"] = "Times";
309  $attrs["font-size"] = "14pt";
310  $a_xml_writer->xmlElement("fo:block", $attrs, $this->getTitle());
311 
312  // page objects
313  //$ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjects");
314  $this->exportFOPageObjects($a_xml_writer);
315  //$ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjects");
316 
317  // structure objects
318  //$this->exportFOStructureObjects($a_xml_writer);
319 
320  }
321 
328  function exportFOPageObjects(&$a_xml_writer)
329  {
330  global $ilBench;
331 
332  $this->tree = new ilTree($this->getLmId());
333  $this->tree->setTableNames('lm_tree', 'lm_data');
334  $this->tree->setTreeTablePK("lm_id");
335 
336  $childs = $this->tree->getChilds($this->getId());
337  foreach ($childs as $child)
338  {
339  if($child["type"] != "pg")
340  {
341  continue;
342  }
343 
344  // export xml to writer object
345  //$ilBench->start("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
346 
347  $page_obj = new ilLMPageObject($this->getContentObject(), $child["obj_id"]);
348  $page_obj->exportFO($a_xml_writer);
349 
350  //$ilBench->stop("ContentObjectExport", "exportStructureObject_exportPageObjectAlias");
351  }
352  }
353 
354 }
355 ?>