ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
197 $parent_tr = $td->parent_node();
198 $parent_table = $parent_tr->parent_node();
199
200 // iterate all table rows
201 $rows = $parent_table->child_nodes();
202 for ($i = 0; $i < count($rows); $i++) {
203 if ($rows[$i]->node_name() == "TableRow") {
204 // clone td at $col_nr
205 $tds = $rows[$i]->child_nodes();
206 $new_td = $tds[$col_nr]->clone_node(true);
207
208 if ($new_td->has_attribute("PCID")) {
209 $new_td->remove_attribute("PCID");
210 }
211
212 // insert clone before $col_nr
213 $new_td = $tds[$col_nr]->insert_before($new_td, $tds[$col_nr]);
214 $this->deleteTDContent($new_td);
215 }
216 }
217 $this->fixHideAndSpans();
218 }
219
223 public function deleteCol()
224 {
225 $this->initTablePCNode();
226 $td = $this->getNode();
227
228 // determine current column nr
229 $hier_id = $this->getHierId();
230 $parts = explode("_", $hier_id);
231 $col_nr = array_pop($parts);
232 $col_nr--;
233
234 $parent_tr = $td->parent_node();
235 $parent_table = $parent_tr->parent_node();
236
237 // iterate all table rows
238 $rows = $parent_table->child_nodes();
239 for ($i = 0; $i < count($rows); $i++) {
240 if ($rows[$i]->node_name() == "TableRow") {
241 // unlink td at $col_nr
242 $tds = $rows[$i]->child_nodes();
243 $tds[$col_nr]->unlink($tds[$col_nr]);
244 }
245 }
246 $this->fixHideAndSpans();
247 }
248
252 public function moveRowDown()
253 {
254 $this->initTablePCNode();
255 $td = $this->getNode();
256 $tr = $td->parent_node();
257 $next = $tr->next_sibling();
258 $next_copy = $next->clone_node(true);
259 $next_copy = $tr->insert_before($next_copy, $tr);
260 $next->unlink($next);
261 $this->fixHideAndSpans();
262 }
263
267 public function moveRowUp()
268 {
269 $this->initTablePCNode();
270 $td = $this->getNode();
271 $tr = $td->parent_node();
272 $prev = $tr->previous_sibling();
273 $tr_copy = $tr->clone_node(true);
274 $tr_copy = $prev->insert_before($tr_copy, $prev);
275 $tr->unlink($tr);
276 $this->fixHideAndSpans();
277 }
278
282 public function moveColRight()
283 {
284 $this->initTablePCNode();
285 $td = $this->getNode();
286
287 // determine current column nr
288 $hier_id = $this->getHierId();
289 $parts = explode("_", $hier_id);
290 $col_nr = array_pop($parts);
291 $col_nr--;
292
293 $parent_tr = $td->parent_node();
294 $parent_table = $parent_tr->parent_node();
295
296 // iterate all table rows
297 $rows = $parent_table->child_nodes();
298 for ($i = 0; $i < count($rows); $i++) {
299 if ($rows[$i]->node_name() == "TableRow") {
300 $tds = $rows[$i]->child_nodes();
301 $td = $tds[$col_nr];
302 //$td = $this->getNode();
303 $next = $td->next_sibling();
304 $next_copy = $next->clone_node(true);
305 $next_copy = $td->insert_before($next_copy, $td);
306 $next->unlink($next);
307 }
308 }
309 $this->fixHideAndSpans();
310 }
311
315 public function moveColLeft()
316 {
317 $this->initTablePCNode();
318 $td = $this->getNode();
319
320 // determine current column nr
321 $hier_id = $this->getHierId();
322 $parts = explode("_", $hier_id);
323 $col_nr = array_pop($parts);
324 $col_nr--;
325
326 $parent_tr = $td->parent_node();
327 $parent_table = $parent_tr->parent_node();
328
329 // iterate all table rows
330 $rows = $parent_table->child_nodes();
331 for ($i = 0; $i < count($rows); $i++) {
332 if ($rows[$i]->node_name() == "TableRow") {
333 $tds = $rows[$i]->child_nodes();
334 $td = $tds[$col_nr];
335 $prev = $td->previous_sibling();
336 $td_copy = $td->clone_node(true);
337 $td_copy = $prev->insert_before($td_copy, $prev);
338 $td->unlink($td);
339 }
340 }
341 $this->fixHideAndSpans();
342 }
343
347 public function initTablePCNode()
348 {
349 $td = $this->getNode();
350 $tr = $td->parent_node();
351 $table = $tr->parent_node();
352 $this->table_pc_node = $table->parent_node();
353 }
354
358 public function fixHideAndSpans()
359 {
360 include_once("./Services/COPage/classes/class.ilPCTable.php");
361 $table_obj = new ilPCTable($this->getPage());
362 $table_obj->setNode($this->table_pc_node);
363 $table_obj->readHierId();
364 $table_obj->readPCId();
365 $table_obj->fixHideAndSpans();
366 }
367}
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: disco.tpl.php:19
if(empty($password)) $table
Definition: pwgen.php:24
$rows
Definition: xhr_table.php:10