ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilPCDataTable.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2008 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24require_once("./Services/COPage/classes/class.ilPageContent.php");
25require_once("./Services/COPage/classes/class.ilPCTable.php");
26
39{
40 public $dom;
41 public $tab_node;
42
46 public function init()
47 {
48 $this->setType("dtab");
49 }
50
51 public function setNode($a_node)
52 {
53 parent::setNode($a_node); // this is the PageContent node
54 $this->tab_node = $a_node->first_child(); // this is the Table node
55 }
56
57 public function create(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
58 {
59 $this->node = $this->createPageContentNode();
60 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
61 $this->tab_node = $this->dom->create_element("Table");
62 $this->tab_node = $this->node->append_child($this->tab_node);
63 $this->tab_node->set_attribute("Language", "");
64 $this->tab_node->set_attribute("DataTable", "y");
65 }
66
67
71 public function makeEmptyCell($td_node)
72 {
73 // delete children of paragraph node
74 $children = $td_node->child_nodes();
75 for ($i = 0; $i < count($children); $i++) {
76 $td_node->remove_child($children[$i]);
77 }
78
79 // create page content and paragraph node here.
80 $pc_node = $this->createPageContentNode(false);
81 $pc_node = $td_node->append_child($pc_node);
82 $par_node = $this->dom->create_element("Paragraph");
83 $par_node = $pc_node->append_child($par_node);
84 $par_node->set_attribute("Characteristic", "TableContent");
85 $par_node->set_attribute(
86 "Language",
87 $this->getLanguage()
88 );
89 }
90
91
95 public function setData($a_data)
96 {
97 $ok = true;
98 //var_dump($a_data);
99 if (is_array($a_data)) {
100 foreach ($a_data as $i => $row) {
101 if (is_array($row)) {
102 foreach ($row as $j => $cell) {
103 //echo "<br><br>=".$cell."=";
104 $temp_dom = @domxml_open_mem(
105 '<?xml version="1.0" encoding="UTF-8"?><Paragraph>' . $cell . '</Paragraph>',
107 $error
108 );
109
110 $par_node = $this->getCellNode($i, $j, true);
111 //echo "<br>=".htmlentities($this->dom->dump_node($par_node))."=";
112 //echo "<br>-$i-$j-$cell-";
113 // remove all childs
114 if (empty($error) && is_object($par_node)) {
115 // delete children of paragraph node
116 $children = $par_node->child_nodes();
117 for ($k = 0; $k < count($children); $k++) {
118 $par_node->remove_child($children[$k]);
119 }
120
121 // copy new content children in paragraph node
122 $xpc = xpath_new_context($temp_dom);
123 $path = "//Paragraph";
124 $res = xpath_eval($xpc, $path);
125
126 if (count($res->nodeset) == 1) {
127 $new_par_node = $res->nodeset[0];
128 $new_childs = $new_par_node->child_nodes();
129 for ($l = 0; $l < count($new_childs); $l++) {
130 $cloned_child = $new_childs[$l]->clone_node(true);
131 $par_node->append_child($cloned_child);
132 //echo "<br>=".htmlentities($this->dom->dump_node($cloned_child))."=";
133 }
134 }
135 } else {
136 if (!empty($error)) {
137 return $error;
138 }
139 }
140 }
141 }
142 }
143 }
144 //exit;
145 return true;
146 }
147}
An exception for terminatinating execution or to throw for unit testing.
const IL_INSERT_AFTER
Class ilPCDataTable.
makeEmptyCell($td_node)
Make cell empty.
init()
Init page content component.
setData($a_data)
Set data of cells.
create(&$a_pg_obj, $a_hier_id, $a_pc_id="")
setNode($a_node)
Set xml node of page content.
Class ilPCTable.
getCellNode($i, $j, $create_if_not_exists=false)
Get cell paragraph node of row $i and cell $j.
getLanguage()
get table language
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element)
setType($a_type)
Set Type.
xpath_eval($xpath_context, $eval_str, $contextnode=null)
domxml_open_mem($str, $mode=0, &$error=null)
xpath_new_context($dom_document)
const DOMXML_LOAD_PARSING
$i
Definition: metadata.php:24
foreach($_POST as $key=> $value) $res