ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPCTableData.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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 
37 {
38  var $dom;
39 
43  function init()
44  {
45  $this->setType("td");
46  }
47 
51  function newRowAfter()
52  {
53  $td =& $this->getNode();
54  $parent_tr =& $td->parent_node();
55  $new_tr = $parent_tr->clone_node(true);
56 
57  // remove pc ids
58  if ($new_tr->has_attribute("PCID"))
59  {
60  $new_tr->remove_attribute("PCID");
61  }
62  if ($next_tr =& $parent_tr->next_sibling())
63  {
64  $new_tr =& $next_tr->insert_before($new_tr, $next_tr);
65  }
66  else
67  {
68  $parent_table =& $parent_tr->parent_node();
69  $new_tr =& $parent_table->append_child($new_tr);
70  }
71 
72  // remove td content of new row
73  $this->deleteRowContent($new_tr);
74  }
75 
76 
80  function newRowBefore()
81  {
82  $td =& $this->getNode();
83  $parent_tr =& $td->parent_node();
84  $new_tr = $parent_tr->clone_node(true);
85  $new_tr =& $parent_tr->insert_before($new_tr, $parent_tr);
86  if ($new_tr->has_attribute("PCID"))
87  {
88  $new_tr->remove_attribute("PCID");
89  }
90 
91  // remove td content of new row
92  $this->deleteRowContent($new_tr);
93  }
94 
95 
101  function deleteRowContent(&$a_row_node)
102  {
103  // remove td content of row
104  $tds =& $a_row_node->child_nodes();
105  for($i=0; $i<count($tds); $i++)
106  {
107  if ($tds[$i]->has_attribute("PCID"))
108  {
109  $tds[$i]->remove_attribute("PCID");
110  }
111  $td_childs =& $tds[$i]->child_nodes();
112  for($j=0; $j<count($td_childs); $j++)
113  {
114  $tds[$i]->remove_child($td_childs[$j]);
115  }
116  }
117  }
118 
124  function deleteTDContent(&$a_td_node)
125  {
126  $td_childs =& $a_td_node->child_nodes();
127  for($j=0; $j<count($td_childs); $j++)
128  {
129  $a_td_node->remove_child($td_childs[$j]);
130  }
131  }
132 
133 
137  function deleteRow()
138  {
139  $td =& $this->getNode();
140  $parent_tr =& $td->parent_node();
141  $parent_tr->unlink($parent_tr);
142  }
143 
144 
148  function newColAfter()
149  {
150  $td =& $this->getNode();
151 
152  // determine current column nr
153  $hier_id = $this->getHierId();
154  $parts = explode("_", $hier_id);
155  $col_nr = array_pop($parts);
156  $col_nr--;
157 
158  $parent_tr =& $td->parent_node();
159  $parent_table =& $parent_tr->parent_node();
160 
161  // iterate all table rows
162  $rows =& $parent_table->child_nodes();
163  for($i=0; $i<count($rows); $i++)
164  {
165  if($rows[$i]->node_name() == "TableRow")
166  {
167  // clone td at $col_nr
168  $tds =& $rows[$i]->child_nodes();
169  $new_td =& $tds[$col_nr]->clone_node(true);
170 
171  if ($new_td->has_attribute("PCID"))
172  {
173  $new_td->remove_attribute("PCID");
174  }
175 
176  // insert clone after $col_nr
177  if ($next_td =& $tds[$col_nr]->next_sibling())
178  {
179  $new_td =& $next_td->insert_before($new_td, $next_td);
180  }
181  else
182  {
183  $new_td =& $rows[$i]->append_child($new_td);
184  }
185  $this->deleteTDContent($new_td);
186  }
187  }
188  }
189 
193  function newColBefore()
194  {
195  $td =& $this->getNode();
196 
197  // determine current column nr
198  $hier_id = $this->getHierId();
199  $parts = explode("_", $hier_id);
200  $col_nr = array_pop($parts);
201  $col_nr--;
202 
203  $parent_tr =& $td->parent_node();
204  $parent_table =& $parent_tr->parent_node();
205 
206  // iterate all table rows
207  $rows =& $parent_table->child_nodes();
208  for($i=0; $i<count($rows); $i++)
209  {
210  if($rows[$i]->node_name() == "TableRow")
211  {
212  // clone td at $col_nr
213  $tds =& $rows[$i]->child_nodes();
214  $new_td =& $tds[$col_nr]->clone_node(true);
215 
216  if ($new_td->has_attribute("PCID"))
217  {
218  $new_td->remove_attribute("PCID");
219  }
220 
221  // insert clone before $col_nr
222  $new_td =& $tds[$col_nr]->insert_before($new_td, $tds[$col_nr]);
223  $this->deleteTDContent($new_td);
224  }
225  }
226  }
227 
231  function deleteCol()
232  {
233  $td =& $this->getNode();
234 
235  // determine current column nr
236  $hier_id = $this->getHierId();
237  $parts = explode("_", $hier_id);
238  $col_nr = array_pop($parts);
239  $col_nr--;
240 
241  $parent_tr =& $td->parent_node();
242  $parent_table =& $parent_tr->parent_node();
243 
244  // iterate all table rows
245  $rows =& $parent_table->child_nodes();
246  for($i=0; $i<count($rows); $i++)
247  {
248  if($rows[$i]->node_name() == "TableRow")
249  {
250  // unlink td at $col_nr
251  $tds =& $rows[$i]->child_nodes();
252  $tds[$col_nr]->unlink($tds[$col_nr]);
253  }
254  }
255  }
256 
260  function moveRowDown()
261  {
262  $td =& $this->getNode();
263  $tr =& $td->parent_node();
264  $next =& $tr->next_sibling();
265  $next_copy = $next->clone_node(true);
266  $next_copy =& $tr->insert_before($next_copy, $tr);
267  $next->unlink($next);
268  }
269 
273  function moveRowUp()
274  {
275  $td =& $this->getNode();
276  $tr =& $td->parent_node();
277  $prev =& $tr->previous_sibling();
278  $tr_copy = $tr->clone_node(true);
279  $tr_copy =& $prev->insert_before($tr_copy, $prev);
280  $tr->unlink($tr);
281  }
282 
286  function moveColRight()
287  {
288  $td =& $this->getNode();
289 
290  // determine current column nr
291  $hier_id = $this->getHierId();
292  $parts = explode("_", $hier_id);
293  $col_nr = array_pop($parts);
294  $col_nr--;
295 
296  $parent_tr =& $td->parent_node();
297  $parent_table =& $parent_tr->parent_node();
298 
299  // iterate all table rows
300  $rows =& $parent_table->child_nodes();
301  for($i=0; $i<count($rows); $i++)
302  {
303  if($rows[$i]->node_name() == "TableRow")
304  {
305  $tds =& $rows[$i]->child_nodes();
306  $td =& $tds[$col_nr];
307  //$td =& $this->getNode();
308  $next =& $td->next_sibling();
309  $next_copy = $next->clone_node(true);
310  $next_copy =& $td->insert_before($next_copy, $td);
311  $next->unlink($next);
312  }
313  }
314  }
315 
319  function moveColLeft()
320  {
321  $td =& $this->getNode();
322 
323  // determine current column nr
324  $hier_id = $this->getHierId();
325  $parts = explode("_", $hier_id);
326  $col_nr = array_pop($parts);
327  $col_nr--;
328 
329  $parent_tr =& $td->parent_node();
330  $parent_table =& $parent_tr->parent_node();
331 
332  // iterate all table rows
333  $rows =& $parent_table->child_nodes();
334  for($i=0; $i<count($rows); $i++)
335  {
336  if($rows[$i]->node_name() == "TableRow")
337  {
338  $tds =& $rows[$i]->child_nodes();
339  $td =& $tds[$col_nr];
340  $prev =& $td->previous_sibling();
341  $td_copy = $td->clone_node(true);
342  $td_copy =& $prev->insert_before($td_copy, $prev);
343  $td->unlink($td);
344  }
345  }
346  }
347 
348 }
349 ?>