ILIAS  Release_3_10_x_branch Revision 61812
 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-2001 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)
407  {
408  global $ilDB;
409 
410  // select
411  $query = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($a_pg_id);
412  $pg_set = $ilDB->query($query);
413  $pg_rec = $pg_set->fetchRow(DB_FETCHMODE_ASSOC);
414 
415  if($a_mode == IL_NO_HEADER)
416  {
417  return "";
418  }
419 
420  $tree = new ilTree($pg_rec["lm_id"]);
421  $tree->setTableNames('lm_tree','lm_data');
422  $tree->setTreeTablePK("lm_id");
423 
424  if($a_mode == IL_PAGE_TITLE)
425  {
426  $nr = "";
427  return $nr.$pg_rec["title"];
428  }
429 
430  if ($tree->isInTree($pg_rec["obj_id"]))
431  {
432  $pred_node = $tree->fetchPredecessorNode($pg_rec["obj_id"], "st");
433  $childs = $tree->getChildsByType($pred_node["obj_id"], "pg");
434  $cnt_str = "";
435  if(count($childs) > 1)
436  {
437  $cnt = 0;
438  foreach($childs as $child)
439  {
440  if ($child["type"] != "pg" || ilLMPageObject::_lookupActive($child["obj_id"]))
441  {
442  $cnt++;
443  }
444  if($child["obj_id"] == $pg_rec["obj_id"])
445  {
446  $cur_cnt = $cnt;
447  }
448  }
449  if ($cnt > 1)
450  {
451  $cnt_str = " (".$cur_cnt."/".$cnt.")";
452  }
453  }
454  require_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
455  //$struct_obj =& new ilStructureObject($pred_node["obj_id"]);
456  //return $struct_obj->getTitle();
457  return ilStructureObject::_getPresentationTitle($pred_node["obj_id"],
458  $a_include_numbers).$cnt_str;
459  //return $pred_node["title"].$cnt_str;
460  }
461  else
462  {
463  return $pg_rec["title"];
464  }
465  }
466 
473  function exportXML(&$a_xml_writer, $a_mode = "normal", $a_inst = 0)
474  {
475  global $ilBench;
476 
477  $attrs = array();
478  $a_xml_writer->xmlStartTag("PageObject", $attrs);
479 
480  switch ($a_mode)
481  {
482  case "normal":
483  // MetaData
484  $ilBench->start("ContentObjectExport", "exportPageObject_XML_Meta");
485  $this->exportXMLMetaData($a_xml_writer);
486  $ilBench->stop("ContentObjectExport", "exportPageObject_XML_Meta");
487 
488  // PageContent
489  $ilBench->start("ContentObjectExport", "exportPageObject_XML_PageContent");
490  $this->exportXMLPageContent($a_xml_writer, $a_inst);
491  $ilBench->stop("ContentObjectExport", "exportPageObject_XML_PageContent");
492  break;
493 
494  case "alias":
495  $attrs = array();
496  $attrs["OriginId"] = "il_".$a_inst.
497  "_pg_".$this->getId();
498  $a_xml_writer->xmlElement("PageAlias", $attrs);
499  break;
500  }
501 
502  // Layout
503  // not implemented
504 
505  $a_xml_writer->xmlEndTag("PageObject");
506  }
507 
511  function _exportXMLAlias(&$a_xml_writer, $a_id, $a_inst = 0)
512  {
513  $attrs = array();
514  $a_xml_writer->xmlStartTag("PageObject", $attrs);
515 
516  $attrs = array();
517  $attrs["OriginId"] = "il_".$a_inst.
518  "_pg_".$a_id;
519  $a_xml_writer->xmlElement("PageAlias", $attrs);
520 
521  $a_xml_writer->xmlEndTag("PageObject");
522  }
523 
524 
531  function exportXMLMetaData(&$a_xml_writer)
532  {
533  include_once("Services/MetaData/classes/class.ilMD2XML.php");
534  $md2xml = new ilMD2XML($this->getLMId(), $this->getId(), $this->getType());
535  $md2xml->setExportMode(true);
536  $md2xml->startExport();
537  $a_xml_writer->appendXML($md2xml->getXML());
538  }
539 
540  function modifyExportIdentifier($a_tag, $a_param, $a_value)
541  {
542  if ($a_tag == "Identifier" && $a_param == "Entry")
543  {
544  $a_value = "il_".IL_INST_ID."_pg_".$this->getId();
545  //$a_value = ilUtil::insertInstIntoID($a_value);
546  }
547 
548  return $a_value;
549  }
550 
551 
558  function exportXMLPageContent(&$a_xml_writer, $a_inst = 0)
559  {
560 //echo "exportxmlpagecontent:$a_inst:<br>";
561  $cont_obj =& $this->getContentObject();
562  //$page_obj = new ilPageObject($cont_obj->getType(), $this->getId());
563 
564  $this->page_object->buildDom();
565  $this->page_object->insertInstIntoIDs($a_inst);
566  $this->mobs_contained = $this->page_object->collectMediaObjects(false);
567  $this->files_contained = $this->page_object->collectFileItems();
568  $xml = $this->page_object->getXMLFromDom(false, false, false, "", true);
569  $xml = str_replace("&","&amp;", $xml);
570  $a_xml_writer->appendXML($xml);
571 
572  $this->page_object->freeDom();
573  }
574 
580  function getMediaObjectIds()
581  {
582  return $this->mobs_contained;
583  }
584 
590  function getFileItemIds()
591  {
592  return $this->files_contained;
593  }
594 
601  function exportFO(&$a_xml_writer)
602  {
603  global $ilBench;
604 
605  //$attrs = array();
606  //$a_xml_writer->xmlStartTag("PageObject", $attrs);
608  if ($title != "")
609  {
610  $attrs = array();
611  $attrs["font-family"] = "Times";
612  $attrs["font-size"] = "14pt";
613  $a_xml_writer->xmlElement("fo:block", $attrs, $title);
614  }
615 
616  // PageContent
617  $this->page_object->buildDom();
618  $fo = $this->page_object->getFO();
619  $a_xml_writer->appendXML($fo);
620 
621  //$a_xml_writer->xmlEndTag("PageObject");
622  }
623 
624 }
625 ?>