ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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() && isset($languages[$a_lang])) {
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 $title = $trans_title;
412 }
413 }
414
415 if ($a_mode == self::PAGE_TITLE) {
416 return $title;
417 }
418
419 $tree = ilLMTree::getInstance($a_lm_id);
420
421 if ($tree->isInTree($a_pg_id)) {
422 $pred_node = $tree->fetchPredecessorNode($a_pg_id, "st");
423 $childs = $tree->getChildsByType($pred_node["obj_id"], "pg");
424 $cnt_str = "";
425 if (count($childs) > 1) {
426 $cnt = 0;
427 foreach ($childs as $child) {
429 $child["obj_id"],
430 ilObject::_lookupType($a_lm_id),
431 $a_time_scheduled_activation
432 );
433
434 if (!$active) {
435 $act_data = ilLMPage::_lookupActivationData((int) $child["obj_id"], ilObject::_lookupType($a_lm_id));
436 if ($act_data["show_activation_info"] &&
437 (ilUtil::now() < $act_data["activation_start"])) {
438 $active = true;
439 }
440 }
441
442 if ($child["type"] != "pg" || $active) {
443 $cnt++;
444 }
445 if ($child["obj_id"] == $a_pg_id) {
446 $cur_cnt = $cnt;
447 }
448 }
449 if ($cnt > 1) {
450 $cnt_str = " (" . $cur_cnt . "/" . $cnt . ")";
451 }
452 }
454 $pred_node["obj_id"],
455 self::CHAPTER_TITLE,
456 $a_include_numbers,
457 false,
458 false,
459 0,
460 $a_lang,
461 true
462 ) . $cnt_str;
463 } else {
464 return $title;
465 }
466 }
467
474 public function exportXML(&$a_xml_writer, $a_mode = "normal", $a_inst = 0)
475 {
476 $attrs = array();
477 $a_xml_writer->xmlStartTag("PageObject", $attrs);
478
479 switch ($a_mode) {
480 case "normal":
481 // MetaData
482 $this->exportXMLMetaData($a_xml_writer);
483
484 // PageContent
485 $this->exportXMLPageContent($a_xml_writer, $a_inst);
486 break;
487
488 case "alias":
489 $attrs = array();
490 $attrs["OriginId"] = "il_" . $a_inst .
491 "_pg_" . $this->getId();
492 $a_xml_writer->xmlElement("PageAlias", $attrs);
493 break;
494 }
495
496 // Layout
497 // not implemented
498
499 $a_xml_writer->xmlEndTag("PageObject");
500 }
501
505 public static function _exportXMLAlias(&$a_xml_writer, $a_id, $a_inst = 0)
506 {
507 $attrs = array();
508 $a_xml_writer->xmlStartTag("PageObject", $attrs);
509
510 $attrs = array();
511 $attrs["OriginId"] = "il_" . $a_inst .
512 "_pg_" . $a_id;
513 $a_xml_writer->xmlElement("PageAlias", $attrs);
514
515 $a_xml_writer->xmlEndTag("PageObject");
516 }
517
518
525 public function exportXMLMetaData(&$a_xml_writer)
526 {
527 $md2xml = new ilMD2XML($this->getLMId(), $this->getId(), $this->getType());
528 $md2xml->setExportMode(true);
529 $md2xml->startExport();
530 $a_xml_writer->appendXML($md2xml->getXML());
531 }
532
533 public function modifyExportIdentifier($a_tag, $a_param, $a_value)
534 {
535 if ($a_tag == "Identifier" && $a_param == "Entry") {
536 $a_value = "il_" . IL_INST_ID . "_pg_" . $this->getId();
537 //$a_value = ilUtil::insertInstIntoID($a_value);
538 }
539
540 return $a_value;
541 }
542
543
550 public function exportXMLPageContent(&$a_xml_writer, $a_inst = 0)
551 {
552 $cont_obj = $this->getContentObject();
553
554 $this->page_object->buildDom();
555 $this->page_object->insertInstIntoIDs($a_inst);
556 $this->mobs_contained = $this->page_object->collectMediaObjects(false);
557 $this->files_contained = ilPCFileList::collectFileItems($this->page_object, $this->page_object->getDomDoc());
558 $xml = $this->page_object->getXMLFromDom(false, false, false, "", true);
559 $xml = str_replace("&", "&amp;", $xml);
560 $a_xml_writer->appendXML($xml);
561
562 $this->page_object->freeDom();
563 }
564
570 public function getQuestionIds()
571 {
573 $this->content_object->getType(),
574 $this->getId()
575 );
576 }
577
583 public function getMediaObjectIds()
584 {
585 return $this->mobs_contained;
586 }
587
593 public function getFileItemIds()
594 {
595 return $this->files_contained;
596 }
597
604 public function exportFO(&$a_xml_writer)
605 {
607 if ($title != "") {
608 $attrs = array();
609 $attrs["font-family"] = "Times";
610 $attrs["font-size"] = "14pt";
611 $a_xml_writer->xmlElement("fo:block", $attrs, $title);
612 }
613
614 // PageContent
615 $this->page_object->buildDom();
616 $fo = $this->page_object->getFO();
617 $a_xml_writer->appendXML($fo);
618 }
619
626 public static function queryQuestionsOfLearningModule(
627 $a_lm_id,
628 $a_order_field,
629 $a_order_dir,
630 $a_offset,
631 $a_limit
632 ) {
633 global $DIC;
634
635 $ilDB = $DIC->database();
636 $rbacreview = $DIC->rbac()->review();
637
638
639 // count query
640 $count_query = "SELECT count(pq.question_id) cnt ";
641
642 // basic query
643 $query = "SELECT pq.page_id, pq.question_id ";
644
645 $from = " FROM page_question pq JOIN lm_tree t ON (t.lm_id = " . $ilDB->quote($a_lm_id, "integer") .
646 " AND pq.page_id = t.child and pq.page_parent_type = " . $ilDB->quote("lm", "text") . ") " .
647 " WHERE t.lm_id = " . $ilDB->quote($a_lm_id, "integer");
648 $count_query .= $from;
649 $query .= $from;
650
651
652 // count query
653 $set = $ilDB->query($count_query);
654 $cnt = 0;
655 if ($rec = $ilDB->fetchAssoc($set)) {
656 $cnt = $rec["cnt"];
657 }
658
659 $offset = (int) $a_offset;
660 $limit = (int) $a_limit;
661 if ($a_limit > 0) {
662 $ilDB->setLimit($limit, $offset);
663 }
664
665 // set query
666 $set = $ilDB->query($query);
667 $result = array();
668 while ($rec = $ilDB->fetchAssoc($set)) {
669 $result[] = $rec;
670 }
671 return array("cnt" => $cnt, "set" => $result);
672 }
673
677 public static function insertPagesFromTemplate($lm_id, $num, $node_id, $first_child, $layout_id, $title = "")
678 {
679 global $DIC;
680
681 $lng = $DIC->language();
682
683 if ($title == "") {
684 $title = $lng->txt("cont_new_page");
685 }
686 $lm_tree = new ilLMTree($lm_id);
687 $lm = new ilObjLearningModule($lm_id, false);
688 if (!$first_child) { // insert after node id
689 $parent_id = $lm_tree->getParentId($node_id);
690 $target = $node_id;
691 } else { // insert as first child
692 $parent_id = $node_id;
693 $target = IL_FIRST_NODE;
694 }
695
696 $page_ids = array();
697 for ($i = 1; $i <= $num; $i++) {
698 $page = new ilLMPageObject($lm);
699 $page->setTitle($title);
700 $page->setLMId($lm->getId());
701 $page->create(false, false, $layout_id);
702 ilLMObject::putInTree($page, $parent_id, $target);
703 $page_ids[] = $page->getId();
704 }
705 $page_ids = array_reverse($page_ids);
706 return $page_ids;
707 }
708}
$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.
$i
Definition: metadata.php:24
$xml
Definition: metadata.php:332
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$query
$lng
global $ilDB
$DIC
Definition: xapitoken.php:46