ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 var $dom;
42
46 function init()
47 {
48 $this->setType("dtab");
49 }
50
51 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 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
70 function getCellNode($i, $j)
71 {
72 $xpc = xpath_new_context($this->dom);
73 $path = "//PageContent[@HierId='".$this->getHierId()."']".
74 "/Table/TableRow[$i+1]/TableData[$j+1]/PageContent[1]/Paragraph[1]";
75//echo "<br>++".$path;
76//]--//PageContent[@HierId='3']/Table/TableRow[+1]/TableData[0 style=+1]/PageContent[1]/Paragraph[1]
77 $res =& xpath_eval($xpc, $path);
78
79 if (is_object($res->nodeset[0]))
80 {
81 return $res->nodeset[0];
82 }
83 else // no node -> delete all childs and create paragraph
84 {
85 $xpc2 = xpath_new_context($this->dom);
86 $path2 = "//PageContent[@HierId='".$this->getHierId()."']".
87 "/Table/TableRow[".($i+1)."]/TableData[".($j+1)."]";
88 //$path2 = "//PageContent";
89
90 $res2 =& xpath_eval($xpc2, $path2);
91
92 $td_node = $res2->nodeset[0];
93
94 if (is_object($td_node))
95 {
96 // delete children of paragraph node
97 $children = $td_node->child_nodes();
98 for($i=0; $i<count($children); $i++)
99 {
100 $td_node->remove_child($children[$i]);
101 }
102
103 // create page content and paragraph node here.
104 $pc_node = $this->createPageContentNode(false);
105 $pc_node = $td_node->append_child($pc_node);
106 $par_node = $this->dom->create_element("Paragraph");
107 $par_node = $pc_node->append_child($par_node);
108 $par_node->set_attribute("Characteristic", "TableContent");
109 $par_node->set_attribute("Language",
110 $this->getLanguage());
111
112 return $par_node;
113 }
114 }
115
116 return "";
117 }
118
122 function makeEmptyCell($td_node)
123 {
124 // delete children of paragraph node
125 $children = $td_node->child_nodes();
126 for($i=0; $i<count($children); $i++)
127 {
128 $td_node->remove_child($children[$i]);
129 }
130
131 // create page content and paragraph node here.
132 $pc_node = $this->createPageContentNode(false);
133 $pc_node = $td_node->append_child($pc_node);
134 $par_node = $this->dom->create_element("Paragraph");
135 $par_node = $pc_node->append_child($par_node);
136 $par_node->set_attribute("Characteristic", "TableContent");
137 $par_node->set_attribute("Language",
138 $this->getLanguage());
139 }
140
144 function getCellText($i, $j)
145 {
146 $cell_par = $this->getCellNode($i, $j);
147
148 if (is_object($cell_par))
149 {
150 $content = "";
151 $childs = $cell_par->child_nodes();
152 for($i=0; $i<count($childs); $i++)
153 {
154 $content.= $this->dom->dump_node($childs[$i]);
155 }
156 return $content;
157 }
158 else
159 {
160 return "";
161 }
162 }
163
167 function setData($a_data)
168 {
169 $ok = true;
170//var_dump($a_data);
171 if (is_array($a_data))
172 {
173 foreach ($a_data as $i => $row)
174 {
175 if (is_array($row))
176 {
177 foreach ($row as $j => $cell)
178 {
179//echo "<br><br>=".$cell."=";
180 $temp_dom = @domxml_open_mem('<?xml version="1.0" encoding="UTF-8"?><Paragraph>'.$cell.'</Paragraph>',
181 DOMXML_LOAD_PARSING, $error);
182
183 $par_node = $this->getCellNode($i, $j);
184//echo "<br>=".htmlentities($this->dom->dump_node($par_node))."=";
185//echo "<br>-$i-$j-$cell-";
186 // remove all childs
187 if(empty($error) && is_object($par_node))
188 {
189 // delete children of paragraph node
190 $children = $par_node->child_nodes();
191 for($k=0; $k < count($children); $k++)
192 {
193 $par_node->remove_child($children[$k]);
194 }
195
196 // copy new content children in paragraph node
197 $xpc = xpath_new_context($temp_dom);
198 $path = "//Paragraph";
199 $res =& xpath_eval($xpc, $path);
200
201 if (count($res->nodeset) == 1)
202 {
203 $new_par_node =& $res->nodeset[0];
204 $new_childs = $new_par_node->child_nodes();
205 for ($l = 0; $l < count($new_childs); $l++)
206 {
207 $cloned_child = $new_childs[$l]->clone_node(true);
208 $par_node->append_child($cloned_child);
209//echo "<br>=".htmlentities($this->dom->dump_node($cloned_child))."=";
210 }
211 }
212 }
213 else
214 {
215 if (!empty($error))
216 {
217 return $error;
218 }
219 }
220 }
221 }
222 }
223 }
224//exit;
225 return true;
226 }
227}
228
229?>
global $l
Definition: afr.php:30
const IL_INSERT_AFTER
Class ilPCDataTable.
makeEmptyCell($td_node)
Make cell empty.
getCellText($i, $j)
Get cell text of row $i and cell $j.
getCellNode($i, $j)
Get cell paragraph node of row $i and cell $j.
init()
Init page content component.
setData($a_data)
Set data of cells.
create(&$a_pg_obj, $a_hier_id, $a_pc_id="")
Class ilPCTable.
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.
const DOMXML_LOAD_PARSING
domxml_open_mem($str, $mode=DOMXML_LOAD_PARSING, &$error=NULL)
xpath_eval($xpath_context, $eval_str, $contextnode=null)
xpath_new_context($dom_document)
$path
Definition: index.php:22