ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPCLayoutTemplate.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 public function init(): void
30 {
31 $this->setType("lay");
32 }
33
34 public function create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id, int $a_tmpl): void
35 {
36 $source_page = ilPageObjectFactory::getInstance("stys", $a_tmpl);
37 $source_page->buildDom();
38 $source_page->addHierIDs();
39 $hier_ids = $source_page->getHierIds();
40
41 $copy_ids = array();
42 foreach ($hier_ids as $hier_id) {
43 // move top level nodes only
44 if (!is_int(strpos($hier_id, "_"))) {
45 if ($hier_id != "pg") {
46 $copy_ids[] = $hier_id;
47 }
48 }
49 }
50 arsort($copy_ids);
51
52 foreach ($copy_ids as $copy_id) {
53 $source_content = $source_page->getContentObject($copy_id);
54
55 $source_node = $source_content->getDomNode();
56 $clone_node = $source_node->cloneNode(true);
57 $this->log->debug($this->dom_util->dump($clone_node));
58 //$clone_node->unlink_node($clone_node);
59 $clone_node = $this->getPage()->getDomDoc()->importNode($clone_node, true);
60
61 // insert cloned node at target
62 $source_content->setDomNode($clone_node);
63 $this->getPage()->insertContent($source_content, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
64
65 $xpath = new DOMXpath($this->getPage()->getDomDoc());
66 if ($clone_node->getAttribute("PCID") != "") {
67 $clone_node->setAttribute("PCID", "");
68 }
69 $els = $xpath->query(".//*[@PCID]", $clone_node);
70 foreach ($els as $el) {
71 $el->setAttribute("PCID", "");
72 }
73 }
74
75 $this->getPage()->update();
76 }
77}
const IL_INSERT_AFTER
Layout templates are not existing in the page.
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id, int $a_tmpl)
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)