ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
5 require_once("./Services/COPage/classes/class.ilPageContent.php");
6 
17 {
21  function init()
22  {
23  $this->setType("templ");
24  }
25 
29  function setNode($a_node)
30  {
31  parent::setNode($a_node); // this is the PageContent node
32  }
33 
42  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  {
53  // move top level nodes only
54  if (!is_int(strpos($hier_id, "_")))
55  {
56  if ($hier_id != "pg" && $hier_id >= $a_hid)
57  {
58  $copy_ids[] = $hier_id;
59  }
60  }
61  }
62  asort($copy_ids);
63 
64  // get the target parent node
65  $pos = explode("_", $a_pos);
66  array_pop($pos);
67  $parent_pos = implode($pos, "_");
68  if($parent_pos != "")
69  {
70  $target_parent = $a_pg_obj->getContentNode($parent_pos);
71  }
72  else
73  {
74  $target_parent = $a_pg_obj->getNode();
75  }
76 
77  //$source_parent = $source_page->getContentNode("pg");
78 
79  $curr_node = $a_pg_obj->getContentNode($a_hier_id, $a_pcid);
80 
81  foreach ($copy_ids as $copy_id)
82  {
83  $source_node = $source_page->getContentNode($copy_id);
84  $new_node = $source_node->clone_node(true);
85  $new_node->unlink_node($new_node);
86 
87  if ($succ_node = $curr_node->next_sibling())
88  {
89  $succ_node->insert_before($new_node, $succ_node);
90  }
91  else
92  {
93 //echo "movin doin append_child";
94  $target_parent->append_child($new_node);
95  }
96 
97  //$xpc = xpath_new_context($a_pg_obj->getDomDoc());
98  $xpath = new DOMXpath($a_pg_obj->getDomDoc());
99 //var_dump($new_node->myDOMNode);
100 //echo "-".$new_node->get_attribute("PCID")."-"; exit;
101  if ($new_node->get_attribute("PCID") != "")
102  {
103  $new_node->set_attribute("PCID", "");
104  }
105  $els = $xpath->query(".//*[@PCID]", $new_node->myDOMNode);
106  foreach ($els as $el)
107  {
108  $el->setAttribute("PCID", "");
109  }
110  $curr_node = $new_node;
111  }
112 
113  $a_pg_obj->update();
114 
115  //$this->node = $this->createPageContentNode();
116 
117  /*$a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
118  $this->map_node =& $this->dom->create_element("Map");
119  $this->map_node =& $this->node->append_child($this->map_node);
120  $this->map_node->set_attribute("Latitude", "0");
121  $this->map_node->set_attribute("Longitude", "0");
122  $this->map_node->set_attribute("Zoom", "3");*/
123  }
124 
125 
126 }
127 
128 ?>