ILIAS  release_8 Revision v8.24
class.ilPCTableData.php
Go to the documentation of this file.
1<?php
2
24{
26
27 public function init(): void
28 {
29 $this->setType("td");
30 }
31
32 public function newRowAfter(): void
33 {
34 $this->initTablePCNode();
35 $td = $this->getNode();
36 $parent_tr = $td->parent_node();
37 $new_tr = $parent_tr->clone_node(true);
38
39 // remove pc ids
40 if ($new_tr->has_attribute("PCID")) {
41 $new_tr->remove_attribute("PCID");
42 }
43 if ($next_tr = $parent_tr->next_sibling()) {
44 $new_tr = $next_tr->insert_before($new_tr, $next_tr);
45 } else {
46 $parent_table = $parent_tr->parent_node();
47 $new_tr = $parent_table->append_child($new_tr);
48 }
49
50 // remove td content of new row
51 $this->deleteRowContent($new_tr);
52 $this->fixHideAndSpans();
53 }
54
55
56 public function newRowBefore(): void
57 {
58 $this->initTablePCNode();
59 $td = $this->getNode();
60 $parent_tr = $td->parent_node();
61 $new_tr = $parent_tr->clone_node(true);
62 $new_tr = $parent_tr->insert_before($new_tr, $parent_tr);
63 if ($new_tr->has_attribute("PCID")) {
64 $new_tr->remove_attribute("PCID");
65 }
66
67 // remove td content of new row
68 $this->deleteRowContent($new_tr);
69 $this->fixHideAndSpans();
70 }
71
72
76 public function deleteRowContent(
77 php4DOMElement $a_row_node
78 ): void {
79 // remove td content of row
80 $tds = $a_row_node->child_nodes();
81 for ($i = 0; $i < count($tds); $i++) {
82 if ($tds[$i]->has_attribute("PCID")) {
83 $tds[$i]->remove_attribute("PCID");
84 }
85 $td_childs = $tds[$i]->child_nodes();
86 for ($j = 0; $j < count($td_childs); $j++) {
87 $tds[$i]->remove_child($td_childs[$j]);
88 }
89 }
90 }
91
95 public function deleteTDContent(
96 php4DOMElement $a_td_node
97 ): void {
98 $td_childs = $a_td_node->child_nodes();
99 for ($j = 0; $j < count($td_childs); $j++) {
100 $a_td_node->remove_child($td_childs[$j]);
101 }
102 }
103
104 public function deleteRow(): void
105 {
106 $this->initTablePCNode();
107 $td = $this->getNode();
108 $parent_tr = $td->parent_node();
109 $parent_tr->unlink($parent_tr);
110 $this->fixHideAndSpans();
111 }
112
113 public function newColAfter(): void
114 {
115 $this->initTablePCNode();
116 $td = $this->getNode();
117
118 // determine current column nr
119 $hier_id = $this->getHierId();
120 $parts = explode("_", $hier_id);
121 $col_nr = array_pop($parts);
122 $col_nr--;
123
124 $parent_tr = $td->parent_node();
125 $parent_table = $parent_tr->parent_node();
126
127 // iterate all table rows
128 $rows = $parent_table->child_nodes();
129 for ($i = 0; $i < count($rows); $i++) {
130 if ($rows[$i]->node_name() == "TableRow") {
131 // clone td at $col_nr
132 $tds = $rows[$i]->child_nodes();
133 $new_td = $tds[$col_nr]->clone_node(true);
134
135 if ($new_td->has_attribute("PCID")) {
136 $new_td->remove_attribute("PCID");
137 }
138
139 // insert clone after $col_nr
140 if ($next_td = $tds[$col_nr]->next_sibling()) {
141 $new_td = $next_td->insert_before($new_td, $next_td);
142 } else {
143 $new_td = $rows[$i]->append_child($new_td);
144 }
145 $this->deleteTDContent($new_td);
146 }
147 }
148 $this->fixHideAndSpans();
149 }
150
151 public function newColBefore(): void
152 {
153 $this->initTablePCNode();
154 $td = $this->getNode();
155
156 // determine current column nr
157 $hier_id = $this->getHierId();
158 $parts = explode("_", $hier_id);
159 $col_nr = array_pop($parts);
160 $col_nr--;
161 $parent_tr = $td->parent_node();
162 $parent_table = $parent_tr->parent_node();
163
164 // iterate all table rows
165 $rows = $parent_table->child_nodes();
166 for ($i = 0; $i < count($rows); $i++) {
167 if ($rows[$i]->node_name() == "TableRow") {
168 // clone td at $col_nr
169 $tds = $rows[$i]->child_nodes();
170 $new_td = $tds[$col_nr]->clone_node(true);
171
172 if ($new_td->has_attribute("PCID")) {
173 $new_td->remove_attribute("PCID");
174 }
175
176 // insert clone before $col_nr
177 $new_td = $tds[$col_nr]->insert_before($new_td, $tds[$col_nr]);
178 $this->deleteTDContent($new_td);
179 }
180 }
181 $this->fixHideAndSpans();
182 }
183
184 public function deleteCol(): void
185 {
186 $this->initTablePCNode();
187 $td = $this->getNode();
188
189 // determine current column nr
190 $hier_id = $this->getHierId();
191 $parts = explode("_", $hier_id);
192 $col_nr = array_pop($parts);
193 $col_nr--;
194
195 $parent_tr = $td->parent_node();
196 $parent_table = $parent_tr->parent_node();
197
198 // iterate all table rows
199 $rows = $parent_table->child_nodes();
200 for ($i = 0; $i < count($rows); $i++) {
201 if ($rows[$i]->node_name() == "TableRow") {
202 // unlink td at $col_nr
203 $tds = $rows[$i]->child_nodes();
204 $tds[$col_nr]->unlink($tds[$col_nr]);
205 }
206 }
207 $this->fixHideAndSpans();
208 }
209
210 public function moveRowDown(): void
211 {
212 $this->initTablePCNode();
213 $td = $this->getNode();
214 $tr = $td->parent_node();
215 $next = $tr->next_sibling();
216 $next_copy = $next->clone_node(true);
217 $next_copy = $tr->insert_before($next_copy, $tr);
218 $next->unlink($next);
219 $this->fixHideAndSpans();
220 }
221
222 public function moveRowUp(): void
223 {
224 $this->initTablePCNode();
225 $td = $this->getNode();
226 $tr = $td->parent_node();
227 $prev = $tr->previous_sibling();
228 $tr_copy = $tr->clone_node(true);
229 $tr_copy = $prev->insert_before($tr_copy, $prev);
230 $tr->unlink($tr);
231 $this->fixHideAndSpans();
232 }
233
234 public function moveColRight(): void
235 {
236 $this->initTablePCNode();
237 $td = $this->getNode();
238
239 // determine current column nr
240 $hier_id = $this->getHierId();
241 $parts = explode("_", $hier_id);
242 $col_nr = array_pop($parts);
243 $col_nr--;
244
245 $parent_tr = $td->parent_node();
246 $parent_table = $parent_tr->parent_node();
247
248 // iterate all table rows
249 $rows = $parent_table->child_nodes();
250 for ($i = 0; $i < count($rows); $i++) {
251 if ($rows[$i]->node_name() == "TableRow") {
252 $tds = $rows[$i]->child_nodes();
253 $td = $tds[$col_nr];
254 //$td = $this->getNode();
255 $next = $td->next_sibling();
256 $next_copy = $next->clone_node(true);
257 $next_copy = $td->insert_before($next_copy, $td);
258 $next->unlink($next);
259 }
260 }
261 $this->fixHideAndSpans();
262 }
263
264 public function moveColLeft(): void
265 {
266 $this->initTablePCNode();
267 $td = $this->getNode();
268
269 // determine current column nr
270 $hier_id = $this->getHierId();
271 $parts = explode("_", $hier_id);
272 $col_nr = array_pop($parts);
273 $col_nr--;
274
275 $parent_tr = $td->parent_node();
276 $parent_table = $parent_tr->parent_node();
277
278 // iterate all table rows
279 $rows = $parent_table->child_nodes();
280 for ($i = 0; $i < count($rows); $i++) {
281 if ($rows[$i]->node_name() == "TableRow") {
282 $tds = $rows[$i]->child_nodes();
283 $td = $tds[$col_nr];
284 $prev = $td->previous_sibling();
285 $td_copy = $td->clone_node(true);
286 $td_copy = $prev->insert_before($td_copy, $prev);
287 $td->unlink($td);
288 }
289 }
290 $this->fixHideAndSpans();
291 }
292
293 public function initTablePCNode(): void
294 {
295 $td = $this->getNode();
296 $tr = $td->parent_node();
297 $table = $tr->parent_node();
298 $this->table_pc_node = $table->parent_node();
299 }
300
301 public function fixHideAndSpans(): void
302 {
303 $table_obj = new ilPCTable($this->getPage());
304 $table_obj->setNode($this->table_pc_node);
305 $table_obj->readHierId();
306 $table_obj->readPCId();
307 $table_obj->fixHideAndSpans();
308 }
309}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
init()
Init object.
deleteTDContent(php4DOMElement $a_td_node)
delete content of a cell (not the cell itself)
php4DOMElement $table_pc_node
deleteRowContent(php4DOMElement $a_row_node)
delete content of cells of a row (not the cells itself)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setType(string $a_type)
Set Type.
remove_child($oldchild)
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:64
$i
Definition: metadata.php:41
$rows
Definition: xhr_table.php:10