ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  public $is_alias;
20  public $origin_id;
21  public $tree;
22 
27  public function __construct(&$a_content_obj, $a_id = 0)
28  {
29  $this->setType("st");
30  parent::__construct($a_content_obj, $a_id);
31  }
32 
33  public function create($a_upload = false)
34  {
35  parent::create($a_upload);
36  }
37 
41  public 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  $obj = ilLMObjectFactory::getInstance($this->content_object, $child["obj_id"], false);
63  if (is_object($obj)) {
64  if ($obj->getType() == "st") {
65  $obj->delete_rec($a_tree, $a_delete_meta_data);
66  }
67  if ($obj->getType() == "pg") {
68  $obj->delete($a_delete_meta_data);
69  }
70  }
71  unset($obj);
72  }
73  parent::delete($a_delete_meta_data);
74  }
75 
79  public function copy($a_target_lm)
80  {
81  $chap = new ilStructureObject($a_target_lm);
82  $chap->setTitle($this->getTitle());
83  if ($this->getLMId() != $a_target_lm->getId()) {
84  $chap->setImportId("il__st_" . $this->getId());
85  }
86  $chap->setLMId($a_target_lm->getId());
87  $chap->setType($this->getType());
88  $chap->setDescription($this->getDescription());
89  $chap->create(true);
90  $a_copied_nodes[$this->getId()] = $chap->getId();
91 
92  // copy meta data
93  include_once("Services/MetaData/classes/class.ilMD.php");
94  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
95  $new_md = $md->cloneMD($a_target_lm->getId(), $chap->getId(), $this->getType());
96 
97  // copy translations
98  include_once("./Modules/LearningModule/classes/class.ilLMObjTranslation.php");
99  ilLMObjTranslation::copy($this->getId(), $chap->getId());
100 
101 
102  return $chap;
103  }
104 
111  public function exportXML(&$a_xml_writer, $a_inst, &$expLog)
112  {
113  $expLog->write(date("[y-m-d H:i:s] ") . "Structure Object " . $this->getId());
114  $attrs = array();
115  $a_xml_writer->xmlStartTag("StructureObject", $attrs);
116 
117  // MetaData
118  $this->exportXMLMetaData($a_xml_writer);
119 
120  // StructureObjects
121  $this->exportXMLPageObjects($a_xml_writer, $a_inst);
122 
123  // PageObjects
124  $this->exportXMLStructureObjects($a_xml_writer, $a_inst, $expLog);
125 
126  // Layout
127  // not implemented
128 
129  $a_xml_writer->xmlEndTag("StructureObject");
130  }
131 
132 
139  public function exportXMLMetaData(&$a_xml_writer)
140  {
141  include_once("Services/MetaData/classes/class.ilMD2XML.php");
142  $md2xml = new ilMD2XML($this->getLMId(), $this->getId(), $this->getType());
143  $md2xml->setExportMode(true);
144  $md2xml->startExport();
145  $a_xml_writer->appendXML($md2xml->getXML());
146  }
147 
148  public function modifyExportIdentifier($a_tag, $a_param, $a_value)
149  {
150  if ($a_tag == "Identifier" && $a_param == "Entry") {
151  $a_value = "il_" . IL_INST_ID . "_st_" . $this->getId();
152  }
153 
154  return $a_value;
155  }
156 
161  public static function _getPresentationTitle(
162  $a_st_id,
163  $a_mode = IL_CHAPTER_TITLE,
164  $a_include_numbers = false,
165  $a_time_scheduled_activation = false,
166  $a_force_content = false,
167  $a_lm_id = 0,
168  $a_lang = "-",
169  $a_include_short = false
170  ) {
171  global $DIC;
172 
173  $ilDB = $DIC->database();
174 
175  if ($a_lm_id == 0) {
176  $a_lm_id = ilLMObject::_lookupContObjID($a_st_id);
177  }
178 
179  if ($a_lm_id == 0) {
180  return "";
181  }
182 
183  // this is optimized when ilLMObject::preloadDataByLM is invoked (e.g. done in ilLMExplorerGUI)
184  $title = "";
185  if ($a_include_short) {
186  $title = trim(ilLMObject::_lookupShortTitle($a_st_id));
187  }
188  if ($title == "") {
189  $title = ilLMObject::_lookupTitle($a_st_id);
190  }
191 
192  // this is also optimized since ilObjectTranslation re-uses instances for one lm
193  include_once("./Services/Object/classes/class.ilObjectTranslation.php");
194  $ot = ilObjectTranslation::getInstance($a_lm_id);
195  $languages = $ot->getLanguages();
196 
197  if ($a_lang != "-" && $ot->getContentActivated() && isset($languages[$a_lang])) {
198  include_once("./Modules/LearningModule/classes/class.ilLMObjTranslation.php");
199  $lmobjtrans = new ilLMObjTranslation($a_st_id, $a_lang);
200  $trans_title = "";
201  if ($a_include_short) {
202  $trans_title = trim($lmobjtrans->getShortTitle());
203  }
204  if ($trans_title == "") {
205  $trans_title = $lmobjtrans->getTitle();
206  }
207  if ($trans_title != "") {
208  $title = $trans_title;
209  }
210  }
211 
212  include_once("./Modules/LearningModule/classes/class.ilLMTree.php");
213  $tree = ilLMTree::getInstance($a_lm_id);
214 
215  if ($a_include_numbers) {
216  // this is optimized, since isInTree is cached
217  if ($tree->isInTree($a_st_id)) {
218  // optimization needed from here
219 
220  // get chapter tree node
221  $query = "SELECT * FROM lm_tree WHERE child = " .
222  $ilDB->quote($a_st_id, "integer") . " AND lm_id = " .
223  $ilDB->quote($a_lm_id, "integer");
224  $tree_set = $ilDB->query($query);
225  $tree_node = $tree_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
226  $depth = $tree_node["depth"];
227 
228  $nr = $tree->getChildSequenceNumber($tree_node, "st") . " ";
229  for ($i = $depth - 1; $i > 1; $i--) {
230  // get next parent tree node
231  $query = "SELECT * FROM lm_tree WHERE child = " .
232  $ilDB->quote($tree_node["parent"], "integer") . " AND lm_id = " .
233  $ilDB->quote($a_lm_id, "integer");
234  $tree_set = $ilDB->query($query);
235  $tree_node = $tree_set->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
236  $seq = $tree->getChildSequenceNumber($tree_node, "st");
237 
238  $nr = $seq . "." . $nr;
239  }
240  }
241  }
242 
243  return $nr . $title;
244  }
245 
246 
247 
254  public function exportXMLPageObjects(&$a_xml_writer, $a_inst = 0)
255  {
256  include_once './Modules/LearningModule/classes/class.ilLMPageObject.php';
257 
258  $this->tree = new ilTree($this->getLmId());
259  $this->tree->setTableNames('lm_tree', 'lm_data');
260  $this->tree->setTreeTablePK("lm_id");
261 
262  $childs = $this->tree->getChilds($this->getId());
263  foreach ($childs as $child) {
264  if ($child["type"] != "pg") {
265  continue;
266  }
267 
268  // export xml to writer object
269  ilLMPageObject::_exportXMLAlias($a_xml_writer, $child["obj_id"], $a_inst);
270  }
271  }
272 
273 
280  public function exportXMLStructureObjects(&$a_xml_writer, $a_inst, &$expLog)
281  {
282  $this->tree = new ilTree($this->getLmId());
283  $this->tree->setTableNames('lm_tree', 'lm_data');
284  $this->tree->setTreeTablePK("lm_id");
285 
286  $childs = $this->tree->getChilds($this->getId());
287  foreach ($childs as $child) {
288  if ($child["type"] != "st") {
289  continue;
290  }
291 
292  // export xml to writer object
293  $structure_obj = new ilStructureObject(
294  $this->getContentObject(),
295  $child["obj_id"]
296  );
297  $structure_obj->exportXML($a_xml_writer, $a_inst, $expLog);
298  unset($structure_obj);
299  }
300  }
301 
308  public function exportFO(&$a_xml_writer)
309  {
310 
311  // fo:block (complete)
312  $attrs = array();
313  $attrs["font-family"] = "Times";
314  $attrs["font-size"] = "14pt";
315  $a_xml_writer->xmlElement("fo:block", $attrs, $this->getTitle());
316 
317  // page objects
318  $this->exportFOPageObjects($a_xml_writer);
319  }
320 
327  public function exportFOPageObjects(&$a_xml_writer)
328  {
329  $this->tree = new ilTree($this->getLmId());
330  $this->tree->setTableNames('lm_tree', 'lm_data');
331  $this->tree->setTreeTablePK("lm_id");
332 
333  $childs = $this->tree->getChilds($this->getId());
334  foreach ($childs as $child) {
335  if ($child["type"] != "pg") {
336  continue;
337  }
338 
339  // export xml to writer object
340  $page_obj = new ilLMPageObject($this->getContentObject(), $child["obj_id"]);
341  $page_obj->exportFO($a_xml_writer);
342  }
343  }
344 
351  public static function getChapterList($a_lm_id)
352  {
353  $tree = new ilTree($a_lm_id);
354  $tree->setTableNames('lm_tree', 'lm_data');
355  $tree->setTreeTablePK("lm_id");
356 
357  $chapters = array();
358  $ndata = $tree->getNodeData($tree->readRootId());
359  $childs = $tree->getSubtree($ndata);
360  foreach ($childs as $child) {
361  if ($child["type"] == "st") {
362  $chapters[] = $child;
363  }
364  }
365  return $chapters;
366  }
367 }
static getChapterList($a_lm_id)
export (sub)structure objects of structure object (see ilias_co.dtd)
__construct(&$a_content_obj, $a_id=0)
Constructor public.
setType($a_type)
global $DIC
Definition: saml.php:7
static _lookupShortTitle($a_obj_id)
Lookup short title.
static _lookupContObjID($a_id)
get learning module / digibook id for lm object
static removeScreenIdsOfChapter($a_chap, $a_module_id=0)
Remove screen ids of chapter.
delete_rec(&$a_tree, $a_delete_meta_data=true)
Delete sub tree.
static _lookupTitle($a_obj_id)
Lookup title.
static _getPresentationTitle( $a_st_id, $a_mode=IL_CHAPTER_TITLE, $a_include_numbers=false, $a_time_scheduled_activation=false, $a_force_content=false, $a_lm_id=0, $a_lang="-", $a_include_short=false)
get presentation title
Class ilLMPageObject.
modifyExportIdentifier($a_tag, $a_param, $a_value)
static getInstance($a_tree_id)
Get Instance.
static getInstance(&$a_content_obj, $a_id=0, $a_halt=true)
exportXML(&$a_xml_writer, $a_inst, &$expLog)
export object to xml (see ilias_co.dtd)
exportXMLMetaData(&$a_xml_writer)
export structure objects meta data to xml (see ilias_co.dtd)
$query
exportXMLStructureObjects(&$a_xml_writer, $a_inst, &$expLog)
export (sub)structure objects of structure object (see ilias_co.dtd)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
copy($a_target_lm)
copy chapter
exportFOPageObjects(&$a_xml_writer)
export page objects of structure object (see ilias_co.dtd)
getTitle()
get title of lm object
Class ilStructreObject.
static getInstance($a_obj_id)
Get instance.
global $ilDB
exportXMLPageObjects(&$a_xml_writer, $a_inst=0)
export page objects of structure object (see ilias_co.dtd)
$i
Definition: disco.tpl.php:19
static _exportXMLAlias(&$a_xml_writer, $a_id, $a_inst=0)
export page alias to xml
const IL_CHAPTER_TITLE
$languages
Definition: cssgen2.php:34
Translation information on lm object.
Class ilLMObject.
exportFO(&$a_xml_writer)
export object to fo
static copy($a_source_id, $a_target_id)
Copy all translations of an object.