ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilPCContentTemplate.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5require_once("./Services/COPage/classes/class.ilPageContent.php");
6
17{
21 public function init()
22 {
23 $this->setType("templ");
24 }
25
29 public function setNode($a_node)
30 {
31 parent::setNode($a_node); // this is the PageContent node
32 }
33
42 public function create($a_pg_obj, $a_hier_id, $a_pc_id, $a_page_templ)
43 {
44 $source_id = explode(":", $a_page_templ);
45 $source_page = ilPageObjectFactory::getInstance($source_id[1], $source_id[0]);
46 $source_page->buildDom();
47 $source_page->addHierIds();
48 $hier_ids = $source_page->getHierIds();
49
50 $copy_ids = array();
51 foreach ($hier_ids as $hier_id) {
52 // move top level nodes only
53 if (!is_int(strpos($hier_id, "_"))) {
54 if ($hier_id != "pg") {
55 $copy_ids[] = $hier_id;
56 }
57 }
58 }
59 arsort($copy_ids);
60
61 foreach ($copy_ids as $copy_id) {
62 $source_content = $source_page->getContentObject($copy_id);
63
64 $source_node = $source_content->getNode();
65 $clone_node = $source_node->clone_node(true);
66 $clone_node->unlink_node($clone_node);
67
68 // insert cloned node at target
69 $source_content->setNode($clone_node);
70 $this->getPage()->insertContent($source_content, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
71
72 $xpath = new DOMXpath($this->getPage()->getDomDoc());
73 if ($clone_node->get_attribute("PCID") != "") {
74 $clone_node->set_attribute("PCID", "");
75 }
76 $els = $xpath->query(".//*[@PCID]", $clone_node->myDOMNode);
77 foreach ($els as $el) {
78 $el->setAttribute("PCID", "");
79 }
80 }
81
82 $this->getPage()->update();
83 }
84}
An exception for terminatinating execution or to throw for unit testing.
const IL_INSERT_AFTER
Content templates are not existing in the page.
init()
Init page content component.
create($a_pg_obj, $a_hier_id, $a_pc_id, $a_page_templ)
Insert content template.
setNode($a_node)
Set node (in fact this will never be called, since these types of nodes do not exist.
Class ilPageContent.
setType($a_type)
Set Type.
static getInstance($a_parent_type, $a_id=0, $a_old_nr=0, $a_lang="-")
Get page object instance.