ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilLMPageObject.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
23{
24 public $is_alias;
25 public $origin_id;
26 public $id;
27 public $dom;
29
34 public function __construct(&$a_content_obj, $a_id = 0, $a_halt = true)
35 {
36 parent::__construct($a_content_obj, $a_id);
37 $this->setType("pg");
38 $this->id = $a_id;
39
40 $this->is_alias = false;
41 $this->contains_int_link = false;
42 $this->mobs_contained = array();
43 $this->files_contained = array();
44 $this->halt_on_error = $a_halt;
45
46 if ($a_id != 0) {
47 $this->read();
48 }
49 }
50
51 public function __desctruct()
52 {
53 if (is_object($this->page_object)) {
54 unset($this->page_object);
55 }
56 }
57
61 public function read()
62 {
63 parent::read();
64
65 $this->page_object = new ilLMPage($this->id, 0);
66 }
67
68 public function create($a_upload = false, $a_omit_page_object_creation = false, $a_layout_id = 0)
69 {
70 parent::create($a_upload);
71 if ($a_omit_page_object_creation) {
72 return;
73 }
74 if (!is_object($this->page_object)) {
75 $this->page_object = new ilLMPage();
76 }
77 $this->page_object->setId($this->getId());
78 $this->page_object->setParentId($this->getLMId());
79 if ($a_layout_id == 0) {
80 $this->page_object->create($a_upload);
81 } else {
82 $this->page_object->createWithLayoutId($a_layout_id);
83 }
84 }
85
86 public function delete($a_delete_meta_data = true)
87 {
88 parent::delete($a_delete_meta_data);
89 $this->page_object->delete();
90 }
91
92
96 public function copy($a_target_lm)
97 {
98 // copy page
99 $lm_page = new ilLMPageObject($a_target_lm);
100 $lm_page->setTitle($this->getTitle());
101 $lm_page->setShortTitle($this->getShortTitle());
102 $lm_page->setLayout($this->getLayout());
103 $lm_page->setLMId($a_target_lm->getId());
104 $lm_page->setType($this->getType());
105 $lm_page->setDescription($this->getDescription());
106 $lm_page->setImportId("il__pg_" . $this->getId());
107 $lm_page->create(true); // setting "upload" flag to true prevents creating of meta data
108
109 // check whether export id already exists in the target lm
110 $del_exp_id = false;
111 $exp_id = ilLMPageObject::getExportId($this->getLMId(), $this->getId());
112 if (trim($exp_id) != "") {
113 if (ilLMPageObject::existsExportID($a_target_lm->getId(), $exp_id)) {
114 $del_exp_id = true;
115 }
116 }
117
118 // copy meta data
119 $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
120 $new_md = $md->cloneMD($a_target_lm->getId(), $lm_page->getId(), $this->getType());
121
122 // check whether export id already exists in the target lm
123 if ($del_exp_id) {
124 ilLMPageObject::saveExportId($a_target_lm->getId(), $lm_page->getId(), "");
125 } else {
127 $a_target_lm->getId(),
128 $lm_page->getId(),
129 trim($exp_id)
130 );
131 }
132
133 // copy page content and activation
134 $page = $lm_page->getPageObject();
135 $this->page_object->copy($page->getId(), $page->getParentType(), $page->getParentId());
136 $lm_page->read(); // this gets the updated page object into lm page
137
138 // copy translations
139 ilLMObjTranslation::copy($this->getId(), $lm_page->getId());
140
141 return $lm_page;
142 }
143
147 public function &copyToOtherContObject(&$a_cont_obj, &$a_copied_nodes)
148 {
149 // copy page
150 $lm_page = new ilLMPageObject($a_cont_obj);
151 $lm_page->setTitle($this->getTitle());
152 $lm_page->setShortTitle($this->getShortTitle());
153 $lm_page->setLMId($a_cont_obj->getId());
154 $lm_page->setImportId("il__pg_" . $this->getId());
155 $lm_page->setType($this->getType());
156 $lm_page->setDescription($this->getDescription());
157 $lm_page->create(true); // setting "upload" flag to true prevents creating of meta data
158 $a_copied_nodes[$this->getId()] = $lm_page->getId();
159
160 // copy meta data
161 $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
162 $new_md = $md->cloneMD($a_cont_obj->getId(), $lm_page->getId(), $this->getType());
163
164 // copy page content
165 $page = $lm_page->getPageObject();
166 $page->setXMLContent($this->page_object->getXMLContent());
167 $page->buildDom();
168 $page->update();
169
170 return $lm_page;
171 }
172
180 public static function _splitPage($a_page_id, $a_pg_parent_type, $a_hier_id)
181 {
182 // get content object (learning module / digilib book)
185 $cont_obj = new ilObjLearningModule($lm_id, false);
186 $source_lm_page = new ilLMPageObject($cont_obj, $a_page_id);
187
188 // create new page
189 $lm_page = new ilLMPageObject($cont_obj);
190 $lm_page->setTitle($source_lm_page->getTitle());
191 $lm_page->setLMId($source_lm_page->getLMId());
192 $lm_page->setType($source_lm_page->getType());
193 $lm_page->setDescription($source_lm_page->getDescription());
194 $lm_page->create(true);
195
196
197 // copy complete content of source page to new page
198 $source_page = $source_lm_page->getPageObject();
199 $page = $lm_page->getPageObject();
200 $page->setXMLContent($source_page->copyXMLContent());
201 //echo htmlentities($source_page->copyXMLContent());
202 $page->buildDom(true);
203 $page->update();
204 // echo "-".$page->getId()."-".$page->getParentType()."-";
205
206 // copy meta data
207 $md = new ilMD($source_lm_page->getLMId(), $a_page_id, $source_lm_page->getType());
208 $md->cloneMD($source_lm_page->getLMId(), $lm_page->getId(), $source_lm_page->getType());
209
210 // insert new page in tree (after original page)
211 $tree = new ilTree($cont_obj->getId());
212 $tree->setTableNames('lm_tree', 'lm_data');
213 $tree->setTreeTablePK("lm_id");
214 if ($tree->isInTree($source_lm_page->getId())) {
215 $parent_node = $tree->getParentNodeData($source_lm_page->getId());
216 $tree->insertNode($lm_page->getId(), $parent_node["child"], $source_lm_page->getId());
217 }
218
219 // remove all nodes < hierarchical id from new page (incl. update)
220 $page->addHierIds();
221 $page->deleteContentBeforeHierId($a_hier_id);
222 // $page->update();
223
224 // remove all nodes >= hierarchical id from source page
225 $source_page->buildDom();
226 $source_page->addHierIds();
227 $source_page->deleteContentFromHierId($a_hier_id);
228
229 return $lm_page;
230 }
231
239 public static function _splitPageNext($a_page_id, $a_pg_parent_type, $a_hier_id)
240 {
241 // get content object (learning module / digilib book)
244 $cont_obj = new ilObjLearningModule($lm_id, false);
245 $tree = new ilTree($cont_obj->getId());
246 $tree->setTableNames('lm_tree', 'lm_data');
247 $tree->setTreeTablePK("lm_id");
248
249 $source_lm_page = new ilLMPageObject($cont_obj, $a_page_id);
250 $source_page = $source_lm_page->getPageObject();
251
252 // get next page
253 $succ = $tree->fetchSuccessorNode($a_page_id, "pg");
254 if ($succ["child"] > 0) {
255 $target_lm_page = new ilLMPageObject($cont_obj, $succ["child"]);
256 $target_page = $target_lm_page->getPageObject();
257 $target_page->buildDom();
258 $target_page->addHierIds();
259
260 // move nodes to target page
261 $source_page->buildDom();
262 $source_page->addHierIds();
263 ilLMPage::_moveContentAfterHierId($source_page, $target_page, $a_hier_id);
264 //$source_page->deleteContentFromHierId($a_hier_id);
265
266 return $succ["child"];
267 }
268 }
269
270
276 public function assignPageObject(&$a_page_obj)
277 {
278 $this->page_object = $a_page_obj;
279 }
280
281
287 public function &getPageObject()
288 {
289 return $this->page_object;
290 }
291
292
296 public function setId($a_id)
297 {
298 $this->id = $a_id;
299 }
300
301 public function getId()
302 {
303 return $this->id;
304 }
305
309 public function setAlias($a_is_alias)
310 {
311 $this->is_alias = $a_is_alias;
312 }
313
314 public function isAlias()
315 {
316 return $this->is_alias;
317 }
318
319 // only for page aliases
320 public function setOriginID($a_id)
321 {
322 return $this->origin_id = $a_id;
323 }
324
325 // only for page aliases
326 public function getOriginID()
327 {
328 return $this->origin_id;
329 }
330
334 public static function getPageList($lm_id)
335 {
336 return ilLMObject::getObjectList($lm_id, "pg");
337 }
338
342 public static function getPagesWithLinksList($a_lm_id, $a_par_type)
343 {
344 $pages = ilLMPageObject::getPageList($a_lm_id);
345 $ids = array();
346 foreach ($pages as $page) {
347 $ids[] = $page["obj_id"];
348 }
349
350 $linked_pages = ilLMPage::getPagesWithLinks($a_par_type, $a_lm_id);
351 $result = array();
352 foreach ($pages as $page) {
353 if (is_array($linked_pages[$page["obj_id"]])) {
354 $result[] = $page;
355 }
356 }
357 return $result;
358 }
359
366 public static function _getPresentationTitle(
367 $a_pg_id,
368 $a_mode = self::CHAPTER_TITLE,
369 $a_include_numbers = false,
370 $a_time_scheduled_activation = false,
371 $a_force_content = false,
372 $a_lm_id = 0,
373 $a_lang = "-",
374 $a_include_short = false
375 ) {
376 if ($a_mode == self::NO_HEADER && !$a_force_content) {
377 return "";
378 }
379
380 if ($a_lm_id == 0) {
381 $a_lm_id = ilLMObject::_lookupContObjID($a_pg_id);
382 }
383
384 if ($a_lm_id == 0) {
385 return "";
386 }
387
388 // this is optimized when ilLMObject::preloadDataByLM is invoked (e.g. done in ilLMExplorerGUI)
389 $title = "";
390 if ($a_include_short) {
391 $title = trim(ilLMObject::_lookupShortTitle($a_pg_id));
392 }
393 if ($title == "") {
395 }
396
397 // this is also optimized since ilObjectTranslation re-uses instances for one lm
398 $ot = ilObjectTranslation::getInstance($a_lm_id);
399 $languages = $ot->getLanguages();
400
401 if ($a_lang != "-" && $ot->getContentActivated()) {
402 $lmobjtrans = new ilLMObjTranslation($a_pg_id, $a_lang);
403 $trans_title = "";
404 if ($a_include_short) {
405 $trans_title = trim($lmobjtrans->getShortTitle());
406 }
407 if ($trans_title == "") {
408 $trans_title = $lmobjtrans->getTitle();
409 }
410 if ($trans_title == "") {
411 $lmobjtrans = new ilLMObjTranslation($a_pg_id, $ot->getFallbackLanguage());
412 $trans_title = $lmobjtrans->getTitle();
413 }
414 if ($trans_title != "") {
415 $title = $trans_title;
416 }
417 }
418
419 if ($a_mode == self::PAGE_TITLE) {
420 return $title;
421 }
422
423 $tree = ilLMTree::getInstance($a_lm_id);
424
425 if ($tree->isInTree($a_pg_id)) {
426 $pred_node = $tree->fetchPredecessorNode($a_pg_id, "st");
427 $childs = $tree->getChildsByType($pred_node["obj_id"], "pg");
428 $cnt_str = "";
429 if (count($childs) > 1) {
430 $cnt = 0;
431 foreach ($childs as $child) {
433 $child["obj_id"],
434 ilObject::_lookupType($a_lm_id),
435 $a_time_scheduled_activation
436 );
437
438 if (!$active) {
439 $act_data = ilLMPage::_lookupActivationData((int) $child["obj_id"], ilObject::_lookupType($a_lm_id));
440 if ($act_data["show_activation_info"] &&
441 (ilUtil::now() < $act_data["activation_start"])) {
442 $active = true;
443 }
444 }
445
446 if ($child["type"] != "pg" || $active) {
447 $cnt++;
448 }
449 if ($child["obj_id"] == $a_pg_id) {
450 $cur_cnt = $cnt;
451 }
452 }
453 if ($cnt > 1) {
454 $cnt_str = " (" . $cur_cnt . "/" . $cnt . ")";
455 }
456 }
458 $pred_node["obj_id"],
459 self::CHAPTER_TITLE,
460 $a_include_numbers,
461 false,
462 false,
463 0,
464 $a_lang,
465 true
466 ) . $cnt_str;
467 } else {
468 return $title;
469 }
470 }
471
478 public function exportXML(&$a_xml_writer, $a_mode = "normal", $a_inst = 0)
479 {
480 $attrs = array();
481 $a_xml_writer->xmlStartTag("PageObject", $attrs);
482
483 switch ($a_mode) {
484 case "normal":
485 // MetaData
486 $this->exportXMLMetaData($a_xml_writer);
487
488 // PageContent
489 $this->exportXMLPageContent($a_xml_writer, $a_inst);
490 break;
491
492 case "alias":
493 $attrs = array();
494 $attrs["OriginId"] = "il_" . $a_inst .
495 "_pg_" . $this->getId();
496 $a_xml_writer->xmlElement("PageAlias", $attrs);
497 break;
498 }
499
500 // Layout
501 // not implemented
502
503 $a_xml_writer->xmlEndTag("PageObject");
504 }
505
509 public static function _exportXMLAlias(&$a_xml_writer, $a_id, $a_inst = 0)
510 {
511 $attrs = array();
512 $a_xml_writer->xmlStartTag("PageObject", $attrs);
513
514 $attrs = array();
515 $attrs["OriginId"] = "il_" . $a_inst .
516 "_pg_" . $a_id;
517 $a_xml_writer->xmlElement("PageAlias", $attrs);
518
519 $a_xml_writer->xmlEndTag("PageObject");
520 }
521
522
529 public function exportXMLMetaData(&$a_xml_writer)
530 {
531 $md2xml = new ilMD2XML($this->getLMId(), $this->getId(), $this->getType());
532 $md2xml->setExportMode(true);
533 $md2xml->startExport();
534 $a_xml_writer->appendXML($md2xml->getXML());
535 }
536
537 public function modifyExportIdentifier($a_tag, $a_param, $a_value)
538 {
539 if ($a_tag == "Identifier" && $a_param == "Entry") {
540 $a_value = "il_" . IL_INST_ID . "_pg_" . $this->getId();
541 //$a_value = ilUtil::insertInstIntoID($a_value);
542 }
543
544 return $a_value;
545 }
546
547
554 public function exportXMLPageContent(&$a_xml_writer, $a_inst = 0)
555 {
556 $cont_obj = $this->getContentObject();
557
558 $this->page_object->buildDom();
559 $this->page_object->insertInstIntoIDs($a_inst);
560 $this->mobs_contained = $this->page_object->collectMediaObjects(false);
561 $this->files_contained = ilPCFileList::collectFileItems($this->page_object, $this->page_object->getDomDoc());
562 $xml = $this->page_object->getXMLFromDom(false, false, false, "", true);
563 $xml = str_replace("&", "&amp;", $xml);
564 $a_xml_writer->appendXML($xml);
565
566 $this->page_object->freeDom();
567 }
568
574 public function getQuestionIds()
575 {
577 $this->content_object->getType(),
578 $this->getId()
579 );
580 }
581
587 public function getMediaObjectIds()
588 {
589 return $this->mobs_contained;
590 }
591
597 public function getFileItemIds()
598 {
599 return $this->files_contained;
600 }
601
608 public function exportFO(&$a_xml_writer)
609 {
611 if ($title != "") {
612 $attrs = array();
613 $attrs["font-family"] = "Times";
614 $attrs["font-size"] = "14pt";
615 $a_xml_writer->xmlElement("fo:block", $attrs, $title);
616 }
617
618 // PageContent
619 $this->page_object->buildDom();
620 $fo = $this->page_object->getFO();
621 $a_xml_writer->appendXML($fo);
622 }
623
630 public static function queryQuestionsOfLearningModule(
631 $a_lm_id,
632 $a_order_field,
633 $a_order_dir,
634 $a_offset,
635 $a_limit
636 ) {
637 global $DIC;
638
639 $ilDB = $DIC->database();
640 $rbacreview = $DIC->rbac()->review();
641
642
643 // count query
644 $count_query = "SELECT count(pq.question_id) cnt ";
645
646 // basic query
647 $query = "SELECT pq.page_id, pq.question_id ";
648
649 $from = " FROM page_question pq JOIN lm_tree t ON (t.lm_id = " . $ilDB->quote($a_lm_id, "integer") .
650 " AND pq.page_id = t.child and pq.page_parent_type = " . $ilDB->quote("lm", "text") . ") " .
651 " WHERE t.lm_id = " . $ilDB->quote($a_lm_id, "integer");
652 $count_query .= $from;
653 $query .= $from;
654
655
656 // count query
657 $set = $ilDB->query($count_query);
658 $cnt = 0;
659 if ($rec = $ilDB->fetchAssoc($set)) {
660 $cnt = $rec["cnt"];
661 }
662
663 $offset = (int) $a_offset;
664 $limit = (int) $a_limit;
665 if ($a_limit > 0) {
666 $ilDB->setLimit($limit, $offset);
667 }
668
669 // set query
670 $set = $ilDB->query($query);
671 $result = array();
672 while ($rec = $ilDB->fetchAssoc($set)) {
673 $result[] = $rec;
674 }
675 return array("cnt" => $cnt, "set" => $result);
676 }
677
681 public static function insertPagesFromTemplate($lm_id, $num, $node_id, $first_child, $layout_id, $title = "")
682 {
683 global $DIC;
684
685 $lng = $DIC->language();
686
687 if ($title == "") {
688 $title = $lng->txt("cont_new_page");
689 }
690 $lm_tree = new ilLMTree($lm_id);
691 $lm = new ilObjLearningModule($lm_id, false);
692 if (!$first_child) { // insert after node id
693 $parent_id = $lm_tree->getParentId($node_id);
694 $target = $node_id;
695 } else { // insert as first child
696 $parent_id = $node_id;
697 $target = IL_FIRST_NODE;
698 }
699
700 $page_ids = array();
701 for ($i = 1; $i <= $num; $i++) {
702 $page = new ilLMPageObject($lm);
703 $page->setTitle($title);
704 $page->setLMId($lm->getId());
705 $page->create(false, false, $layout_id);
706 ilLMObject::putInTree($page, $parent_id, $target);
707 $page_ids[] = $page->getId();
708 }
709 $page_ids = array_reverse($page_ids);
710 return $page_ids;
711 }
712}
$result
An exception for terminatinating execution or to throw for unit testing.
const IL_FIRST_NODE
Definition: class.ilTree.php:5
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.
static getObjectList($lm_id, $type="")
static
static _lookupShortTitle($a_obj_id)
Lookup short title.
static _lookupContObjID($a_id)
get learning module / digibook id for lm object
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.
getTitle()
get title of lm object
static _lookupTitle($a_obj_id)
Lookup title.
setType($a_type)
static putInTree($a_obj, $a_parent_id="", $a_target_node_id="")
put this object into content object tree
getShortTitle()
get short title of lm object
Class ilLMPageObject.
getMediaObjectIds()
get ids of all media objects within the page
exportXMLMetaData(&$a_xml_writer)
export page objects meta data to xml (see ilias_co.dtd)
static _splitPageNext($a_page_id, $a_pg_parent_type, $a_hier_id)
split page to next page at hierarchical id
getFileItemIds()
get ids of all file items within the page
static _splitPage($a_page_id, $a_pg_parent_type, $a_hier_id)
split page at hierarchical id
copy($a_target_lm)
copy page
static insertPagesFromTemplate($lm_id, $num, $node_id, $first_child, $layout_id, $title="")
Insert (multiple) pages templates at node.
assignPageObject(&$a_page_obj)
assign page object
& copyToOtherContObject(&$a_cont_obj, &$a_copied_nodes)
copy a page to another content object (learning module / dlib book)
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
static getPageList($lm_id)
static
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.
modifyExportIdentifier($a_tag, $a_param, $a_value)
static queryQuestionsOfLearningModule( $a_lm_id, $a_order_field, $a_order_dir, $a_offset, $a_limit)
Get questions of learning module.
static getPagesWithLinksList($a_lm_id, $a_par_type)
Get all pages of lm that contain any internal links.
static _exportXMLAlias(&$a_xml_writer, $a_id, $a_inst=0)
export page alias to xml
static _getPresentationTitle( $a_pg_id, $a_mode=self::CHAPTER_TITLE, $a_include_numbers=false, $a_time_scheduled_activation=false, $a_force_content=false, $a_lm_id=0, $a_lang="-", $a_include_short=false)
presentation title doesn't have to be page title, it may be chapter title + page title or chapter tit...
__construct(&$a_content_obj, $a_id=0, $a_halt=true)
Constructor @access public.
create($a_upload=false, $a_omit_page_object_creation=false, $a_layout_id=0)
Extension of ilPageObject for learning modules.
static getInstance($a_tree_id)
Get Instance.
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.
static _lookupActive($a_id, $a_parent_type, $a_check_scheduled_activation=false, $a_lang="-")
lookup activation status
static _lookupActivationData($a_id, $a_parent_type, $a_lang="-")
Lookup activation data.
static getPagesWithLinks($a_parent_type, $a_parent_id, $a_lang="-")
Get all pages for parent object that contain internal links.
static _moveContentAfterHierId(&$a_source_page, &$a_target_page, $a_hid)
move content of hierarchical id >= $a_hid to other page
static _getPresentationTitle( $a_st_id, $a_mode=self::CHAPTER_TITLE, $a_include_numbers=false, $a_time_scheduled_activation=false, $a_force_content=false, $a_lm_id=0, $a_lang="-", $a_include_short=false)
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.
const IL_INST_ID
Definition: constants.php:38
global $DIC
Definition: goto.php:24
$i
Definition: metadata.php:24
$xml
Definition: metadata.php:332
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$query
$lng
global $ilDB