ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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
32 protected function getTemplatePage(string $a_page_templ): ilPageObject
33 {
34 $source_id = explode(":", $a_page_templ);
35 return $this->getPageManager()->get($source_id[1], (int) $source_id[0]);
36 }
37
38 public function create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id, string $a_page_templ): void
39 {
40 $source_id = explode(":", $a_page_templ);
42 $source_id[1],
43 (int) $source_id[0],
44 0,
45 $this->getPage()->getLanguage()
46 );
47 $source_page->buildDom();
48 $source_page->addHierIDs();
49 $hier_ids = $source_page->getHierIds();
50
51 $copy_ids = array();
52 foreach ($hier_ids as $hier_id) {
53 // move top level nodes only
54 if (!is_int(strpos($hier_id, "_"))) {
55 if ($hier_id != "pg") {
56 $copy_ids[] = $hier_id;
57 }
58 }
59 }
60 arsort($copy_ids);
61 foreach ($copy_ids as $copy_id) {
62 $source_content = $source_page->getContentObject($copy_id);
63
64 $source_node = $source_content->getDomNode();
65 $clone_node = $source_node->cloneNode(true);
66 $clone_node = $this->getPage()->getDomDoc()->importNode($clone_node, true);
67
68 // insert cloned node at target
69 $source_content->setDomNode($clone_node);
70 $this->getPage()->insertContent($source_content, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
71 $xpath = new DOMXpath($this->getPage()->getDomDoc());
72 if ($clone_node->getAttribute("PCID") != "") {
73 $clone_node->setAttribute("PCID", "");
74 }
75 $els = $xpath->query(".//*[@PCID]", $clone_node);
76 foreach ($els as $el) {
77 $el->setAttribute("PCID", "");
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...
getTemplatePage(string $a_page_templ)
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id, string $a_page_templ)
Content object of ilPageObject (see ILIAS DTD).
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)
getLanguage()