ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilLMPageObject.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
6require_once("./Modules/LearningModule/classes/class.ilLMPage.php");
7
8define ("IL_CHAPTER_TITLE", "st_title");
9define ("IL_PAGE_TITLE", "pg_title");
10define ("IL_NO_HEADER", "none");
11
30{
33 var $id;
34 var $ilias;
35 var $dom;
37
42 function ilLMPageObject(&$a_content_obj, $a_id = 0, $a_halt = true)
43 {
44 global $ilias, $ilBench;
45
46 $ilBench->start("ContentPresentation", "ilLMPageObject_Constructor");
47
48 parent::ilLMObject($a_content_obj, $a_id);
49 $this->setType("pg");
50 $this->id = $a_id;
51
52 $this->is_alias = false;
53 $this->contains_int_link = false;
54 $this->mobs_contained = array();
55 $this->files_contained = array();
56 $this->halt_on_error = $a_halt;
57
58 if($a_id != 0)
59 {
60 $this->read();
61 }
62
63 $ilBench->stop("ContentPresentation", "ilLMPageObject_Constructor");
64 }
65
66 function _ilLMPageObject()
67 {
68 if(is_object($this->page_object))
69 {
70 unset($this->page_object);
71 }
72 }
73
77 function read()
78 {
79 parent::read();
80
81 $this->page_object = new ilLMPage($this->id, 0);
82 }
83
84 function create($a_upload = false, $a_omit_page_object_creation = false)
85 {
86 parent::create($a_upload);
87 if ($a_omit_page_object_creation)
88 {
89 return;
90 }
91 if(!is_object($this->page_object))
92 {
93 $this->page_object = new ilLMPage();
94 }
95 $this->page_object->setId($this->getId());
96 $this->page_object->setParentId($this->getLMId());
97 $this->page_object->create($a_upload);
98 }
99
100 function delete($a_delete_meta_data = true)
101 {
102 parent::delete($a_delete_meta_data);
103 $this->page_object->delete();
104 }
105
106
110 function copy($a_target_lm)
111 {
112 // copy page
113 $lm_page = new ilLMPageObject($a_target_lm);
114 $lm_page->setTitle($this->getTitle());
115 $lm_page->setLayout($this->getLayout());
116 $lm_page->setLMId($a_target_lm->getId());
117 $lm_page->setType($this->getType());
118 $lm_page->setDescription($this->getDescription());
119 $lm_page->setImportId("il__pg_".$this->getId());
120 $lm_page->create(true); // setting "upload" flag to true prevents creating of meta data
121
122 // check whether export id already exists in the target lm
123 $del_exp_id = false;
124 $exp_id = ilLMPageObject::getExportId($this->getLMId(), $this->getId());
125 if (trim($exp_id) != "")
126 {
127 if (ilLMPageObject::existsExportID($a_target_lm->getId(), $exp_id))
128 {
129 $del_exp_id = true;
130 }
131 }
132
133 // copy meta data
134 include_once("Services/MetaData/classes/class.ilMD.php");
135 $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
136 $new_md = $md->cloneMD($a_target_lm->getId(), $lm_page->getId(), $this->getType());
137
138 // check whether export id already exists in the target lm
139 if ($del_exp_id)
140 {
141 ilLMPageObject::saveExportId($a_target_lm->getId(), $lm_page->getId(), "");
142 }
143 else
144 {
145 ilLMPageObject::saveExportId($a_target_lm->getId(), $lm_page->getId(),
146 trim($exp_id));
147 }
148
149 // copy page content and activation
150 $page = $lm_page->getPageObject();
151 $this->page_object->copy($page->getId(), $page->getParentType(), $page->getParentId());
152 /*$page->setXMLContent($this->page_object->copyXMLContent());
153 $page->setActive($this->page_object->getActive());
154 $page->setActivationStart($this->page_object->getActivationStart());
155 $page->setActivationEnd($this->page_object->getActivationEnd());
156 $page->buildDom();
157 $page->update();*/
158 $lm_page->read(); // this gets the updated page object into lm page
159
160 // copy translations
161 include_once("./Modules/LearningModule/classes/class.ilLMObjTranslation.php");
162 ilLMObjTranslation::copy($this->getId(), $lm_page->getId());
163
164 return $lm_page;
165 }
166
170 function &copyToOtherContObject(&$a_cont_obj, &$a_copied_nodes)
171 {
172 // copy page
173 $lm_page =& new ilLMPageObject($a_cont_obj);
174 $lm_page->setTitle($this->getTitle());
175 $lm_page->setLMId($a_cont_obj->getId());
176 $lm_page->setImportId("il__pg_".$this->getId());
177 $lm_page->setType($this->getType());
178 $lm_page->setDescription($this->getDescription());
179 $lm_page->create(true); // setting "upload" flag to true prevents creating of meta data
180 $a_copied_nodes[$this->getId()] = $lm_page->getId();
181
182 // copy meta data
183 include_once("Services/MetaData/classes/class.ilMD.php");
184 $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
185 $new_md =& $md->cloneMD($a_cont_obj->getId(), $lm_page->getId(), $this->getType());
186
187 // copy page content
188 $page =& $lm_page->getPageObject();
189 $page->setXMLContent($this->page_object->getXMLContent());
190 $page->buildDom();
191 $page->update();
192
193 return $lm_page;
194 }
195
203 function _splitPage($a_page_id, $a_pg_parent_type, $a_hier_id)
204 {
205 // get content object (learning module / digilib book)
208 switch ($type)
209 {
210 case "lm":
211 include_once ("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
212 $cont_obj = new ilObjLearningModule($lm_id, false);
213 break;
214
215 case "dbk":
216 include_once ("./Modules/LearningModule/classes/class.ilObjDlBook.php");
217 $cont_obj = new ilObjDlBook($lm_id, false);
218 break;
219 }
220
221 $source_lm_page = new ilLMPageObject($cont_obj, $a_page_id);
222
223 // create new page
224 $lm_page = new ilLMPageObject($cont_obj);
225 $lm_page->setTitle($source_lm_page->getTitle());
226 $lm_page->setLMId($source_lm_page->getLMId());
227 $lm_page->setType($source_lm_page->getType());
228 $lm_page->setDescription($source_lm_page->getDescription());
229 $lm_page->create(true);
230
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->copyXMLContent());
236//echo htmlentities($source_page->copyXMLContent());
237 $page->buildDom(true);
238 $page->update();
239// echo "-".$page->getId()."-".$page->getParentType()."-";
240
241 // copy meta data
242 include_once("Services/MetaData/classes/class.ilMD.php");
243 $md = new ilMD($source_lm_page->getLMId(), $a_page_id, $source_lm_page->getType());
244 $md->cloneMD($source_lm_page->getLMId(), $lm_page->getId(), $source_lm_page->getType());
245
246 // insert new page in tree (after original page)
247 $tree = new ilTree($cont_obj->getId());
248 $tree->setTableNames('lm_tree','lm_data');
249 $tree->setTreeTablePK("lm_id");
250 if ($tree->isInTree($source_lm_page->getId()))
251 {
252 $parent_node = $tree->getParentNodeData($source_lm_page->getId());
253 $tree->insertNode($lm_page->getId(), $parent_node["child"], $source_lm_page->getId());
254 }
255
256 // remove all nodes < hierarchical id from new page (incl. update)
257 $page->addHierIds();
258 $page->deleteContentBeforeHierId($a_hier_id);
259// $page->update();
260
261 // remove all nodes >= hierarchical id from source page
262 $source_page->buildDom();
263 $source_page->addHierIds();
264 $source_page->deleteContentFromHierId($a_hier_id);
265
266 return $lm_page;
267
268 }
269
277 function _splitPageNext($a_page_id, $a_pg_parent_type, $a_hier_id)
278 {
279 // get content object (learning module / digilib book)
282 switch ($type)
283 {
284 case "lm":
285 include_once ("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
286 $cont_obj = new ilObjLearningModule($lm_id, false);
287 break;
288
289 case "dbk":
290 include_once ("./Modules/LearningModule/classes/class.ilObjDlBook.php");
291 $cont_obj = new ilObjDlBook($lm_id, false);
292 break;
293 }
294 $tree = new ilTree($cont_obj->getId());
295 $tree->setTableNames('lm_tree','lm_data');
296 $tree->setTreeTablePK("lm_id");
297
298 $source_lm_page =& new ilLMPageObject($cont_obj, $a_page_id);
299 $source_page =& $source_lm_page->getPageObject();
300
301 // get next page
302 $succ = $tree->fetchSuccessorNode($a_page_id, "pg");
303 if ($succ["child"] > 0)
304 {
305 $target_lm_page =& new ilLMPageObject($cont_obj, $succ["child"]);
306 $target_page =& $target_lm_page->getPageObject();
307 $target_page->buildDom();
308 $target_page->addHierIds();
309
310 // move nodes to target page
311 $source_page->buildDom();
312 $source_page->addHierIds();
313 ilLMPage::_moveContentAfterHierId($source_page, $target_page, $a_hier_id);
314 //$source_page->deleteContentFromHierId($a_hier_id);
315
316 return $succ["child"];
317 }
318
319 }
320
321
327 function assignPageObject(&$a_page_obj)
328 {
329 $this->page_object =& $a_page_obj;
330 }
331
332
338 function &getPageObject()
339 {
340 return $this->page_object;
341 }
342
343
347 function setId($a_id)
348 {
349 $this->id = $a_id;
350 }
351
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
386 {
387 return ilLMObject::getObjectList($lm_id, "pg");
388 }
389
393 function getPagesWithLinksList($a_lm_id, $a_par_type)
394 {
395 $pages = ilLMPageObject::getPageList($a_lm_id);
396 $ids = array();
397 foreach($pages as $page)
398 {
399 $ids[] = $page["obj_id"];
400 }
401
402 $linked_pages = ilLMPage::getPagesWithLinks($a_par_type, $a_lm_id);
403 $result = array();
404 foreach($pages as $page)
405 {
406 if (is_array($linked_pages[$page["obj_id"]]))
407 {
408 $result[] = $page;
409 }
410 }
411 return $result;
412 }
413
420 static function _getPresentationTitle($a_pg_id, $a_mode = IL_CHAPTER_TITLE,
421 $a_include_numbers = false, $a_time_scheduled_activation = false,
422 $a_force_content = false, $a_lm_id = 0, $a_lang = "-")
423 {
424 if($a_mode == IL_NO_HEADER && !$a_force_content)
425 {
426 return "";
427 }
428
429 if ($a_lm_id == 0)
430 {
431 $a_lm_id = ilLMObject::_lookupContObjID($a_pg_id);
432 }
433
434 if ($a_lm_id == 0)
435 {
436 return "";
437 }
438
439 // this is optimized when ilLMObject::preloadDataByLM is invoked (e.g. done in ilLMExplorerGUI)
441
442 // this is also optimized since ilObjectTranslation re-uses instances for one lm
443 include_once("./Services/Object/classes/class.ilObjectTranslation.php");
444 $ot = ilObjectTranslation::getInstance($a_lm_id);
445 $languages = $ot->getLanguages();
446
447 if ($a_lang != "-" && $ot->getContentActivated() && isset($languages[$a_lang]))
448 {
449 include_once("./Modules/LearningModule/classes/class.ilLMObjTranslation.php");
450 $lmobjtrans = new ilLMObjTranslation($a_pg_id, $a_lang);
451 if ($lmobjtrans->getTitle() != "")
452 {
453 $title = $lmobjtrans->getTitle();
454 }
455 }
456
457 if($a_mode == IL_PAGE_TITLE)
458 {
459 return $title;
460 }
461
462 include_once("./Modules/LearningModule/classes/class.ilLMTree.php");
463 $tree = ilLMTree::getInstance($a_lm_id);
464
465 if ($tree->isInTree($a_pg_id))
466 {
467 $pred_node = $tree->fetchPredecessorNode($a_pg_id, "st");
468 $childs = $tree->getChildsByType($pred_node["obj_id"], "pg");
469 $cnt_str = "";
470 if(count($childs) > 1)
471 {
472 $cnt = 0;
473 foreach($childs as $child)
474 {
475 include_once("./Modules/LearningModule/classes/class.ilLMPage.php");
476 $active = ilLMPage::_lookupActive($child["obj_id"],
477 ilObject::_lookupType($a_lm_id), $a_time_scheduled_activation);
478
479 if (!$active)
480 {
481 $act_data = ilLMPage::_lookupActivationData((int) $child["obj_id"], ilObject::_lookupType($a_lm_id));
482 if ($act_data["show_activation_info"] &&
483 (ilUtil::now() < $act_data["activation_start"]))
484 {
485 $active = true;
486 }
487 }
488
489 if ($child["type"] != "pg" || $active)
490 {
491 $cnt++;
492 }
493 if($child["obj_id"] == $a_pg_id)
494 {
495 $cur_cnt = $cnt;
496 }
497 }
498 if ($cnt > 1)
499 {
500 $cnt_str = " (".$cur_cnt."/".$cnt.")";
501 }
502 }
503 require_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
504 //$struct_obj =& new ilStructureObject($pred_node["obj_id"]);
505 //return $struct_obj->getTitle();
506 return ilStructureObject::_getPresentationTitle($pred_node["obj_id"],
507 $a_include_numbers, false, 0, $a_lang).$cnt_str;
508
509 //return $pred_node["title"].$cnt_str;
510 }
511 else
512 {
513 return $title;
514 }
515 }
516
523 function exportXML(&$a_xml_writer, $a_mode = "normal", $a_inst = 0)
524 {
525 global $ilBench;
526
527 $attrs = array();
528 $a_xml_writer->xmlStartTag("PageObject", $attrs);
529
530 switch ($a_mode)
531 {
532 case "normal":
533 // MetaData
534 $ilBench->start("ContentObjectExport", "exportPageObject_XML_Meta");
535 $this->exportXMLMetaData($a_xml_writer);
536 $ilBench->stop("ContentObjectExport", "exportPageObject_XML_Meta");
537
538 // PageContent
539 $ilBench->start("ContentObjectExport", "exportPageObject_XML_PageContent");
540 $this->exportXMLPageContent($a_xml_writer, $a_inst);
541 $ilBench->stop("ContentObjectExport", "exportPageObject_XML_PageContent");
542 break;
543
544 case "alias":
545 $attrs = array();
546 $attrs["OriginId"] = "il_".$a_inst.
547 "_pg_".$this->getId();
548 $a_xml_writer->xmlElement("PageAlias", $attrs);
549 break;
550 }
551
552 // Layout
553 // not implemented
554
555 $a_xml_writer->xmlEndTag("PageObject");
556 }
557
561 function _exportXMLAlias(&$a_xml_writer, $a_id, $a_inst = 0)
562 {
563 $attrs = array();
564 $a_xml_writer->xmlStartTag("PageObject", $attrs);
565
566 $attrs = array();
567 $attrs["OriginId"] = "il_".$a_inst.
568 "_pg_".$a_id;
569 $a_xml_writer->xmlElement("PageAlias", $attrs);
570
571 $a_xml_writer->xmlEndTag("PageObject");
572 }
573
574
581 function exportXMLMetaData(&$a_xml_writer)
582 {
583 include_once("Services/MetaData/classes/class.ilMD2XML.php");
584 $md2xml = new ilMD2XML($this->getLMId(), $this->getId(), $this->getType());
585 $md2xml->setExportMode(true);
586 $md2xml->startExport();
587 $a_xml_writer->appendXML($md2xml->getXML());
588 }
589
590 function modifyExportIdentifier($a_tag, $a_param, $a_value)
591 {
592 if ($a_tag == "Identifier" && $a_param == "Entry")
593 {
594 $a_value = "il_".IL_INST_ID."_pg_".$this->getId();
595 //$a_value = ilUtil::insertInstIntoID($a_value);
596 }
597
598 return $a_value;
599 }
600
601
608 function exportXMLPageContent(&$a_xml_writer, $a_inst = 0)
609 {
610//echo "exportxmlpagecontent:$a_inst:<br>";
611 $cont_obj = $this->getContentObject();
612
613 $this->page_object->buildDom();
614 $this->page_object->insertInstIntoIDs($a_inst);
615 $this->mobs_contained = $this->page_object->collectMediaObjects(false);
616 //$this->files_contained = $this->page_object->collectFileItems();
617 include_once("./Services/COPage/classes/class.ilPCFileList.php");
618 $this->files_contained = ilPCFileList::collectFileItems($this->page_object, $this->page_object->getDomDoc());
619// $this->questions_contained = $this->page_object->getQuestionIds();
620 $xml = $this->page_object->getXMLFromDom(false, false, false, "", true);
621 $xml = str_replace("&","&amp;", $xml);
622 $a_xml_writer->appendXML($xml);
623
624 $this->page_object->freeDom();
625 }
626
632 function getQuestionIds()
633 {
634 include_once("./Services/COPage/classes/class.ilPCQuestion.php");
635 return ilPCQuestion::_getQuestionIdsForPage($this->content_object->getType(),
636 $this->getId());
637 }
638
645 {
646 return $this->mobs_contained;
647 }
648
654 function getFileItemIds()
655 {
656 return $this->files_contained;
657 }
658
665 function exportFO(&$a_xml_writer)
666 {
667 global $ilBench;
668
669 //$attrs = array();
670 //$a_xml_writer->xmlStartTag("PageObject", $attrs);
672 if ($title != "")
673 {
674 $attrs = array();
675 $attrs["font-family"] = "Times";
676 $attrs["font-size"] = "14pt";
677 $a_xml_writer->xmlElement("fo:block", $attrs, $title);
678 }
679
680 // PageContent
681 $this->page_object->buildDom();
682 $fo = $this->page_object->getFO();
683 $a_xml_writer->appendXML($fo);
684
685 //$a_xml_writer->xmlEndTag("PageObject");
686 }
687
694 static function queryQuestionsOfLearningModule($a_lm_id, $a_order_field,
695 $a_order_dir, $a_offset, $a_limit)
696 {
697 global $ilDB, $rbacreview;
698
699
700 // count query
701 $count_query = "SELECT count(pq.question_id) cnt ";
702
703 // basic query
704 $query = "SELECT pq.page_id, pq.question_id ";
705
706 $from = " FROM page_question pq JOIN lm_tree t ON (t.lm_id = ".$ilDB->quote($a_lm_id, "integer").
707 " AND pq.page_id = t.child and pq.page_parent_type = ".$ilDB->quote("lm", "text").") ".
708 " WHERE t.lm_id = ".$ilDB->quote($a_lm_id, "integer");
709 $count_query.= $from;
710 $query.= $from;
711
712
713 // count query
714 $set = $ilDB->query($count_query);
715 $cnt = 0;
716 if ($rec = $ilDB->fetchAssoc($set))
717 {
718 $cnt = $rec["cnt"];
719 }
720
721 $offset = (int) $a_offset;
722 $limit = (int) $a_limit;
723 if ($a_limit > 0)
724 {
725 $ilDB->setLimit($limit, $offset);
726 }
727
728 // set query
729 $set = $ilDB->query($query);
730 $result = array();
731 while($rec = $ilDB->fetchAssoc($set))
732 {
733 $result[] = $rec;
734 }
735 return array("cnt" => $cnt, "set" => $result);
736 }
737}
738?>
$result
const IL_PAGE_TITLE
const IL_CHAPTER_TITLE
const IL_NO_HEADER
Translation information on lm object.
static copy($a_source_id, $a_target_id)
Copy all translations of an object.
Class ilLMObject.
static getExportId($a_lm_id, $a_lmobj_id, $a_type="pg")
Get export ID.
existsExportID($a_lm_id, $a_exp_id, $a_type="pg")
Does export ID exist in lm?
getLayout()
Get layout.
static saveExportId($a_lm_id, $a_lmobj_id, $a_exp_id, $a_type="pg")
Save export id.
getObjectList($lm_id, $type="")
static
getTitle()
get title of lm object
static _lookupTitle($a_obj_id)
Lookup title.
setType($a_type)
_lookupContObjID($a_id)
get learning module / digibook id for lm object
Class ilLMPageObject.
getMediaObjectIds()
get ids of all media objects within the page
_exportXMLAlias(&$a_xml_writer, $a_id, $a_inst=0)
export page alias to xml
exportXMLMetaData(&$a_xml_writer)
export page objects meta data to xml (see ilias_co.dtd)
getFileItemIds()
get ids of all file items within the page
copy($a_target_lm)
copy page
getPagesWithLinksList($a_lm_id, $a_par_type)
Get all pages of lm that contain any internal links.
_splitPageNext($a_page_id, $a_pg_parent_type, $a_hier_id)
split page to next page at hierarchical id
assignPageObject(&$a_page_obj)
assign page object
ilLMPageObject(&$a_content_obj, $a_id=0, $a_halt=true)
Constructor @access public.
& copyToOtherContObject(&$a_cont_obj, &$a_copied_nodes)
copy a page to another content object (learning module / dlib book)
create($a_upload=false, $a_omit_page_object_creation=false)
exportFO(&$a_xml_writer)
export page object to fo
& getPageObject()
get assigned page object
setAlias($a_is_alias)
set wether page object is an alias
_splitPage($a_page_id, $a_pg_parent_type, $a_hier_id)
split page at hierarchical id
exportXMLPageContent(&$a_xml_writer, $a_inst=0)
export page objects meta data to xml (see ilias_co.dtd)
exportXML(&$a_xml_writer, $a_mode="normal", $a_inst=0)
export page object to xml (see ilias_co.dtd)
getQuestionIds()
Get question ids.
static queryQuestionsOfLearningModule($a_lm_id, $a_order_field, $a_order_dir, $a_offset, $a_limit)
Get questions of learning module.
modifyExportIdentifier($a_tag, $a_param, $a_value)
static _getPresentationTitle($a_pg_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="-")
presentation title doesn't have to be page title, it may be chapter title + page title or chapter tit...
getPageList($lm_id)
static
Extension of ilPageObject for learning modules.
static getInstance($a_tree_id)
Get Instance.
Class ilObjDlBook.
Class ilObjLearningModule.
static getInstance($a_obj_id)
Get instance.
static _lookupType($a_id, $a_reference=false)
lookup object type
static collectFileItems($a_page, $a_domdoc)
Get all file items that are used within the page.
static _getQuestionIdsForPage($a_parent_type, $a_page_id, $a_lang="-")
Get all questions of a page.
_moveContentAfterHierId(&$a_source_page, &$a_target_page, $a_hid)
move content of hierarchical id >= $a_hid to other page
static _lookupActive($a_id, $a_parent_type, $a_check_scheduled_activation=false, $a_lang="-")
lookup activation status
static getPagesWithLinks($a_parent_type, $a_parent_id, $a_lang="-")
Get all pages for parent object that contain internal links.
_lookupActivationData($a_id, $a_parent_type, $a_lang="-")
Lookup activation data.
static _getPresentationTitle($a_st_id, $a_include_numbers=false, $a_time_scheduled_activation=false, $a_lm_id=0, $a_lang="-")
get presentation title
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
static now()
Return current timestamp in Y-m-d H:i:s format.
global $ilBench
Definition: ilias.php:18
global $ilDB