ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSCORM2004PageNode.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once("./Modules/Scorm2004/classes/class.ilSCORM2004Node.php");
5 require_once("./Services/COPage/classes/class.ilPageObject.php");
6 
7 // unclear whether we need this somehow...
8 //define ("IL_CHAPTER_TITLE", "st_title");
9 //define ("IL_PAGE_TITLE", "pg_title");
10 //define ("IL_NO_HEADER", "none");
11 
31 {
32  var $id;
34 
39  function ilSCORM2004PageNode($a_slm_object, $a_id = 0)
40  {
41  parent::ilSCORM2004Node($a_slm_object, $a_id);
42  $this->setType("page");
43  $this->id = $a_id;
44 
45  $this->mobs_contained = array();
46  $this->files_contained = array();
47 
48  if($a_id != 0)
49  {
50  $this->read();
51  }
52  }
53 
57  function __descruct()
58  {
59  if(is_object($this->page_object))
60  {
61  unset($this->page_object);
62  }
63  }
64 
68  function read()
69  {
70  parent::read();
71 
72  $this->page_object = new ilPageObject($this->slm_object->getType(),
73  $this->id, 0, false);
74  }
75 
81  function create($a_upload = false,$a_layout_id = 0)
82  {
83  parent::create($a_upload);
84 
85  // create scorm2004 page
86  include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Page.php");
87  if(!is_object($this->page_object))
88  {
89  $this->page_object =& new ilSCORM2004Page($this->slm_object->getType());
90  }
91  $this->page_object->setId($this->getId());
92  $this->page_object->setParentId($this->getSLMId());
93  if ($a_layout_id == 0) {
94  $this->page_object->create($a_upload);
95  } else{
96  $this->page_object->createWithLayoutId($a_layout_id);
97  }
98  }
99 
105  function delete($a_delete_meta_data = true)
106  {
107  parent::delete($a_delete_meta_data);
108  $this->page_object->delete();
109  }
110 
111 
115  function copy($a_target_slm)
116  {
117  // copy page
118  $slm_page = new ilSCORM2004PageNode($a_target_slm);
119  $slm_page->setTitle($this->getTitle());
120  $slm_page->setSLMId($a_target_slm->getId());
121  $slm_page->setType($this->getType());
122  $slm_page->setDescription($this->getDescription());
123  $slm_page->setImportId("il__page_".$this->getId());
124  $slm_page->create(true); // setting "upload" flag to true prevents creating of meta data
125 
126  // copy meta data
127  include_once("Services/MetaData/classes/class.ilMD.php");
128  $md = new ilMD($this->getSLMId(), $this->getId(), $this->getType());
129  $new_md = $md->cloneMD($a_target_slm->getId(), $slm_page->getId(), $this->getType());
130 
131  // copy page content
132  $page = $slm_page->getPageObject();
133  // clone media objects, if source and target lm are not the same
134  $clone_mobs = ($this->getSLMId() == $a_target_slm->getId())
135  ? false
136  : true;
137 
138  $page->setXMLContent($this->page_object->copyXMLContent($clone_mobs));
139  $page->buildDom();
140  $page->update();
141 
142  return $slm_page;
143  }
144 
148  function &copyToOtherContObject(&$a_cont_obj)
149  {
150  // @todo
151  /*
152  // copy page
153  $lm_page =& new ilLMPageObject($a_cont_obj);
154  $lm_page->setTitle($this->getTitle());
155  $lm_page->setLMId($a_cont_obj->getId());
156  $lm_page->setType($this->getType());
157  $lm_page->setDescription($this->getDescription());
158  $lm_page->create(true); // setting "upload" flag to true prevents creating of meta data
159 
160  // copy meta data
161  include_once("Services/MetaData/classes/class.ilMD.php");
162  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
163  $new_md =& $md->cloneMD($a_cont_obj->getId(), $lm_page->getId(), $this->getType());
164 
165  // copy page content
166  $page =& $lm_page->getPageObject();
167  $page->setXMLContent($this->page_object->getXMLContent());
168  $page->buildDom();
169  $page->update();
170 
171  return $lm_page;
172  */
173  }
174 
182  function _splitPage($a_page_id, $a_pg_parent_type, $a_hier_id)
183  {
184  // @todo: This has to be checked, maybe abandoned or generalized?
185  /*
186  // get content object (learning module / digilib book)
187  $lm_id = ilLMObject::_lookupContObjID($a_page_id);
188  $type = ilObject::_lookupType($lm_id, false);
189  switch ($type)
190  {
191  case "lm":
192  include_once ("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
193  $cont_obj = new ilObjLearningModule($lm_id, false);
194  break;
195 
196  case "dbk":
197  include_once ("./Modules/LearningModule/classes/class.ilObjDlBook.php");
198  $cont_obj = new ilObjDlBook($lm_id, false);
199  break;
200  }
201 
202  $source_lm_page =& new ilLMPageObject($cont_obj, $a_page_id);
203 
204  // create new page
205  $lm_page =& new ilLMPageObject($cont_obj);
206  $lm_page->setTitle($source_lm_page->getTitle());
207  $lm_page->setLMId($source_lm_page->getLMId());
208  $lm_page->setType($source_lm_page->getType());
209  $lm_page->setDescription($source_lm_page->getDescription());
210  $lm_page->create(true);
211 
212  // copy meta data
213  include_once("Services/MetaData/classes/class.ilMD.php");
214  $md = new ilMD($source_lm_page->getLMId(), $a_page_id, $source_lm_page->getType());
215  $new_md =& $md->cloneMD($source_lm_page->getLMId(), $lm_page->getId(), $source_lm_page->getType());
216 
217  // copy complete content of source page to new page
218  $source_page =& $source_lm_page->getPageObject();
219  $page =& $lm_page->getPageObject();
220  $page->setXMLContent($source_page->getXMLContent());
221  $page->buildDom();
222 
223  // insert new page in tree (after original page)
224  $tree = new ilTree($cont_obj->getId());
225  $tree->setTableNames('lm_tree','lm_data');
226  $tree->setTreeTablePK("lm_id");
227  if ($tree->isInTree($source_lm_page->getId()))
228  {
229  $parent_node = $tree->getParentNodeData($source_lm_page->getId());
230  $tree->insertNode($lm_page->getId(), $parent_node["child"], $source_lm_page->getId());
231  }
232 
233  // remove all nodes < hierarchical id from new page (incl. update)
234  $page->addHierIds();
235  $page->deleteContentBeforeHierId($a_hier_id);
236 
237  // remove all nodes >= hierarchical id from source page
238  $source_page->buildDom();
239  $source_page->addHierIds();
240  $source_page->deleteContentFromHierId($a_hier_id);
241 
242  return $lm_page;
243  */
244  }
245 
253  // @todo: This has to be checked, maybe abandoned or generalized?
254  /*
255  function _splitPageNext($a_page_id, $a_pg_parent_type, $a_hier_id)
256  {
257  // get content object (learning module / digilib book)
258  $lm_id = ilLMObject::_lookupContObjID($a_page_id);
259  $type = ilObject::_lookupType($lm_id, false);
260  switch ($type)
261  {
262  case "lm":
263  include_once ("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
264  $cont_obj = new ilObjLearningModule($lm_id, false);
265  break;
266 
267  case "dbk":
268  include_once ("./Modules/LearningModule/classes/class.ilObjDlBook.php");
269  $cont_obj = new ilObjDlBook($lm_id, false);
270  break;
271  }
272  $tree = new ilTree($cont_obj->getId());
273  $tree->setTableNames('lm_tree','lm_data');
274  $tree->setTreeTablePK("lm_id");
275 
276  $source_lm_page =& new ilLMPageObject($cont_obj, $a_page_id);
277  $source_page =& $source_lm_page->getPageObject();
278 
279  // get next page
280  $succ = $tree->fetchSuccessorNode($a_page_id, "pg");
281  if ($succ["child"] > 0)
282  {
283  $target_lm_page =& new ilLMPageObject($cont_obj, $succ["child"]);
284  $target_page =& $target_lm_page->getPageObject();
285  $target_page->buildDom();
286  $target_page->addHierIds();
287 
288  // move nodes to target page
289  $source_page->buildDom();
290  $source_page->addHierIds();
291  ilPageObject::_moveContentAfterHierId($source_page, $target_page, $a_hier_id);
292  //$source_page->deleteContentFromHierId($a_hier_id);
293 
294  return $succ["child"];
295  }
296 
297  }
298  */
299 
305  function assignPageObject(&$a_page_obj)
306  {
307  $this->page_object =& $a_page_obj;
308  }
309 
310 
316  function &getPageObject()
317  {
318  return $this->page_object;
319  }
320 
321 
327  function setId($a_id)
328  {
329  $this->id = $a_id;
330  }
331 
337  function getId()
338  {
339  return $this->id;
340  }
341 
345  function setAlias($a_is_alias)
346  {
347  $this->is_alias = $a_is_alias;
348  }
349 
350  function isAlias()
351  {
352  return $this->is_alias;
353  }
354 
355  // only for page aliases
356  function setOriginID($a_id)
357  {
358  return $this->origin_id = $a_id;
359  }
360 
361  // only for page aliases
362  function getOriginID()
363  {
364  return $this->origin_id;
365  }
366 
370  // @todo: not sure whether we need this...
371  /*
372  function getPageList($lm_id)
373  {
374  return ilLMObject::getObjectList($lm_id, "pg");
375  }
376  */
377 
384  // @todo: not sure whether we need this...
385  /*
386  function _getPresentationTitle($a_pg_id, $a_mode = IL_CHAPTER_TITLE,
387  $a_include_numbers = false)
388  {
389  global $ilDB;
390 
391  // select
392  $query = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($a_pg_id);
393  $pg_set = $ilDB->query($query);
394  $pg_rec = $pg_set->fetchRow(DB_FETCHMODE_ASSOC);
395 
396  if($a_mode == IL_NO_HEADER)
397  {
398  return "";
399  }
400 
401  $tree = new ilTree($pg_rec["lm_id"]);
402  $tree->setTableNames('lm_tree','lm_data');
403  $tree->setTreeTablePK("lm_id");
404 
405  if($a_mode == IL_PAGE_TITLE)
406  {
407  $nr = "";
408  return $nr.$pg_rec["title"];
409  }
410 
411  if ($tree->isInTree($pg_rec["obj_id"]))
412  {
413  $pred_node = $tree->fetchPredecessorNode($pg_rec["obj_id"], "st");
414  $childs = $tree->getChildsByType($pred_node["obj_id"], "pg");
415  $cnt_str = "";
416  if(count($childs) > 1)
417  {
418  $cnt = 0;
419  foreach($childs as $child)
420  {
421  if ($child["type"] != "pg" || ilLMPageObject::_lookupActive($child["obj_id"]))
422  {
423  $cnt++;
424  }
425  if($child["obj_id"] == $pg_rec["obj_id"])
426  {
427  $cur_cnt = $cnt;
428  }
429  }
430  if ($cnt > 1)
431  {
432  $cnt_str = " (".$cur_cnt."/".$cnt.")";
433  }
434  }
435  require_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
436  //$struct_obj =& new ilStructureObject($pred_node["obj_id"]);
437  //return $struct_obj->getTitle();
438  return ilStructureObject::_getPresentationTitle($pred_node["obj_id"],
439  $a_include_numbers).$cnt_str;
440  //return $pred_node["title"].$cnt_str;
441  }
442  else
443  {
444  return $pg_rec["title"];
445  }
446  }
447  */
448 
449 
450 
451 
457  function getMediaObjectIds()
458  {
459  return $this->mobs_contained;
460  }
461 
467  function getFileItemIds()
468  {
469  return $this->files_contained;
470  }
471 
478  /* todo: this needs to be adopted
479  function exportFO(&$a_xml_writer)
480  {
481  global $ilBench;
482 
483  //$attrs = array();
484  //$a_xml_writer->xmlStartTag("PageObject", $attrs);
485  $title = ilLMPageObject::_getPresentationTitle($this->getId());
486  if ($title != "")
487  {
488  $attrs = array();
489  $attrs["font-family"] = "Times";
490  $attrs["font-size"] = "14pt";
491  $a_xml_writer->xmlElement("fo:block", $attrs, $title);
492  }
493 
494  // PageContent
495  $this->page_object->buildDom();
496  $fo = $this->page_object->getFO();
497  $a_xml_writer->appendXML($fo);
498 
499  //$a_xml_writer->xmlEndTag("PageObject");
500  }
501  */
502 
503 }
504 ?>