ILIAS  release_8 Revision v8.24
class.ilPCContentTemplate.php
Go to the documentation of this file.
1<?php
2
26{
27 public function init(): void
28 {
29 $this->setType("templ");
30 }
31
35 public function setNode(php4DOMElement $a_node): void
36 {
37 parent::setNode($a_node); // this is the PageContent node
38 }
39
40 public function create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id, string $a_page_templ): void
41 {
42 $source_id = explode(":", $a_page_templ);
43 $source_page = ilPageObjectFactory::getInstance($source_id[1], $source_id[0]);
44 $source_page->buildDom();
45 $source_page->addHierIDs();
46 $hier_ids = $source_page->getHierIds();
47
48 $copy_ids = array();
49 foreach ($hier_ids as $hier_id) {
50 // move top level nodes only
51 if (!is_int(strpos($hier_id, "_"))) {
52 if ($hier_id != "pg") {
53 $copy_ids[] = $hier_id;
54 }
55 }
56 }
57 arsort($copy_ids);
58
59 foreach ($copy_ids as $copy_id) {
60 $source_content = $source_page->getContentObject($copy_id);
61
62 $source_node = $source_content->getNode();
63 $clone_node = $source_node->clone_node(true);
64 $clone_node->unlink_node($clone_node);
65
66 // insert cloned node at target
67 $source_content->setNode($clone_node);
68 $this->getPage()->insertContent($source_content, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
69
70 $xpath = new DOMXpath($this->getPage()->getDomDoc());
71 if ($clone_node->get_attribute("PCID") != "") {
72 $clone_node->set_attribute("PCID", "");
73 }
74 $els = $xpath->query(".//*[@PCID]", $clone_node->myDOMNode);
75 foreach ($els as $el) {
76 $el->setAttribute("PCID", "");
77 }
78 }
79
80 $this->getPage()->update();
81 }
82}
const IL_INSERT_AFTER
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setNode(php4DOMElement $a_node)
Set node (in fact this will never be called, since these types of nodes do not exist.
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id, string $a_page_templ)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setType(string $a_type)
Set Type.
static getInstance(string $a_parent_type, int $a_id=0, int $a_old_nr=0, string $a_lang="-")
Get page object instance.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)