ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLMPageObject.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 require_once("./Services/COPage/classes/class.ilPageObject.php");
26 
27 define ("IL_CHAPTER_TITLE", "st_title");
28 define ("IL_PAGE_TITLE", "pg_title");
29 define ("IL_NO_HEADER", "none");
30 
49 {
50  var $is_alias;
52  var $id;
53  var $ilias;
54  var $dom;
56 
61  function ilLMPageObject(&$a_content_obj, $a_id = 0, $a_halt = true)
62  {
63  global $ilias, $ilBench;
64 
65  $ilBench->start("ContentPresentation", "ilLMPageObject_Constructor");
66 
67  parent::ilLMObject($a_content_obj, $a_id);
68  $this->setType("pg");
69  $this->id = $a_id;
70  $this->ilias =& $ilias;
71 
72  $this->is_alias = false;
73  $this->contains_int_link = false;
74  $this->mobs_contained = array();
75  $this->files_contained = array();
76  $this->halt_on_error = $a_halt;
77 
78  if($a_id != 0)
79  {
80  $this->read();
81  }
82 
83  $ilBench->stop("ContentPresentation", "ilLMPageObject_Constructor");
84  }
85 
86  function _ilLMPageObject()
87  {
88  if(is_object($this->page_object))
89  {
90  unset($this->page_object);
91  }
92  }
93 
97  function read()
98  {
99  global $ilBench;
100 
101  $ilBench->start("ContentPresentation", "ilLMPageObject_read");
102  parent::read();
103 
104  $this->page_object =& new ilPageObject($this->content_object->getType(),
105  $this->id, 0, $this->halt_on_error);
106 
107  $ilBench->stop("ContentPresentation", "ilLMPageObject_read");
108  }
109 
110  function create($a_upload = false)
111  {
112  parent::create($a_upload);
113  if(!is_object($this->page_object))
114  {
115  $this->page_object =& new ilPageObject($this->content_object->getType());
116  }
117  $this->page_object->setId($this->getId());
118  $this->page_object->setParentId($this->getLMId());
119  $this->page_object->create($a_upload);
120  }
121 
122  function delete($a_delete_meta_data = true)
123  {
124  parent::delete($a_delete_meta_data);
125  $this->page_object->delete();
126  }
127 
128 
132  function copy($a_target_lm)
133  {
134  // copy page
135  $lm_page = new ilLMPageObject($a_target_lm);
136  $lm_page->setTitle($this->getTitle());
137  $lm_page->setLMId($a_target_lm->getId());
138  $lm_page->setType($this->getType());
139  $lm_page->setDescription($this->getDescription());
140  $lm_page->setImportId("il__pg_".$this->getId());
141  $lm_page->create(true); // setting "upload" flag to true prevents creating of meta data
142 
143  // copy meta data
144  include_once("Services/MetaData/classes/class.ilMD.php");
145  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
146  $new_md = $md->cloneMD($a_target_lm->getId(), $lm_page->getId(), $this->getType());
147 
148  // copy page content
149  $page = $lm_page->getPageObject();
150  $page->setXMLContent($this->page_object->getXMLContent());
151  $page->buildDom();
152  $page->update();
153 
154  return $lm_page;
155  }
156 
160  function &copyToOtherContObject(&$a_cont_obj, &$a_copied_nodes)
161  {
162  // copy page
163  $lm_page =& new ilLMPageObject($a_cont_obj);
164  $lm_page->setTitle($this->getTitle());
165  $lm_page->setLMId($a_cont_obj->getId());
166  $lm_page->setImportId("il__pg_".$this->getId());
167  $lm_page->setType($this->getType());
168  $lm_page->setDescription($this->getDescription());
169  $lm_page->create(true); // setting "upload" flag to true prevents creating of meta data
170  $a_copied_nodes[$this->getId()] = $lm_page->getId();
171 
172  // copy meta data
173  include_once("Services/MetaData/classes/class.ilMD.php");
174  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
175  $new_md =& $md->cloneMD($a_cont_obj->getId(), $lm_page->getId(), $this->getType());
176 
177  // copy page content
178  $page =& $lm_page->getPageObject();
179  $page->setXMLContent($this->page_object->getXMLContent());
180  $page->buildDom();
181  $page->update();
182 
183  return $lm_page;
184  }
185 
193  function _splitPage($a_page_id, $a_pg_parent_type, $a_hier_id)
194  {
195  // get content object (learning module / digilib book)
196  $lm_id = ilLMObject::_lookupContObjID($a_page_id);
198  switch ($type)
199  {
200  case "lm":
201  include_once ("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
202  $cont_obj = new ilObjLearningModule($lm_id, false);
203  break;
204 
205  case "dbk":
206  include_once ("./Modules/LearningModule/classes/class.ilObjDlBook.php");
207  $cont_obj = new ilObjDlBook($lm_id, false);
208  break;
209  }
210 
211  $source_lm_page =& new ilLMPageObject($cont_obj, $a_page_id);
212 
213  // create new page
214  $lm_page =& new ilLMPageObject($cont_obj);
215  $lm_page->setTitle($source_lm_page->getTitle());
216  $lm_page->setLMId($source_lm_page->getLMId());
217  $lm_page->setType($source_lm_page->getType());
218  $lm_page->setDescription($source_lm_page->getDescription());
219  $lm_page->create(true);
220 
221  // copy meta data
222  include_once("Services/MetaData/classes/class.ilMD.php");
223  $md = new ilMD($source_lm_page->getLMId(), $a_page_id, $source_lm_page->getType());
224  $new_md =& $md->cloneMD($source_lm_page->getLMId(), $lm_page->getId(), $source_lm_page->getType());
225 
226  // copy complete content of source page to new page
227  $source_page =& $source_lm_page->getPageObject();
228  $page =& $lm_page->getPageObject();
229  $page->setXMLContent($source_page->getXMLContent());
230  $page->buildDom();
231 
232  // insert new page in tree (after original page)
233  $tree = new ilTree($cont_obj->getId());
234  $tree->setTableNames('lm_tree','lm_data');
235  $tree->setTreeTablePK("lm_id");
236  if ($tree->isInTree($source_lm_page->getId()))
237  {
238  $parent_node = $tree->getParentNodeData($source_lm_page->getId());
239  $tree->insertNode($lm_page->getId(), $parent_node["child"], $source_lm_page->getId());
240  }
241 
242  // remove all nodes < hierarchical id from new page (incl. update)
243  $page->addHierIds();
244  $page->deleteContentBeforeHierId($a_hier_id);
245 
246  // remove all nodes >= hierarchical id from source page
247  $source_page->buildDom();
248  $source_page->addHierIds();
249  $source_page->deleteContentFromHierId($a_hier_id);
250 
251  return $lm_page;
252 
253  }
254 
262  function _splitPageNext($a_page_id, $a_pg_parent_type, $a_hier_id)
263  {
264  // get content object (learning module / digilib book)
265  $lm_id = ilLMObject::_lookupContObjID($a_page_id);
267  switch ($type)
268  {
269  case "lm":
270  include_once ("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
271  $cont_obj = new ilObjLearningModule($lm_id, false);
272  break;
273 
274  case "dbk":
275  include_once ("./Modules/LearningModule/classes/class.ilObjDlBook.php");
276  $cont_obj = new ilObjDlBook($lm_id, false);
277  break;
278  }
279  $tree = new ilTree($cont_obj->getId());
280  $tree->setTableNames('lm_tree','lm_data');
281  $tree->setTreeTablePK("lm_id");
282 
283  $source_lm_page =& new ilLMPageObject($cont_obj, $a_page_id);
284  $source_page =& $source_lm_page->getPageObject();
285 
286  // get next page
287  $succ = $tree->fetchSuccessorNode($a_page_id, "pg");
288  if ($succ["child"] > 0)
289  {
290  $target_lm_page =& new ilLMPageObject($cont_obj, $succ["child"]);
291  $target_page =& $target_lm_page->getPageObject();
292  $target_page->buildDom();
293  $target_page->addHierIds();
294 
295  // move nodes to target page
296  $source_page->buildDom();
297  $source_page->addHierIds();
298  ilPageObject::_moveContentAfterHierId($source_page, $target_page, $a_hier_id);
299  //$source_page->deleteContentFromHierId($a_hier_id);
300 
301  return $succ["child"];
302  }
303 
304  }
305 
306 
312  function assignPageObject(&$a_page_obj)
313  {
314  $this->page_object =& $a_page_obj;
315  }
316 
317 
323  function &getPageObject()
324  {
325  return $this->page_object;
326  }
327 
328 
332  function setId($a_id)
333  {
334  $this->id = $a_id;
335  }
336 
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  function getPageList($lm_id)
371  {
372  return ilLMObject::getObjectList($lm_id, "pg");
373  }
374 
378  function getPagesWithLinksList($a_lm_id, $a_par_type)
379  {
380  $pages = ilLMPageObject::getPageList($a_lm_id);
381  $ids = array();
382  foreach($pages as $page)
383  {
384  $ids[] = $page["obj_id"];
385  }
386 
387  $linked_pages = ilPageObject::getPagesWithLinks($a_par_type, $a_lm_id);
388  $result = array();
389  foreach($pages as $page)
390  {
391  if (is_array($linked_pages[$page["obj_id"]]))
392  {
393  $result[] = $page;
394  }
395  }
396  return $result;
397  }
398 
405  function _getPresentationTitle($a_pg_id, $a_mode = IL_CHAPTER_TITLE,
406  $a_include_numbers = false, $a_time_scheduled_activation = false)
407  {
408  global $ilDB;
409 
410  // select
411  $query = "SELECT * FROM lm_data WHERE obj_id = ".
412  $ilDB->quote($a_pg_id, "integer");
413  $pg_set = $ilDB->query($query);
414  $pg_rec = $ilDB->fetchAssoc($pg_set);
415 
416  if($a_mode == IL_NO_HEADER)
417  {
418  return "";
419  }
420 
421  $tree = new ilTree($pg_rec["lm_id"]);
422  $tree->setTableNames('lm_tree','lm_data');
423  $tree->setTreeTablePK("lm_id");
424 
425  if($a_mode == IL_PAGE_TITLE)
426  {
427  $nr = "";
428  return $nr.$pg_rec["title"];
429  }
430 
431  if ($tree->isInTree($pg_rec["obj_id"]))
432  {
433  $pred_node = $tree->fetchPredecessorNode($pg_rec["obj_id"], "st");
434  $childs = $tree->getChildsByType($pred_node["obj_id"], "pg");
435  $cnt_str = "";
436  if(count($childs) > 1)
437  {
438  $cnt = 0;
439  foreach($childs as $child)
440  {
441  include_once("./Services/COPage/classes/class.ilPageObject.php");
442  $active = ilPageObject::_lookupActive($child["obj_id"],
443  ilObject::_lookupType($pg_rec["lm_id"]), $a_time_scheduled_activation);
444 
445  if ($child["type"] != "pg" || $active)
446  {
447  $cnt++;
448  }
449  if($child["obj_id"] == $pg_rec["obj_id"])
450  {
451  $cur_cnt = $cnt;
452  }
453  }
454  if ($cnt > 1)
455  {
456  $cnt_str = " (".$cur_cnt."/".$cnt.")";
457  }
458  }
459  require_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
460  //$struct_obj =& new ilStructureObject($pred_node["obj_id"]);
461  //return $struct_obj->getTitle();
462  return ilStructureObject::_getPresentationTitle($pred_node["obj_id"],
463  $a_include_numbers).$cnt_str;
464  //return $pred_node["title"].$cnt_str;
465  }
466  else
467  {
468  return $pg_rec["title"];
469  }
470  }
471 
478  function exportXML(&$a_xml_writer, $a_mode = "normal", $a_inst = 0)
479  {
480  global $ilBench;
481 
482  $attrs = array();
483  $a_xml_writer->xmlStartTag("PageObject", $attrs);
484 
485  switch ($a_mode)
486  {
487  case "normal":
488  // MetaData
489  $ilBench->start("ContentObjectExport", "exportPageObject_XML_Meta");
490  $this->exportXMLMetaData($a_xml_writer);
491  $ilBench->stop("ContentObjectExport", "exportPageObject_XML_Meta");
492 
493  // PageContent
494  $ilBench->start("ContentObjectExport", "exportPageObject_XML_PageContent");
495  $this->exportXMLPageContent($a_xml_writer, $a_inst);
496  $ilBench->stop("ContentObjectExport", "exportPageObject_XML_PageContent");
497  break;
498 
499  case "alias":
500  $attrs = array();
501  $attrs["OriginId"] = "il_".$a_inst.
502  "_pg_".$this->getId();
503  $a_xml_writer->xmlElement("PageAlias", $attrs);
504  break;
505  }
506 
507  // Layout
508  // not implemented
509 
510  $a_xml_writer->xmlEndTag("PageObject");
511  }
512 
516  function _exportXMLAlias(&$a_xml_writer, $a_id, $a_inst = 0)
517  {
518  $attrs = array();
519  $a_xml_writer->xmlStartTag("PageObject", $attrs);
520 
521  $attrs = array();
522  $attrs["OriginId"] = "il_".$a_inst.
523  "_pg_".$a_id;
524  $a_xml_writer->xmlElement("PageAlias", $attrs);
525 
526  $a_xml_writer->xmlEndTag("PageObject");
527  }
528 
529 
536  function exportXMLMetaData(&$a_xml_writer)
537  {
538  include_once("Services/MetaData/classes/class.ilMD2XML.php");
539  $md2xml = new ilMD2XML($this->getLMId(), $this->getId(), $this->getType());
540  $md2xml->setExportMode(true);
541  $md2xml->startExport();
542  $a_xml_writer->appendXML($md2xml->getXML());
543  }
544 
545  function modifyExportIdentifier($a_tag, $a_param, $a_value)
546  {
547  if ($a_tag == "Identifier" && $a_param == "Entry")
548  {
549  $a_value = "il_".IL_INST_ID."_pg_".$this->getId();
550  //$a_value = ilUtil::insertInstIntoID($a_value);
551  }
552 
553  return $a_value;
554  }
555 
556 
563  function exportXMLPageContent(&$a_xml_writer, $a_inst = 0)
564  {
565 //echo "exportxmlpagecontent:$a_inst:<br>";
566  $cont_obj =& $this->getContentObject();
567  //$page_obj = new ilPageObject($cont_obj->getType(), $this->getId());
568 
569  $this->page_object->buildDom();
570  $this->page_object->insertInstIntoIDs($a_inst);
571  $this->mobs_contained = $this->page_object->collectMediaObjects(false);
572  $this->files_contained = $this->page_object->collectFileItems();
573  $xml = $this->page_object->getXMLFromDom(false, false, false, "", true);
574  $xml = str_replace("&","&amp;", $xml);
575  $a_xml_writer->appendXML($xml);
576 
577  $this->page_object->freeDom();
578  }
579 
585  function getMediaObjectIds()
586  {
587  return $this->mobs_contained;
588  }
589 
595  function getFileItemIds()
596  {
597  return $this->files_contained;
598  }
599 
606  function exportFO(&$a_xml_writer)
607  {
608  global $ilBench;
609 
610  //$attrs = array();
611  //$a_xml_writer->xmlStartTag("PageObject", $attrs);
613  if ($title != "")
614  {
615  $attrs = array();
616  $attrs["font-family"] = "Times";
617  $attrs["font-size"] = "14pt";
618  $a_xml_writer->xmlElement("fo:block", $attrs, $title);
619  }
620 
621  // PageContent
622  $this->page_object->buildDom();
623  $fo = $this->page_object->getFO();
624  $a_xml_writer->appendXML($fo);
625 
626  //$a_xml_writer->xmlEndTag("PageObject");
627  }
628 
629 }
630 ?>