ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
24 require_once("./Services/COPage/classes/class.ilPageContent.php");
25 require_once("./Services/COPage/classes/class.ilPCTable.php");
26 
38 class ilPCDataTable extends ilPCTable
39 {
40  var $dom;
41  var $tab_node;
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  $res =& xpath_eval($xpc, $path);
76 
77  if (is_object($res->nodeset[0]))
78  {
79  return $res->nodeset[0];
80  }
81  else // no node -> delete all childs and create paragraph
82  {
83  $xpc2 = xpath_new_context($this->dom);
84  $path2 = "//PageContent[@HierId='".$this->getHierId()."']".
85  "/Table/TableRow[".($i+1)."]/TableData[".($j+1)."]";
86  //$path2 = "//PageContent";
87 
88  $res2 =& xpath_eval($xpc2, $path2);
89 
90  $td_node = $res2->nodeset[0];
91 
92  if (is_object($td_node))
93  {
94  // delete children of paragraph node
95  $children = $td_node->child_nodes();
96  for($i=0; $i<count($children); $i++)
97  {
98  $td_node->remove_child($children[$i]);
99  }
100 
101  // create page content and paragraph node here.
102  $pc_node = $this->createPageContentNode(false);
103  $pc_node = $td_node->append_child($pc_node);
104  $par_node = $this->dom->create_element("Paragraph");
105  $par_node = $pc_node->append_child($par_node);
106  $par_node->set_attribute("Characteristic", "TableContent");
107  $par_node->set_attribute("Language",
108  $this->getLanguage());
109 
110  return $par_node;
111  }
112  }
113 
114  return "";
115  }
116 
120  function getCellText($i, $j)
121  {
122  $cell_par = $this->getCellNode($i, $j);
123 
124  if (is_object($cell_par))
125  {
126  $content = "";
127  $childs = $cell_par->child_nodes();
128  for($i=0; $i<count($childs); $i++)
129  {
130  $content.= $this->dom->dump_node($childs[$i]);
131  }
132  return $content;
133  }
134  else
135  {
136  return "";
137  }
138  }
139 
143  function setData($a_data)
144  {
145  $ok = true;
146 //var_dump($a_data);
147  if (is_array($a_data))
148  {
149  foreach ($a_data as $i => $row)
150  {
151  if (is_array($row))
152  {
153  foreach ($row as $j => $cell)
154  {
155  $temp_dom = @domxml_open_mem('<?xml version="1.0" encoding="UTF-8"?><Paragraph>'.$cell.'</Paragraph>',
156  DOMXML_LOAD_PARSING, $error);
157 
158  $par_node = $this->getCellNode($i, $j);
159 //echo "<br>=".htmlentities($this->dom->dump_node($par_node))."=";
160 //echo "<br>-$i-$j-$cell-";
161  // remove all childs
162  if(empty($error) && is_object($par_node))
163  {
164  // delete children of paragraph node
165  $children = $par_node->child_nodes();
166  for($k=0; $k < count($children); $k++)
167  {
168  $par_node->remove_child($children[$k]);
169  }
170 
171  // copy new content children in paragraph node
172  $xpc = xpath_new_context($temp_dom);
173  $path = "//Paragraph";
174  $res =& xpath_eval($xpc, $path);
175 
176  if (count($res->nodeset) == 1)
177  {
178  $new_par_node =& $res->nodeset[0];
179  $new_childs = $new_par_node->child_nodes();
180  for ($l = 0; $l < count($new_childs); $l++)
181  {
182  $cloned_child = $new_childs[$l]->clone_node(true);
183  $par_node->append_child($cloned_child);
184 //echo "<br>=".htmlentities($this->dom->dump_node($cloned_child))."=";
185  }
186  }
187  }
188  else
189  {
190  if (!empty($error))
191  {
192  return $error;
193  }
194  }
195  }
196  }
197  }
198  }
199 
200  return true;
201  }
202 }
203 
204 ?>