ILIAS  release_7 Revision v7.30-3-g800a261c036
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
24require_once("./Services/COPage/classes/class.ilPageContent.php");
25
37{
38 public $dom;
39
43 public function init()
44 {
45 $this->setType("td");
46 }
47
51 public 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 $new_tr->remove_attribute("PCID");
61 }
62 if ($next_tr = $parent_tr->next_sibling()) {
63 $new_tr = $next_tr->insert_before($new_tr, $next_tr);
64 } else {
65 $parent_table = $parent_tr->parent_node();
66 $new_tr = $parent_table->append_child($new_tr);
67 }
68
69 // remove td content of new row
70 $this->deleteRowContent($new_tr);
71 $this->fixHideAndSpans();
72 }
73
74
78 public function newRowBefore()
79 {
80 $this->initTablePCNode();
81 $td = $this->getNode();
82 $parent_tr = $td->parent_node();
83 $new_tr = $parent_tr->clone_node(true);
84 $new_tr = $parent_tr->insert_before($new_tr, $parent_tr);
85 if ($new_tr->has_attribute("PCID")) {
86 $new_tr->remove_attribute("PCID");
87 }
88
89 // remove td content of new row
90 $this->deleteRowContent($new_tr);
91 $this->fixHideAndSpans();
92 }
93
94
100 public function deleteRowContent(&$a_row_node)
101 {
102 // remove td content of row
103 $tds = $a_row_node->child_nodes();
104 for ($i = 0; $i < count($tds); $i++) {
105 if ($tds[$i]->has_attribute("PCID")) {
106 $tds[$i]->remove_attribute("PCID");
107 }
108 $td_childs = $tds[$i]->child_nodes();
109 for ($j = 0; $j < count($td_childs); $j++) {
110 $tds[$i]->remove_child($td_childs[$j]);
111 }
112 }
113 }
114
120 public function deleteTDContent(&$a_td_node)
121 {
122 $td_childs = $a_td_node->child_nodes();
123 for ($j = 0; $j < count($td_childs); $j++) {
124 $a_td_node->remove_child($td_childs[$j]);
125 }
126 }
127
128
132 public function deleteRow()
133 {
134 $this->initTablePCNode();
135 $td = $this->getNode();
136 $parent_tr = $td->parent_node();
137 $parent_tr->unlink($parent_tr);
138 $this->fixHideAndSpans();
139 }
140
141
145 public function newColAfter()
146 {
147 $this->initTablePCNode();
148 $td = $this->getNode();
149
150 // determine current column nr
151 $hier_id = $this->getHierId();
152 $parts = explode("_", $hier_id);
153 $col_nr = array_pop($parts);
154 $col_nr--;
155
156 $parent_tr = $td->parent_node();
157 $parent_table = $parent_tr->parent_node();
158
159 // iterate all table rows
160 $rows = $parent_table->child_nodes();
161 for ($i = 0; $i < count($rows); $i++) {
162 if ($rows[$i]->node_name() == "TableRow") {
163 // clone td at $col_nr
164 $tds = $rows[$i]->child_nodes();
165 $new_td = $tds[$col_nr]->clone_node(true);
166
167 if ($new_td->has_attribute("PCID")) {
168 $new_td->remove_attribute("PCID");
169 }
170
171 // insert clone after $col_nr
172 if ($next_td = $tds[$col_nr]->next_sibling()) {
173 $new_td = $next_td->insert_before($new_td, $next_td);
174 } else {
175 $new_td = $rows[$i]->append_child($new_td);
176 }
177 $this->deleteTDContent($new_td);
178 }
179 }
180 $this->fixHideAndSpans();
181 }
182
186 public function newColBefore()
187 {
188 $this->initTablePCNode();
189 $td = $this->getNode();
190
191 // determine current column nr
192 $hier_id = $this->getHierId();
193 $parts = explode("_", $hier_id);
194 $col_nr = array_pop($parts);
195 $col_nr--;
196 $parent_tr = $td->parent_node();
197 $parent_table = $parent_tr->parent_node();
198
199 // iterate all table rows
200 $rows = $parent_table->child_nodes();
201 for ($i = 0; $i < count($rows); $i++) {
202 if ($rows[$i]->node_name() == "TableRow") {
203 // clone td at $col_nr
204 $tds = $rows[$i]->child_nodes();
205 $new_td = $tds[$col_nr]->clone_node(true);
206
207 if ($new_td->has_attribute("PCID")) {
208 $new_td->remove_attribute("PCID");
209 }
210
211 // insert clone before $col_nr
212 $new_td = $tds[$col_nr]->insert_before($new_td, $tds[$col_nr]);
213 $this->deleteTDContent($new_td);
214 }
215 }
216 $this->fixHideAndSpans();
217 }
218
222 public function deleteCol()
223 {
224 $this->initTablePCNode();
225 $td = $this->getNode();
226
227 // determine current column nr
228 $hier_id = $this->getHierId();
229 $parts = explode("_", $hier_id);
230 $col_nr = array_pop($parts);
231 $col_nr--;
232
233 $parent_tr = $td->parent_node();
234 $parent_table = $parent_tr->parent_node();
235
236 // iterate all table rows
237 $rows = $parent_table->child_nodes();
238 for ($i = 0; $i < count($rows); $i++) {
239 if ($rows[$i]->node_name() == "TableRow") {
240 // unlink td at $col_nr
241 $tds = $rows[$i]->child_nodes();
242 $tds[$col_nr]->unlink($tds[$col_nr]);
243 }
244 }
245 $this->fixHideAndSpans();
246 }
247
251 public function moveRowDown()
252 {
253 $this->initTablePCNode();
254 $td = $this->getNode();
255 $tr = $td->parent_node();
256 $next = $tr->next_sibling();
257 $next_copy = $next->clone_node(true);
258 $next_copy = $tr->insert_before($next_copy, $tr);
259 $next->unlink($next);
260 $this->fixHideAndSpans();
261 }
262
266 public function moveRowUp()
267 {
268 $this->initTablePCNode();
269 $td = $this->getNode();
270 $tr = $td->parent_node();
271 $prev = $tr->previous_sibling();
272 $tr_copy = $tr->clone_node(true);
273 $tr_copy = $prev->insert_before($tr_copy, $prev);
274 $tr->unlink($tr);
275 $this->fixHideAndSpans();
276 }
277
281 public function moveColRight()
282 {
283 $this->initTablePCNode();
284 $td = $this->getNode();
285
286 // determine current column nr
287 $hier_id = $this->getHierId();
288 $parts = explode("_", $hier_id);
289 $col_nr = array_pop($parts);
290 $col_nr--;
291
292 $parent_tr = $td->parent_node();
293 $parent_table = $parent_tr->parent_node();
294
295 // iterate all table rows
296 $rows = $parent_table->child_nodes();
297 for ($i = 0; $i < count($rows); $i++) {
298 if ($rows[$i]->node_name() == "TableRow") {
299 $tds = $rows[$i]->child_nodes();
300 $td = $tds[$col_nr];
301 //$td = $this->getNode();
302 $next = $td->next_sibling();
303 $next_copy = $next->clone_node(true);
304 $next_copy = $td->insert_before($next_copy, $td);
305 $next->unlink($next);
306 }
307 }
308 $this->fixHideAndSpans();
309 }
310
314 public function moveColLeft()
315 {
316 $this->initTablePCNode();
317 $td = $this->getNode();
318
319 // determine current column nr
320 $hier_id = $this->getHierId();
321 $parts = explode("_", $hier_id);
322 $col_nr = array_pop($parts);
323 $col_nr--;
324
325 $parent_tr = $td->parent_node();
326 $parent_table = $parent_tr->parent_node();
327
328 // iterate all table rows
329 $rows = $parent_table->child_nodes();
330 for ($i = 0; $i < count($rows); $i++) {
331 if ($rows[$i]->node_name() == "TableRow") {
332 $tds = $rows[$i]->child_nodes();
333 $td = $tds[$col_nr];
334 $prev = $td->previous_sibling();
335 $td_copy = $td->clone_node(true);
336 $td_copy = $prev->insert_before($td_copy, $prev);
337 $td->unlink($td);
338 }
339 }
340 $this->fixHideAndSpans();
341 }
342
346 public function initTablePCNode()
347 {
348 $td = $this->getNode();
349 $tr = $td->parent_node();
350 $table = $tr->parent_node();
351 $this->table_pc_node = $table->parent_node();
352 }
353
357 public function fixHideAndSpans()
358 {
359 include_once("./Services/COPage/classes/class.ilPCTable.php");
360 $table_obj = new ilPCTable($this->getPage());
361 $table_obj->setNode($this->table_pc_node);
362 $table_obj->readHierId();
363 $table_obj->readPCId();
364 $table_obj->fixHideAndSpans();
365 }
366}
An exception for terminatinating execution or to throw for unit testing.
Class ilPCTableData.
deleteRowContent(&$a_row_node)
delete content of cells of a row (not the cells itself)
newRowBefore()
insert new row after cell
moveColLeft()
move column left
fixHideAndSpans()
Fix hide attribute and spans.
init()
Init page content component.
newRowAfter()
insert new row after cell
deleteTDContent(&$a_td_node)
delete content of a cell (not the cell itself)
deleteCol()
delete column of cell
deleteRow()
delete row of cell
moveRowDown()
move row down
moveColRight()
move column right
initTablePCNode()
Table PC Node.
newColBefore()
insert new column before cell
newColAfter()
insert new column after cell
moveRowUp()
move row up
Class ilPCTable.
Class ilPageContent.
getHierId()
Get hierarchical id.
& getNode()
Get xml node of page content.
setType($a_type)
Set Type.
$i
Definition: metadata.php:24
$rows
Definition: xhr_table.php:10