ILIAS  release_8 Revision v8.24
class.ilPCTable.php
Go to the documentation of this file.
1<?php
2
25{
27
28 public function init(): void
29 {
30 $this->setType("tab");
31 }
32
33 public function setNode(php4DOMElement $a_node): void
34 {
35 parent::setNode($a_node); // this is the PageContent node
36 $this->tab_node = $a_node->first_child(); // this is the Table node
37 }
38
39 public function create(
40 ilPageObject $a_pg_obj,
41 string $a_hier_id,
42 string $a_pc_id = ""
43 ): void {
44 $this->node = $this->createPageContentNode();
45 $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
46 $this->tab_node = $this->dom->create_element("Table");
47 $this->tab_node = $this->node->append_child($this->tab_node);
48 $this->tab_node->set_attribute("Language", "");
49 }
50
51 public function addRow(): php4DOMElement
52 {
53 $new_tr = $this->dom->create_element("TableRow");
54 $new_tr = $this->tab_node->append_child($new_tr);
55 return $new_tr;
56 }
57
58 public function addCell(
59 php4DOMElement $aRow,
60 string $a_data = "",
61 string $a_lang = ""
63 $new_td = $this->dom->create_element("TableData");
64 $new_td = $aRow->append_child($new_td);
65
66 // insert data if given
67 if ($a_data != "") {
68 $new_pg = $this->createPageContentNode(false);
69 $new_par = $this->dom->create_element("Paragraph");
70 $new_par = $new_pg->append_child($new_par);
71 $new_par->set_attribute("Language", $a_lang);
72 $new_par->set_attribute("Characteristic", "TableContent");
73 $new_par->set_content($a_data);
74 $new_td->append_child($new_pg);
75 }
76
77 return $new_td;
78 }
79
83 public function getCellText(int $i, int $j): string
84 {
85 $cell_par = $this->getCellNode($i, $j, false);
86
87 if (is_object($cell_par)) {
88 $content = "";
89 $childs = $cell_par->child_nodes();
90 for ($i = 0; $i < count($childs); $i++) {
91 $content .= $this->dom->dump_node($childs[$i]);
92 }
93 return $content;
94 } else {
95 return "";
96 }
97 }
98
102 public function getCellNode(int $i, int $j, bool $create_if_not_exists = false): ?php4DOMElement
103 {
104 $xpc = xpath_new_context($this->dom);
105 $path = "//PageContent[@HierId='" . $this->getHierId() . "']" .
106 "/Table/TableRow[$i+1]/TableData[$j+1]/PageContent[1]/Paragraph[1]";
107 //echo "<br>++".$path;
108 //]--//PageContent[@HierId='3']/Table/TableRow[+1]/TableData[0 style=+1]/PageContent[1]/Paragraph[1]
109 $res = xpath_eval($xpc, $path);
110
111 if (isset($res->nodeset[0])) {
112 return $res->nodeset[0];
113 } else { // no node -> delete all childs and create paragraph
114 if (!$create_if_not_exists) {
115 return null;
116 }
117 $xpc2 = xpath_new_context($this->dom);
118 $path2 = "//PageContent[@HierId='" . $this->getHierId() . "']" .
119 "/Table/TableRow[" . ($i + 1) . "]/TableData[" . ($j + 1) . "]";
120 //$path2 = "//PageContent";
121
122 $res2 = xpath_eval($xpc2, $path2);
123
124 $td_node = $res2->nodeset[0];
125
126 if (is_object($td_node)) {
127 // delete children of paragraph node
128 $children = $td_node->child_nodes();
129 for ($i = 0; $i < count($children); $i++) {
130 $td_node->remove_child($children[$i]);
131 }
132
133 // create page content and paragraph node here.
134 $pc_node = $this->createPageContentNode(false);
135 $pc_node = $td_node->append_child($pc_node);
136 $par_node = $this->dom->create_element("Paragraph");
137 $par_node = $pc_node->append_child($par_node);
138 $par_node->set_attribute("Characteristic", "TableContent");
139 $par_node->set_attribute(
140 "Language",
141 $this->getLanguage()
142 );
143
144 return $par_node;
145 }
146 }
147
148 return null;
149 }
150
154 public function addRows(int $a_nr_rows, int $a_nr_cols): void
155 {
156 for ($i = 1; $i <= $a_nr_rows; $i++) {
157 $aRow = $this->addRow();
158 for ($j = 1; $j <= $a_nr_cols; $j++) {
159 $this->addCell($aRow);
160 }
161 }
162 }
163
167 public function importSpreadsheet(
168 string $a_lang,
169 string $a_data
170 ): void {
171 $max_cols = 0;
172
173 str_replace($a_data, "\r", "\n");
174 str_replace($a_data, "\n\n", "\n");
175 $target_rows = array();
176 $rows = explode("\n", $a_data);
177
178 // get maximum of cols in a row and
179 // put data in target_row arrays
180 foreach ($rows as $row) {
181 $cells = explode("\t", $row);
182 $max_cols = ($max_cols > count($cells))
183 ? $max_cols
184 : count($cells);
185 $target_rows[] = $cells;
186 }
187
188 // iterate target row arrays and insert data
189 foreach ($target_rows as $row) {
190 $aRow = $this->addRow();
191 for ($j = 0; $j < $max_cols; $j++) {
192 // mask html
193 $data = str_replace("&", "&amp;", ($row[$j] ?? ""));
194 $data = str_replace("<", "&lt;", $data);
195 $data = str_replace(">", "&gt;", $data);
196
197 $this->addCell($aRow, $data, $a_lang);
198 }
199 }
200 }
201
202 public function getLanguage(): string
203 {
204 return $this->getTableAttribute("Language");
205 }
206
207 public function setLanguage(string $a_lang): void
208 {
209 if ($a_lang != "") {
210 $this->setTableAttribute("Language", $a_lang);
211 }
212 }
213
214 public function getWidth(): string
215 {
216 return $this->getTableAttribute("Width");
217 }
218
219 public function setWidth(string $a_width): void
220 {
221 $this->setTableAttribute("Width", $a_width);
222 }
223
224 public function getBorder(): string
225 {
226 return $this->getTableAttribute("Border");
227 }
228
229 public function setBorder(string $a_border): void
230 {
231 $this->setTableAttribute("Border", $a_border);
232 }
233
234 public function getCellSpacing(): string
235 {
236 return $this->getTableAttribute("CellSpacing");
237 }
238
239 public function setCellSpacing(string $a_spacing): void
240 {
241 $this->setTableAttribute("CellSpacing", $a_spacing);
242 }
243
244 public function getCellPadding(): string
245 {
246 return $this->getTableAttribute("CellPadding");
247 }
248
249 public function setCellPadding(string $a_padding): void
250 {
251 $this->setTableAttribute("CellPadding", $a_padding);
252 }
253
254 public function setHorizontalAlign(string $a_halign): void
255 {
256 $this->tab_node->set_attribute("HorizontalAlign", $a_halign);
257 }
258
259 public function getHorizontalAlign(): string
260 {
261 return $this->getTableAttribute("HorizontalAlign");
262 }
263
267 public function setTDWidth(
268 string $a_hier_id,
269 string $a_width,
270 string $a_pc_id = ""
271 ): void {
272 $xpc = xpath_new_context($this->dom);
273
274 if ($a_pc_id == "") {
275 $path = "//TableData[@HierId = '" . $a_hier_id . "']";
276 } else {
277 $path = "//TableData[@PCID = '" . $a_pc_id . "']";
278 }
279 $res = xpath_eval($xpc, $path);
280
281 if (count($res->nodeset) == 1) {
282 if ($a_width != "") {
283 $res->nodeset[0]->set_attribute("Width", $a_width);
284 } else {
285 if ($res->nodeset[0]->has_attribute("Width")) {
286 $res->nodeset[0]->remove_attribute("Width");
287 }
288 }
289 }
290 }
291
292 public function setTDSpans(
293 array $a_colspans,
294 array $a_rowspans
295 ): void {
296 $y = 0;
297 $rows = $this->tab_node->child_nodes();
298 foreach ($rows as $row) {
299 if ($row->node_name() == "TableRow") {
300 $x = 0;
301 $cells = $row->child_nodes();
302 foreach ($cells as $cell) {
303 if ($cell->node_name() == "TableData") {
304 $ckey = $cell->get_attribute("HierId") . ":" . $cell->get_attribute("PCID");
305 if ((int) ($a_colspans[$ckey] ?? 0) > 1) {
306 $cell->set_attribute("ColSpan", (int) $a_colspans[$ckey]);
307 } else {
308 if ($cell->has_attribute("ColSpan")) {
309 $cell->remove_attribute("ColSpan");
310 }
311 }
312 if ((int) ($a_rowspans[$ckey] ?? 0) > 1) {
313 $cell->set_attribute("RowSpan", (int) $a_rowspans[$ckey]);
314 } else {
315 if ($cell->has_attribute("RowSpan")) {
316 $cell->remove_attribute("RowSpan");
317 }
318 }
319 }
320 $x++;
321 }
322 $y++;
323 }
324 }
325 $this->fixHideAndSpans();
326 }
327
333 public function fixHideAndSpans(): void
334 {
335
336 // first: get max x and y
337 $max_x = $max_y = 0;
338 $y = 0;
339 $rows = $this->tab_node->child_nodes();
340
341 foreach ($rows as $row) {
342 if ($row->node_name() == "TableRow") {
343 $x = 0;
344 $cells = $row->child_nodes();
345 foreach ($cells as $cell) {
346 if ($cell->node_name() == "TableData") {
347 $max_x = max($max_x, $x);
348 $max_y = max($max_y, $y);
349 }
350 $x++;
351 }
352 $y++;
353 }
354 }
355
356 // second: fix hidden/colspans for all cells
357 $y = 0;
358 $colspans = [];
359 $rowspans = [];
360 $rows = $this->tab_node->child_nodes();
361 foreach ($rows as $row) {
362 if ($row->node_name() == "TableRow") {
363 $x = 0;
364 $cells = $row->child_nodes();
365 foreach ($cells as $cell) {
366 if ($cell->node_name() == "TableData") {
367 $cspan = max(1, (int) $cell->get_attribute("ColSpan"));
368 $rspan = max(1, (int) $cell->get_attribute("RowSpan"));
369
370 // if col or rowspan is to high: reduce it to the max
371 if ($cspan > $max_x - $x + 1) {
372 $cell->set_attribute("ColSpan", $max_x - $x + 1);
373 $cspan = $max_x - $x + 1;
374 }
375 if ($rspan > $max_y - $y + 1) {
376 $cell->set_attribute("RowSpan", $max_y - $y + 1);
377 $rspan = $max_y - $y + 1;
378 }
379
380 // check hidden status
381 if ($this->checkCellHidden($colspans, $rowspans, $x, $y)) {
382 // hidden: set hidden flag, remove col and rowspan
383 $cell->set_attribute("Hidden", "Y");
384 $cspan = 1;
385 $rspan = 1;
386 if ($cell->has_attribute("ColSpan")) {
387 $cell->remove_attribute("ColSpan");
388 }
389 if ($cell->has_attribute("RowSpan")) {
390 $cell->remove_attribute("RowSpan");
391 }
392 $this->makeEmptyCell($cell);
393 } else {
394 // not hidden: remove hidden flag if existing
395 if ($cell->has_attribute("Hidden")) {
396 $cell->remove_attribute("Hidden");
397 }
398 }
399
400 $colspans[$x][$y] = $cspan;
401 $rowspans[$x][$y] = $rspan;
402 }
403 $x++;
404 }
405 $y++;
406 }
407 }
408 }
409
410
414 public function makeEmptyCell(php4DOMElement $td_node): void
415 {
416 // delete children of paragraph node
417 $children = $td_node->child_nodes();
418 for ($i = 0; $i < count($children); $i++) {
419 $td_node->remove_child($children[$i]);
420 }
421 }
422
426 public function checkCellHidden(array $colspans, array $rowspans, int $x, int $y): bool
427 {
428 for ($i = 0; $i <= $x; $i++) {
429 for ($j = 0; $j <= $y; $j++) {
430 if ($i != $x || $j != $y) {
431 if ((($i + $colspans[$i][$j] > $x) &&
432 ($j + $rowspans[$i][$j] > $y))) {
433 return true;
434 }
435 }
436 }
437 }
438 return false;
439 }
440
444 public function getAllCellClasses(): array
445 {
446 $classes = array();
447 $rows = $this->tab_node->child_nodes();
448 foreach ($rows as $row) {
449 if ($row->node_name() == "TableRow") {
450 $cells = $row->child_nodes();
451 foreach ($cells as $cell) {
452 if ($cell->node_name() == "TableData") {
453 $classes[$cell->get_attribute("HierId") . ":" . $cell->get_attribute("PCID")]
454 = $cell->get_attribute("Class");
455 }
456 }
457 }
458 }
459
460 return $classes;
461 }
462
463 public function getAllCellAlignments(): array
464 {
465 $classes = array();
466 $rows = $this->tab_node->child_nodes();
467 foreach ($rows as $row) {
468 if ($row->node_name() == "TableRow") {
469 $cells = $row->child_nodes();
470 foreach ($cells as $cell) {
471 if ($cell->node_name() == "TableData") {
472 $classes[$cell->get_attribute("HierId") . ":" . $cell->get_attribute("PCID")]
473 = $cell->get_attribute("HorizontalAlign");
474 }
475 }
476 }
477 }
478
479 return $classes;
480 }
481
485 public function getAllCellSpans(): array
486 {
487 $spans = array();
488 $rows = $this->tab_node->child_nodes();
489 $y = 0;
490 $max_x = 0;
491 $max_y = 0;
492 foreach ($rows as $row) {
493 if ($row->node_name() == "TableRow") {
494 $x = 0;
495 $cells = $row->child_nodes();
496 foreach ($cells as $cell) {
497 if ($cell->node_name() == "TableData") {
498 $spans[$cell->get_attribute("HierId") . ":" . $cell->get_attribute("PCID")]
499 = array("x" => $x, "y" => $y, "colspan" => $cell->get_attribute("ColSpan"),
500 "rowspan" => $cell->get_attribute("RowSpan"));
501 $max_x = max($max_x, $x);
502 $max_y = max($max_y, $y);
503 }
504 $x++;
505 }
506 $y++;
507 }
508 }
509 foreach ($spans as $k => $v) {
510 $spans[$k]["max_x"] = $max_x;
511 $spans[$k]["max_y"] = $max_y;
512 }
513
514 return $spans;
515 }
516
521 public function getAllCellWidths(): array
522 {
523 $widths = array();
524 $rows = $this->tab_node->child_nodes();
525 foreach ($rows as $row) {
526 if ($row->node_name() == "TableRow") {
527 $cells = $row->child_nodes();
528 foreach ($cells as $cell) {
529 if ($cell->node_name() == "TableData") {
530 $widths[$cell->get_attribute("HierId") . ":" . $cell->get_attribute("PCID")]
531 = $cell->get_attribute("Width");
532 }
533 }
534 }
535 }
536
537 return $widths;
538 }
539
543 public function setTDClass(
544 string $a_hier_id,
545 string $a_class,
546 string $a_pc_id = ""
547 ): void {
548 $xpc = xpath_new_context($this->dom);
549 if ($a_pc_id == "") {
550 $path = "//TableData[@HierId = '" . $a_hier_id . "']";
551 } else {
552 $path = "//TableData[@PCID = '" . $a_pc_id . "']";
553 }
554 $res = xpath_eval($xpc, $path);
555 if (count($res->nodeset) == 1) {
556 if ($a_class != "") {
557 $res->nodeset[0]->set_attribute("Class", $a_class);
558 } else {
559 if ($res->nodeset[0]->has_attribute("Class")) {
560 $res->nodeset[0]->remove_attribute("Class");
561 }
562 }
563 }
564 }
565
569 public function setTDAlignment(
570 string $a_hier_id,
571 string $a_class,
572 string $a_pc_id = ""
573 ): void {
574 $xpc = xpath_new_context($this->dom);
575 if ($a_pc_id == "") {
576 $path = "//TableData[@HierId = '" . $a_hier_id . "']";
577 } else {
578 $path = "//TableData[@PCID = '" . $a_pc_id . "']";
579 }
580 $res = xpath_eval($xpc, $path);
581 if (count($res->nodeset) == 1) {
582 if ($a_class != "") {
583 $res->nodeset[0]->set_attribute("HorizontalAlign", $a_class);
584 } else {
585 if ($res->nodeset[0]->has_attribute("HorizontalAlign")) {
586 $res->nodeset[0]->remove_attribute("HorizontalAlign");
587 }
588 }
589 }
590 }
591
592 public function getCaption(): string
593 {
594 $hier_id = $this->getHierId();
595 if (!empty($hier_id)) {
596 $xpc = xpath_new_context($this->dom);
597 $path = "//PageContent[@HierId = '" . $hier_id . "']/Table/Caption";
598 $res = xpath_eval($xpc, $path);
599
600 if (count($res->nodeset) == 1) {
601 return $res->nodeset[0]->get_content();
602 }
603 }
604 return "";
605 }
606
610 public function getCaptionAlign(): string
611 {
612 $hier_id = $this->getHierId();
613 if (!empty($hier_id)) {
614 $xpc = xpath_new_context($this->dom);
615 $path = "//PageContent[@HierId = '" . $hier_id . "']/Table/Caption";
616 $res = xpath_eval($xpc, $path);
617 if (count($res->nodeset) == 1) {
618 return $res->nodeset[0]->get_attribute("Align");
619 }
620 }
621 return "";
622 }
623
624 public function setCaption(string $a_content, string $a_align): void
625 {
626 if ($a_content != "") {
628 $this->dom,
629 $this->tab_node,
630 "Caption",
631 array("Summary", "TableRow"),
632 $a_content,
633 array("Align" => $a_align)
634 );
635 } else {
636 ilDOMUtil::deleteAllChildsByName($this->tab_node, array("Caption"));
637 }
638 }
639
640
641 public function importTableAttributes(
642 php4DOMElement $node
643 ): void {
644 /*echo "importing table attributes";
645 var_dump($tableNode);*/
646 if ($node->has_attributes()) {
647 foreach ($node->attributes() as $n) {
648 switch (strtolower($n->node_name())) {
649 case "border":
650 $this->setBorder($this->extractText($n));
651 break;
652 case "align":
653 $this->setHorizontalAlign(ucfirst(strtolower($this->extractText($n))));
654 break;
655 case "cellspacing":
656 $this->setCellSpacing($this->extractText($n));
657 break;
658 case "cellpadding":
659 $this->setCellPadding($this->extractText($n));
660 break;
661 case "width":
662 $this->setWidth($this->extractText($n));
663 break;
664 }
665 }
666 }
667 }
668
669
670 public function importCellAttributes(
671 php4DOMElement $node,
672 php4DOMElement $par
673 ): void {
674 /*echo "importing table attributes";
675 var_dump($tableNode);*/
676 if ($node->has_attributes()) {
677 foreach ($node->attributes() as $n) {
678 switch (strtolower($n->node_name())) {
679 case "class":
680 $par->set_attribute("Class", $this->extractText($n));
681 break;
682 case "width":
683 $par->set_attribute("Width", $this->extractText($n));
684 break;
685 }
686 }
687 }
688 }
689
690
691 public function importRow(
692 string $lng,
693 php4DOMElement $node
694 ): void {
695 $aRow = $this->addRow();
696
697 if ($node->has_child_nodes()) {
698 foreach ($node->child_nodes() as $n) {
699 if ($n->node_type() == XML_ELEMENT_NODE &&
700 strcasecmp($n->node_name(), "td") == 0) {
701 $this->importCell($lng, $n, $aRow);
702 }
703 }
704 }
705 }
706
707 public function importCell(
708 string $lng,
709 php4DOMElement $cellNode,
710 php4DOMElement $aRow
711 ): void {
712 /*echo "add Cell";
713 var_dump($cellNode);*/
714 $aCell = $this->addCell($aRow);
715 $par = new ilPCParagraph($this->getPage());
716 $par->createAtNode($aCell);
717 $par->setText($par->input2xml($this->extractText($cellNode)));
718 $par->setCharacteristic("TableContent");
719 $par->setLanguage($lng);
720 $this->importCellAttributes($cellNode, $aCell);
721 }
722
723 public function extractText(
724 php4DOMElement $node
725 ): string {
726 $output = "";
727
728 $owner_document = $node->owner_document();
729 $children = $node->child_nodes();
730 $total_children = count($children);
731 for ($i = 0; $i < $total_children; $i++) {
732 $cur_child_node = $children[$i];
733 $output .= $owner_document->dump_node($cur_child_node);
734 }
735 return $output;
736 }
737
741 public function importHtml(
742 string $lng,
743 string $htmlTable
744 ) {
745 $dummy = ilUtil::stripSlashes($htmlTable, false);
746 $dom = domxml_open_mem($dummy, DOMXML_LOAD_PARSING, $error);
747
748 if ($dom) {
749 $xpc = xpath_new_context($dom);
750 // extract first table object
751 $path = "//table[1] | //Table[1]";
752 $res = xpath_eval($xpc, $path);
753
754 if (count($res->nodeset) == 0) {
755 $error = "Could not find a table root node";
756 }
757
758 if (empty($error)) {
759 for ($i = 0; $i < count($res->nodeset); $i++) {
760 $node = $res->nodeset[$i];
761
762 $this->importTableAttributes($node);
763
764 if ($node->has_child_nodes()) {
765 foreach ($node->child_nodes() as $n) {
766 if ($n->node_type() == XML_ELEMENT_NODE &&
767 strcasecmp($n->node_name(), "tr") == 0) {
768 $this->importRow($lng, $n);
769 }
770 }
771 }
772 }
773 }
774 $dom->free();
775 }
776 if (is_array($error)) {
777 $errmsg = "";
778 foreach ($error as $errorline) { # Loop through all errors
779 $errmsg .= "[" . $errorline['line'] . ", " . $errorline['col'] . "]: " . $errorline['errormessage'] . " at Node '" . $errorline['nodename'] . "'<br />";
780 }
781 } else {
782 $errmsg = $error;
783 }
784
785 if (empty($errmsg)) {
786 return true;
787 }
788
789 return $errmsg;
790 }
791
792 public function setFirstRowStyle(
793 string $a_class
794 ): void {
795 $childs = $this->tab_node->child_nodes();
796 foreach ($childs as $child) {
797 if ($child->node_name() == "TableRow") {
798 $gchilds = $child->child_nodes();
799 foreach ($gchilds as $gchild) {
800 if ($gchild->node_name() == "TableData") {
801 $gchild->set_attribute("Class", $a_class);
802 }
803 }
804 return;
805 }
806 }
807 }
808
812 public function setClass(string $a_class): void
813 {
814 $this->setTableAttribute("Class", $a_class);
815 }
816
817 public function getClass(): string
818 {
819 return $this->getTableAttribute("Class");
820 }
821
822 public function setTemplate(string $a_template): void
823 {
824 $this->setTableAttribute("Template", $a_template);
825 }
826
827 public function getTemplate(): string
828 {
829 return $this->getTableAttribute("Template");
830 }
831
832 public function setHeaderRows(int $a_nr): void
833 {
834 $this->setTableAttribute("HeaderRows", $a_nr);
835 }
836
837 public function getHeaderRows(): int
838 {
839 return (int) $this->getTableAttribute("HeaderRows");
840 }
841
842 public function setFooterRows(int $a_nr): void
843 {
844 $this->setTableAttribute("FooterRows", $a_nr);
845 }
846
847 public function getFooterRows(): int
848 {
849 return (int) $this->getTableAttribute("FooterRows");
850 }
851
852 public function setHeaderCols(int $a_nr): void
853 {
854 $this->setTableAttribute("HeaderCols", $a_nr);
855 }
856
857 public function getHeaderCols(): int
858 {
859 return (int) $this->getTableAttribute("HeaderCols");
860 }
861
862 public function setFooterCols(int $a_nr): void
863 {
864 $this->setTableAttribute("FooterCols", $a_nr);
865 }
866
867 public function getFooterCols(): int
868 {
869 return (int) $this->getTableAttribute("FooterCols");
870 }
871
875 protected function setTableAttribute(
876 string $a_attr,
877 string $a_value
878 ): void {
879 if (!empty($a_value)) {
880 $this->tab_node->set_attribute($a_attr, $a_value);
881 } else {
882 if ($this->tab_node->has_attribute($a_attr)) {
883 $this->tab_node->remove_attribute($a_attr);
884 }
885 }
886 }
887
888 public function getTableAttribute(string $a_attr): string
889 {
890 if (is_object($this->tab_node)) {
891 return $this->tab_node->get_attribute($a_attr);
892 }
893 return "";
894 }
895
896 public static function getLangVars(): array
897 {
898 return array("ed_insert_dtable", "ed_insert_atable","ed_new_row_after", "ed_new_row_before",
899 "ed_new_col_after", "ed_new_col_before", "ed_delete_col",
900 "ed_delete_row", "ed_edit_data", "ed_row_up", "ed_row_down",
901 "ed_col_left", "ed_col_right");
902 }
903
904
905 public static function handleCopiedContent(
906 DOMDocument $a_domdoc,
907 bool $a_self_ass = true,
908 bool $a_clone_mobs = false,
909 int $new_parent_id = 0,
910 int $obj_copy_id = 0
911 ): void {
912 $xpath = new DOMXPath($a_domdoc);
913 $nodes = $xpath->query("//Table");
914 foreach ($nodes as $node) {
915 $node->removeAttribute("Id");
916 }
917 }
918
919 public function getModel(): ?stdClass
920 {
921 $model = new \stdClass();
922
923 $rows = $this->tab_node->child_nodes();
924
925 $y = 0;
926 foreach ($rows as $row) {
927 if ($row->node_name() == "TableRow") {
928 $x = 0;
929 $cells = $row->child_nodes();
930 foreach ($cells as $cell) {
931 if ($cell->node_name() == "TableData") {
933 $this->getCellText($y, $x),
934 true,
935 false
936 );
937 $text = ilPCParagraphGUI::xml2outputJS($text);
938 $model->content[$y][$x] = $text;
939 }
940 $x++;
941 }
942 $y++;
943 }
944 }
945
946 return $model;
947 }
948}
const IL_INSERT_AFTER
static deleteAllChildsByName(php4DOMElement $a_parent, array $a_node_names)
delete all childs of a node by names in $a_node_names
static setFirstOptionalElement(php4DOMDocument $doc, php4DOMElement $parent_node, string $a_node_name, array $a_successors, string $a_content, array $a_attributes, bool $a_remove_childs=true)
searches for an element $a_node_name within the childs of $parent_node if no node is found,...
static xml2outputJS(string $s_text)
Prepare content for js output.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static xml2output(string $a_text, bool $a_wysiwyg=false, bool $a_replace_lists=true, bool $unmask=true)
Converts xml from DB to output in edit textarea.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
importSpreadsheet(string $a_lang, string $a_data)
import from table
setTDAlignment(string $a_hier_id, string $a_class, string $a_pc_id="")
set alignment of table data cell
setTDSpans(array $a_colspans, array $a_rowspans)
setTableAttribute(string $a_attr, string $a_value)
Set attribute of table tag.
setBorder(string $a_border)
setFirstRowStyle(string $a_class)
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
importCell(string $lng, php4DOMElement $cellNode, php4DOMElement $aRow)
setCaption(string $a_content, string $a_align)
addRows(int $a_nr_rows, int $a_nr_cols)
add rows to table
setCellSpacing(string $a_spacing)
getCellText(int $i, int $j)
Get cell text of row $i and cell $j.
setCellPadding(string $a_padding)
setTemplate(string $a_template)
static getLangVars()
Get lang vars needed for editing.
checkCellHidden(array $colspans, array $rowspans, int $x, int $y)
Check hidden status.
importRow(string $lng, php4DOMElement $node)
setFooterCols(int $a_nr)
setHeaderCols(int $a_nr)
addCell(php4DOMElement $aRow, string $a_data="", string $a_lang="")
importTableAttributes(php4DOMElement $node)
importCellAttributes(php4DOMElement $node, php4DOMElement $par)
php4DOMElement $tab_node
getModel()
Get model as needed for the front-end editor.
setTDWidth(string $a_hier_id, string $a_width, string $a_pc_id="")
set width of table data cell
setLanguage(string $a_lang)
setWidth(string $a_width)
setHorizontalAlign(string $a_halign)
static handleCopiedContent(DOMDocument $a_domdoc, bool $a_self_ass=true, bool $a_clone_mobs=false, int $new_parent_id=0, int $obj_copy_id=0)
Handle copied content.
getTableAttribute(string $a_attr)
setTDClass(string $a_hier_id, string $a_class, string $a_pc_id="")
set class of table data cell
setNode(php4DOMElement $a_node)
Set xml node of page content.
fixHideAndSpans()
Fix Hide and Spans.
setClass(string $a_class)
Set Style Class of table.
getAllCellClasses()
Get all cell classes.
importHtml(string $lng, string $htmlTable)
extractText(php4DOMElement $node)
getAllCellSpans()
Get all cell spans.
init()
Init object.
getCellNode(int $i, int $j, bool $create_if_not_exists=false)
Get cell paragraph node of row $i and cell $j.
makeEmptyCell(php4DOMElement $td_node)
Make cell empty.
getCaptionAlign()
get caption alignment (Top | Bottom)
setFooterRows(int $a_nr)
getAllCellWidths()
Get all cell widths.
setHeaderRows(int $a_nr)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
createPageContentNode(bool $a_set_this_node=true)
Create page content node (always use this method first when adding a new element)
setType(string $a_type)
Set Type.
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
insertContent(ilPageContent $a_cont_obj, string $a_pos, int $a_mode=IL_INSERT_AFTER, string $a_pcid="", bool $remove_placeholder=true)
insert a content node before/after a sibling or as first child of a parent
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
set_attribute($name, $value)
remove_child($oldchild)
append_child($newnode)
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
domxml_open_mem($str, $mode=0, &$error=null)
xpath_new_context($dom_document)
const DOMXML_LOAD_PARSING
xpath_eval(php4DOMXPath $xpath_context, string $eval_str, $contextnode=null)
$path
Definition: ltiservices.php:32
$res
Definition: ltiservices.php:69
$i
Definition: metadata.php:41
$lng
$rows
Definition: xhr_table.php:10