ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSCORM2004PageNode.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2008 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/Scorm2004/classes/class.ilSCORM2004Node.php");
25 require_once("./Services/COPage/classes/class.ilPageObject.php");
26 
27 // unclear whether we need this somehow...
28 //define ("IL_CHAPTER_TITLE", "st_title");
29 //define ("IL_PAGE_TITLE", "pg_title");
30 //define ("IL_NO_HEADER", "none");
31 
51 {
52  var $id;
54 
59  function ilSCORM2004PageNode($a_slm_object, $a_id = 0)
60  {
61  parent::ilSCORM2004Node($a_slm_object, $a_id);
62  $this->setType("page");
63  $this->id = $a_id;
64 
65  $this->mobs_contained = array();
66  $this->files_contained = array();
67 
68  if($a_id != 0)
69  {
70  $this->read();
71  }
72  }
73 
77  function __descruct()
78  {
79  if(is_object($this->page_object))
80  {
81  unset($this->page_object);
82  }
83  }
84 
88  function read()
89  {
90  parent::read();
91 
92  $this->page_object = new ilPageObject($this->slm_object->getType(),
93  $this->id, 0, false);
94  }
95 
101  function create($a_upload = false,$a_layout_id = 0)
102  {
103  parent::create($a_upload);
104 
105  // create scorm2004 page
106  include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Page.php");
107  if(!is_object($this->page_object))
108  {
109  $this->page_object =& new ilSCORM2004Page($this->slm_object->getType());
110  }
111  $this->page_object->setId($this->getId());
112  $this->page_object->setParentId($this->getSLMId());
113  if ($a_layout_id == 0) {
114  $this->page_object->create($a_upload);
115  } else{
116  $this->page_object->createWithLayoutId($a_layout_id);
117  }
118  }
119 
125  function delete($a_delete_meta_data = true)
126  {
127  parent::delete($a_delete_meta_data);
128  $this->page_object->delete();
129  }
130 
131 
135  function copy($a_target_slm)
136  {
137  // copy page
138  $slm_page = new ilSCORM2004PageNode($a_target_slm);
139  $slm_page->setTitle($this->getTitle());
140  $slm_page->setSLMId($a_target_slm->getId());
141  $slm_page->setType($this->getType());
142  $slm_page->setDescription($this->getDescription());
143  $slm_page->setImportId("il__page_".$this->getId());
144  $slm_page->create(true); // setting "upload" flag to true prevents creating of meta data
145 
146  // copy meta data
147  include_once("Services/MetaData/classes/class.ilMD.php");
148  $md = new ilMD($this->getSLMId(), $this->getId(), $this->getType());
149  $new_md = $md->cloneMD($a_target_slm->getId(), $slm_page->getId(), $this->getType());
150 
151  // copy page content
152  $page = $slm_page->getPageObject();
153  $page->setXMLContent($this->page_object->copyXMLContent());
154  $page->buildDom();
155  $page->update();
156 
157  return $slm_page;
158  }
159 
163  function &copyToOtherContObject(&$a_cont_obj)
164  {
165  // @todo
166  /*
167  // copy page
168  $lm_page =& new ilLMPageObject($a_cont_obj);
169  $lm_page->setTitle($this->getTitle());
170  $lm_page->setLMId($a_cont_obj->getId());
171  $lm_page->setType($this->getType());
172  $lm_page->setDescription($this->getDescription());
173  $lm_page->create(true); // setting "upload" flag to true prevents creating of meta data
174 
175  // copy meta data
176  include_once("Services/MetaData/classes/class.ilMD.php");
177  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
178  $new_md =& $md->cloneMD($a_cont_obj->getId(), $lm_page->getId(), $this->getType());
179 
180  // copy page content
181  $page =& $lm_page->getPageObject();
182  $page->setXMLContent($this->page_object->getXMLContent());
183  $page->buildDom();
184  $page->update();
185 
186  return $lm_page;
187  */
188  }
189 
197  function _splitPage($a_page_id, $a_pg_parent_type, $a_hier_id)
198  {
199  // @todo: This has to be checked, maybe abandoned or generalized?
200  /*
201  // get content object (learning module / digilib book)
202  $lm_id = ilLMObject::_lookupContObjID($a_page_id);
203  $type = ilObject::_lookupType($lm_id, false);
204  switch ($type)
205  {
206  case "lm":
207  include_once ("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
208  $cont_obj = new ilObjLearningModule($lm_id, false);
209  break;
210 
211  case "dbk":
212  include_once ("./Modules/LearningModule/classes/class.ilObjDlBook.php");
213  $cont_obj = new ilObjDlBook($lm_id, false);
214  break;
215  }
216 
217  $source_lm_page =& new ilLMPageObject($cont_obj, $a_page_id);
218 
219  // create new page
220  $lm_page =& new ilLMPageObject($cont_obj);
221  $lm_page->setTitle($source_lm_page->getTitle());
222  $lm_page->setLMId($source_lm_page->getLMId());
223  $lm_page->setType($source_lm_page->getType());
224  $lm_page->setDescription($source_lm_page->getDescription());
225  $lm_page->create(true);
226 
227  // copy meta data
228  include_once("Services/MetaData/classes/class.ilMD.php");
229  $md = new ilMD($source_lm_page->getLMId(), $a_page_id, $source_lm_page->getType());
230  $new_md =& $md->cloneMD($source_lm_page->getLMId(), $lm_page->getId(), $source_lm_page->getType());
231 
232  // copy complete content of source page to new page
233  $source_page =& $source_lm_page->getPageObject();
234  $page =& $lm_page->getPageObject();
235  $page->setXMLContent($source_page->getXMLContent());
236  $page->buildDom();
237 
238  // insert new page in tree (after original page)
239  $tree = new ilTree($cont_obj->getId());
240  $tree->setTableNames('lm_tree','lm_data');
241  $tree->setTreeTablePK("lm_id");
242  if ($tree->isInTree($source_lm_page->getId()))
243  {
244  $parent_node = $tree->getParentNodeData($source_lm_page->getId());
245  $tree->insertNode($lm_page->getId(), $parent_node["child"], $source_lm_page->getId());
246  }
247 
248  // remove all nodes < hierarchical id from new page (incl. update)
249  $page->addHierIds();
250  $page->deleteContentBeforeHierId($a_hier_id);
251 
252  // remove all nodes >= hierarchical id from source page
253  $source_page->buildDom();
254  $source_page->addHierIds();
255  $source_page->deleteContentFromHierId($a_hier_id);
256 
257  return $lm_page;
258  */
259  }
260 
268  // @todo: This has to be checked, maybe abandoned or generalized?
269  /*
270  function _splitPageNext($a_page_id, $a_pg_parent_type, $a_hier_id)
271  {
272  // get content object (learning module / digilib book)
273  $lm_id = ilLMObject::_lookupContObjID($a_page_id);
274  $type = ilObject::_lookupType($lm_id, false);
275  switch ($type)
276  {
277  case "lm":
278  include_once ("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
279  $cont_obj = new ilObjLearningModule($lm_id, false);
280  break;
281 
282  case "dbk":
283  include_once ("./Modules/LearningModule/classes/class.ilObjDlBook.php");
284  $cont_obj = new ilObjDlBook($lm_id, false);
285  break;
286  }
287  $tree = new ilTree($cont_obj->getId());
288  $tree->setTableNames('lm_tree','lm_data');
289  $tree->setTreeTablePK("lm_id");
290 
291  $source_lm_page =& new ilLMPageObject($cont_obj, $a_page_id);
292  $source_page =& $source_lm_page->getPageObject();
293 
294  // get next page
295  $succ = $tree->fetchSuccessorNode($a_page_id, "pg");
296  if ($succ["child"] > 0)
297  {
298  $target_lm_page =& new ilLMPageObject($cont_obj, $succ["child"]);
299  $target_page =& $target_lm_page->getPageObject();
300  $target_page->buildDom();
301  $target_page->addHierIds();
302 
303  // move nodes to target page
304  $source_page->buildDom();
305  $source_page->addHierIds();
306  ilPageObject::_moveContentAfterHierId($source_page, $target_page, $a_hier_id);
307  //$source_page->deleteContentFromHierId($a_hier_id);
308 
309  return $succ["child"];
310  }
311 
312  }
313  */
314 
320  function assignPageObject(&$a_page_obj)
321  {
322  $this->page_object =& $a_page_obj;
323  }
324 
325 
331  function &getPageObject()
332  {
333  return $this->page_object;
334  }
335 
336 
342  function setId($a_id)
343  {
344  $this->id = $a_id;
345  }
346 
352  function getId()
353  {
354  return $this->id;
355  }
356 
360  function setAlias($a_is_alias)
361  {
362  $this->is_alias = $a_is_alias;
363  }
364 
365  function isAlias()
366  {
367  return $this->is_alias;
368  }
369 
370  // only for page aliases
371  function setOriginID($a_id)
372  {
373  return $this->origin_id = $a_id;
374  }
375 
376  // only for page aliases
377  function getOriginID()
378  {
379  return $this->origin_id;
380  }
381 
385  // @todo: not sure whether we need this...
386  /*
387  function getPageList($lm_id)
388  {
389  return ilLMObject::getObjectList($lm_id, "pg");
390  }
391  */
392 
399  // @todo: not sure whether we need this...
400  /*
401  function _getPresentationTitle($a_pg_id, $a_mode = IL_CHAPTER_TITLE,
402  $a_include_numbers = false)
403  {
404  global $ilDB;
405 
406  // select
407  $query = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($a_pg_id);
408  $pg_set = $ilDB->query($query);
409  $pg_rec = $pg_set->fetchRow(DB_FETCHMODE_ASSOC);
410 
411  if($a_mode == IL_NO_HEADER)
412  {
413  return "";
414  }
415 
416  $tree = new ilTree($pg_rec["lm_id"]);
417  $tree->setTableNames('lm_tree','lm_data');
418  $tree->setTreeTablePK("lm_id");
419 
420  if($a_mode == IL_PAGE_TITLE)
421  {
422  $nr = "";
423  return $nr.$pg_rec["title"];
424  }
425 
426  if ($tree->isInTree($pg_rec["obj_id"]))
427  {
428  $pred_node = $tree->fetchPredecessorNode($pg_rec["obj_id"], "st");
429  $childs = $tree->getChildsByType($pred_node["obj_id"], "pg");
430  $cnt_str = "";
431  if(count($childs) > 1)
432  {
433  $cnt = 0;
434  foreach($childs as $child)
435  {
436  if ($child["type"] != "pg" || ilLMPageObject::_lookupActive($child["obj_id"]))
437  {
438  $cnt++;
439  }
440  if($child["obj_id"] == $pg_rec["obj_id"])
441  {
442  $cur_cnt = $cnt;
443  }
444  }
445  if ($cnt > 1)
446  {
447  $cnt_str = " (".$cur_cnt."/".$cnt.")";
448  }
449  }
450  require_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
451  //$struct_obj =& new ilStructureObject($pred_node["obj_id"]);
452  //return $struct_obj->getTitle();
453  return ilStructureObject::_getPresentationTitle($pred_node["obj_id"],
454  $a_include_numbers).$cnt_str;
455  //return $pred_node["title"].$cnt_str;
456  }
457  else
458  {
459  return $pg_rec["title"];
460  }
461  }
462  */
463 
464 
465 
466 
472  function getMediaObjectIds()
473  {
474  return $this->mobs_contained;
475  }
476 
482  function getFileItemIds()
483  {
484  return $this->files_contained;
485  }
486 
493  /* todo: this needs to be adopted
494  function exportFO(&$a_xml_writer)
495  {
496  global $ilBench;
497 
498  //$attrs = array();
499  //$a_xml_writer->xmlStartTag("PageObject", $attrs);
500  $title = ilLMPageObject::_getPresentationTitle($this->getId());
501  if ($title != "")
502  {
503  $attrs = array();
504  $attrs["font-family"] = "Times";
505  $attrs["font-size"] = "14pt";
506  $a_xml_writer->xmlElement("fo:block", $attrs, $title);
507  }
508 
509  // PageContent
510  $this->page_object->buildDom();
511  $fo = $this->page_object->getFO();
512  $a_xml_writer->appendXML($fo);
513 
514  //$a_xml_writer->xmlEndTag("PageObject");
515  }
516  */
517 
518 }
519 ?>