ILIAS  Release_4_0_x_branch Revision 61816
 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  $this->initTablePCNode();
54  $td =& $this->getNode();
55  $parent_tr =& $td->parent_node();
56  $new_tr = $parent_tr->clone_node(true);
57 
58  // remove pc ids
59  if ($new_tr->has_attribute("PCID"))
60  {
61  $new_tr->remove_attribute("PCID");
62  }
63  if ($next_tr =& $parent_tr->next_sibling())
64  {
65  $new_tr =& $next_tr->insert_before($new_tr, $next_tr);
66  }
67  else
68  {
69  $parent_table =& $parent_tr->parent_node();
70  $new_tr =& $parent_table->append_child($new_tr);
71  }
72 
73  // remove td content of new row
74  $this->deleteRowContent($new_tr);
75  $this->fixHideAndSpans();
76  }
77 
78 
82  function newRowBefore()
83  {
84  $this->initTablePCNode();
85  $td =& $this->getNode();
86  $parent_tr =& $td->parent_node();
87  $new_tr = $parent_tr->clone_node(true);
88  $new_tr =& $parent_tr->insert_before($new_tr, $parent_tr);
89  if ($new_tr->has_attribute("PCID"))
90  {
91  $new_tr->remove_attribute("PCID");
92  }
93 
94  // remove td content of new row
95  $this->deleteRowContent($new_tr);
96  $this->fixHideAndSpans();
97  }
98 
99 
105  function deleteRowContent(&$a_row_node)
106  {
107  // remove td content of row
108  $tds =& $a_row_node->child_nodes();
109  for($i=0; $i<count($tds); $i++)
110  {
111  if ($tds[$i]->has_attribute("PCID"))
112  {
113  $tds[$i]->remove_attribute("PCID");
114  }
115  $td_childs =& $tds[$i]->child_nodes();
116  for($j=0; $j<count($td_childs); $j++)
117  {
118  $tds[$i]->remove_child($td_childs[$j]);
119  }
120  }
121 
122  }
123 
129  function deleteTDContent(&$a_td_node)
130  {
131  $td_childs =& $a_td_node->child_nodes();
132  for($j=0; $j<count($td_childs); $j++)
133  {
134  $a_td_node->remove_child($td_childs[$j]);
135  }
136  }
137 
138 
142  function deleteRow()
143  {
144  $this->initTablePCNode();
145  $td =& $this->getNode();
146  $parent_tr =& $td->parent_node();
147  $parent_tr->unlink($parent_tr);
148  $this->fixHideAndSpans();
149  }
150 
151 
155  function newColAfter()
156  {
157  $this->initTablePCNode();
158  $td =& $this->getNode();
159 
160  // determine current column nr
161  $hier_id = $this->getHierId();
162  $parts = explode("_", $hier_id);
163  $col_nr = array_pop($parts);
164  $col_nr--;
165 
166  $parent_tr =& $td->parent_node();
167  $parent_table =& $parent_tr->parent_node();
168 
169  // iterate all table rows
170  $rows =& $parent_table->child_nodes();
171  for($i=0; $i<count($rows); $i++)
172  {
173  if($rows[$i]->node_name() == "TableRow")
174  {
175  // clone td at $col_nr
176  $tds =& $rows[$i]->child_nodes();
177  $new_td =& $tds[$col_nr]->clone_node(true);
178 
179  if ($new_td->has_attribute("PCID"))
180  {
181  $new_td->remove_attribute("PCID");
182  }
183 
184  // insert clone after $col_nr
185  if ($next_td =& $tds[$col_nr]->next_sibling())
186  {
187  $new_td =& $next_td->insert_before($new_td, $next_td);
188  }
189  else
190  {
191  $new_td =& $rows[$i]->append_child($new_td);
192  }
193  $this->deleteTDContent($new_td);
194  }
195  }
196  $this->fixHideAndSpans();
197  }
198 
202  function newColBefore()
203  {
204  $this->initTablePCNode();
205  $td =& $this->getNode();
206 
207  // determine current column nr
208  $hier_id = $this->getHierId();
209  $parts = explode("_", $hier_id);
210  $col_nr = array_pop($parts);
211  $col_nr--;
212 
213  $parent_tr =& $td->parent_node();
214  $parent_table =& $parent_tr->parent_node();
215 
216  // iterate all table rows
217  $rows =& $parent_table->child_nodes();
218  for($i=0; $i<count($rows); $i++)
219  {
220  if($rows[$i]->node_name() == "TableRow")
221  {
222  // clone td at $col_nr
223  $tds =& $rows[$i]->child_nodes();
224  $new_td =& $tds[$col_nr]->clone_node(true);
225 
226  if ($new_td->has_attribute("PCID"))
227  {
228  $new_td->remove_attribute("PCID");
229  }
230 
231  // insert clone before $col_nr
232  $new_td =& $tds[$col_nr]->insert_before($new_td, $tds[$col_nr]);
233  $this->deleteTDContent($new_td);
234  }
235  }
236  $this->fixHideAndSpans();
237  }
238 
242  function deleteCol()
243  {
244  $this->initTablePCNode();
245  $td =& $this->getNode();
246 
247  // determine current column nr
248  $hier_id = $this->getHierId();
249  $parts = explode("_", $hier_id);
250  $col_nr = array_pop($parts);
251  $col_nr--;
252 
253  $parent_tr =& $td->parent_node();
254  $parent_table =& $parent_tr->parent_node();
255 
256  // iterate all table rows
257  $rows =& $parent_table->child_nodes();
258  for($i=0; $i<count($rows); $i++)
259  {
260  if($rows[$i]->node_name() == "TableRow")
261  {
262  // unlink td at $col_nr
263  $tds =& $rows[$i]->child_nodes();
264  $tds[$col_nr]->unlink($tds[$col_nr]);
265  }
266  }
267  $this->fixHideAndSpans();
268  }
269 
273  function moveRowDown()
274  {
275  $this->initTablePCNode();
276  $td =& $this->getNode();
277  $tr =& $td->parent_node();
278  $next =& $tr->next_sibling();
279  $next_copy = $next->clone_node(true);
280  $next_copy =& $tr->insert_before($next_copy, $tr);
281  $next->unlink($next);
282  $this->fixHideAndSpans();
283  }
284 
288  function moveRowUp()
289  {
290  $this->initTablePCNode();
291  $td =& $this->getNode();
292  $tr =& $td->parent_node();
293  $prev =& $tr->previous_sibling();
294  $tr_copy = $tr->clone_node(true);
295  $tr_copy =& $prev->insert_before($tr_copy, $prev);
296  $tr->unlink($tr);
297  $this->fixHideAndSpans();
298  }
299 
303  function moveColRight()
304  {
305  $this->initTablePCNode();
306  $td =& $this->getNode();
307 
308  // determine current column nr
309  $hier_id = $this->getHierId();
310  $parts = explode("_", $hier_id);
311  $col_nr = array_pop($parts);
312  $col_nr--;
313 
314  $parent_tr =& $td->parent_node();
315  $parent_table =& $parent_tr->parent_node();
316 
317  // iterate all table rows
318  $rows =& $parent_table->child_nodes();
319  for($i=0; $i<count($rows); $i++)
320  {
321  if($rows[$i]->node_name() == "TableRow")
322  {
323  $tds =& $rows[$i]->child_nodes();
324  $td =& $tds[$col_nr];
325  //$td =& $this->getNode();
326  $next =& $td->next_sibling();
327  $next_copy = $next->clone_node(true);
328  $next_copy =& $td->insert_before($next_copy, $td);
329  $next->unlink($next);
330  }
331  }
332  $this->fixHideAndSpans();
333  }
334 
338  function moveColLeft()
339  {
340  $this->initTablePCNode();
341  $td =& $this->getNode();
342 
343  // determine current column nr
344  $hier_id = $this->getHierId();
345  $parts = explode("_", $hier_id);
346  $col_nr = array_pop($parts);
347  $col_nr--;
348 
349  $parent_tr =& $td->parent_node();
350  $parent_table =& $parent_tr->parent_node();
351 
352  // iterate all table rows
353  $rows =& $parent_table->child_nodes();
354  for($i=0; $i<count($rows); $i++)
355  {
356  if($rows[$i]->node_name() == "TableRow")
357  {
358  $tds =& $rows[$i]->child_nodes();
359  $td =& $tds[$col_nr];
360  $prev =& $td->previous_sibling();
361  $td_copy = $td->clone_node(true);
362  $td_copy =& $prev->insert_before($td_copy, $prev);
363  $td->unlink($td);
364  }
365  }
366  $this->fixHideAndSpans();
367  }
368 
372  function initTablePCNode()
373  {
374  $td = $this->getNode();
375  $tr = $td->parent_node();
376  $table = $tr->parent_node();
377  $this->table_pc_node = $table->parent_node();
378  }
379 
383  function fixHideAndSpans()
384  {
385  include_once("./Services/COPage/classes/class.ilPCTable.php");
386  $table_obj = new ilPCTable($this->dom);
387  $table_obj->setNode($this->table_pc_node);
388  $table_obj->readHierId();
389  $table_obj->readPCId();
390  $table_obj->fixHideAndSpans();
391  }
392 }
393 ?>