ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPCTable.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once("./Services/COPage/classes/class.ilPageContent.php");
6 
17 class ilPCTable extends ilPageContent
18 {
19  public $dom;
20  public $tab_node;
21 
22 
26  public function init()
27  {
28  $this->setType("tab");
29  }
30 
31  public function setNode($a_node)
32  {
33  parent::setNode($a_node); // this is the PageContent node
34  $this->tab_node = $a_node->first_child(); // this is the Table node
35  }
36 
37  public function create(&$a_pg_obj, $a_hier_id, $a_pc_id = "")
38  {
39  $this->node = $this->createPageContentNode();
40  $a_pg_obj->insertContent($this, $a_hier_id, IL_INSERT_AFTER, $a_pc_id);
41  $this->tab_node = $this->dom->create_element("Table");
42  $this->tab_node = $this->node->append_child($this->tab_node);
43  $this->tab_node->set_attribute("Language", "");
44  }
45 
46  public function &addRow()
47  {
48  $new_tr = $this->dom->create_element("TableRow");
49  $new_tr = &$this->tab_node->append_child($new_tr);
50  return $new_tr;
51  }
52 
53  public function &addCell(&$aRow, $a_data = "", $a_lang = "")
54  {
55  $new_td = $this->dom->create_element("TableData");
56  $new_td = $aRow->append_child($new_td);
57 
58  // insert data if given
59  if ($a_data != "") {
60  $new_pg = $this->createPageContentNode(false);
61  $new_par = $this->dom->create_element("Paragraph");
62  $new_par = $new_pg->append_child($new_par);
63  $new_par->set_attribute("Language", $a_lang);
64  $new_par->set_attribute("Characteristic", "TableContent");
65  $new_par->set_content($a_data);
66  $new_td->append_child($new_pg);
67  }
68 
69  return $new_td;
70  }
71 
75  public function getCellText($i, $j)
76  {
77  $cell_par = $this->getCellNode($i, $j, false);
78 
79  if (is_object($cell_par)) {
80  $content = "";
81  $childs = $cell_par->child_nodes();
82  for ($i = 0; $i < count($childs); $i++) {
83  $content .= $this->dom->dump_node($childs[$i]);
84  }
85  return $content;
86  } else {
87  return "";
88  }
89  }
90 
94  public function getCellNode($i, $j, $create_if_not_exists = false)
95  {
96  $xpc = xpath_new_context($this->dom);
97  $path = "//PageContent[@HierId='" . $this->getHierId() . "']" .
98  "/Table/TableRow[$i+1]/TableData[$j+1]/PageContent[1]/Paragraph[1]";
99  //echo "<br>++".$path;
100  //]--//PageContent[@HierId='3']/Table/TableRow[+1]/TableData[0 style=+1]/PageContent[1]/Paragraph[1]
101  $res = xpath_eval($xpc, $path);
102 
103  if (is_object($res->nodeset[0])) {
104  return $res->nodeset[0];
105  } else { // no node -> delete all childs and create paragraph
106  if (!$create_if_not_exists) {
107  return null;
108  }
109  $xpc2 = xpath_new_context($this->dom);
110  $path2 = "//PageContent[@HierId='" . $this->getHierId() . "']" .
111  "/Table/TableRow[" . ($i + 1) . "]/TableData[" . ($j + 1) . "]";
112  //$path2 = "//PageContent";
113 
114  $res2 = xpath_eval($xpc2, $path2);
115 
116  $td_node = $res2->nodeset[0];
117 
118  if (is_object($td_node)) {
119  // delete children of paragraph node
120  $children = $td_node->child_nodes();
121  for ($i = 0; $i < count($children); $i++) {
122  $td_node->remove_child($children[$i]);
123  }
124 
125  // create page content and paragraph node here.
126  $pc_node = $this->createPageContentNode(false);
127  $pc_node = $td_node->append_child($pc_node);
128  $par_node = $this->dom->create_element("Paragraph");
129  $par_node = $pc_node->append_child($par_node);
130  $par_node->set_attribute("Characteristic", "TableContent");
131  $par_node->set_attribute(
132  "Language",
133  $this->getLanguage()
134  );
135 
136  return $par_node;
137  }
138  }
139 
140  return "";
141  }
142 
146  public function addRows($a_nr_rows, $a_nr_cols)
147  {
148  for ($i = 1; $i <= $a_nr_rows; $i++) {
149  $aRow = $this->addRow();
150  for ($j = 1; $j <= $a_nr_cols; $j++) {
151  $this->addCell($aRow);
152  }
153  }
154  }
155 
159  public function importSpreadsheet($a_lang, $a_data)
160  {
161  str_replace($a_data, "\r", "\n");
162  str_replace($a_data, "\n\n", "\n");
163  $target_rows = array();
164  $rows = explode("\n", $a_data);
165 
166  // get maximum of cols in a row and
167  // put data in target_row arrays
168  foreach ($rows as $row) {
169  $cells = explode("\t", $row);
170  $max_cols = ($max_cols > count($cells))
171  ? $max_cols
172  : count($cells);
173  $target_rows[] = $cells;
174  }
175 
176  // iterate target row arrays and insert data
177  foreach ($target_rows as $row) {
178  $aRow = $this->addRow();
179  for ($j = 0; $j < $max_cols; $j++) {
180  // mask html
181  $data = str_replace("&", "&amp;", $row[$j]);
182  $data = str_replace("<", "&lt;", $data);
183  $data = str_replace(">", "&gt;", $data);
184 
185  $this->addCell($aRow, $data, $a_lang);
186  }
187  }
188  }
189 
193  public function getLanguage()
194  {
195  return $this->getTableAttribute("Language");
196  }
197 
203  public function setLanguage($a_lang)
204  {
205  if ($a_lang != "") {
206  $this->setTableAttribute("Language", $a_lang);
207  }
208  }
209 
213  public function getWidth()
214  {
215  return $this->getTableAttribute("Width");
216  }
217 
223  public function setWidth($a_width)
224  {
225  $this->setTableAttribute("Width", $a_width);
226  }
227 
231  public function getBorder()
232  {
233  return $this->getTableAttribute("Border");
234  }
235 
241  public function setBorder($a_border)
242  {
243  $this->setTableAttribute("Border", $a_border);
244  }
245 
249  public function getCellSpacing()
250  {
251  return $this->getTableAttribute("CellSpacing");
252  }
253 
259  public function setCellSpacing($a_spacing)
260  {
261  $this->setTableAttribute("CellSpacing", $a_spacing);
262  }
263 
267  public function getCellPadding()
268  {
269  return $this->getTableAttribute("CellPadding");
270  }
271 
277  public function setCellPadding($a_padding)
278  {
279  $this->setTableAttribute("CellPadding", $a_padding);
280  }
281 
285  public function setHorizontalAlign($a_halign)
286  {
287  $this->tab_node->set_attribute("HorizontalAlign", $a_halign);
288  }
289 
293  public function getHorizontalAlign()
294  {
295  return $this->getTableAttribute("HorizontalAlign");
296  }
297 
301  public function setTDWidth($a_hier_id, $a_width, $a_pc_id = "")
302  {
303  $xpc = xpath_new_context($this->dom);
304 
305  if ($a_pc_id == "") {
306  $path = "//TableData[@HierId = '" . $a_hier_id . "']";
307  } else {
308  $path = "//TableData[@PCID = '" . $a_pc_id . "']";
309  }
310  $res = xpath_eval($xpc, $path);
311 
312  if (count($res->nodeset) == 1) {
313  if ($a_width != "") {
314  $res->nodeset[0]->set_attribute("Width", $a_width);
315  } else {
316  if ($res->nodeset[0]->has_attribute("Width")) {
317  $res->nodeset[0]->remove_attribute("Width");
318  }
319  }
320  }
321  }
322 
326  public function setTDSpans($a_colspans, $a_rowspans)
327  {
328  $y = 0;
329  $rows = $this->tab_node->child_nodes();
330  foreach ($rows as $row) {
331  if ($row->node_name() == "TableRow") {
332  $x = 0;
333  $cells = $row->child_nodes();
334  foreach ($cells as $cell) {
335  if ($cell->node_name() == "TableData") {
336  $ckey = $cell->get_attribute("HierId") . ":" . $cell->get_attribute("PCID");
337  if ((int) $a_colspans[$ckey] > 1) {
338  $cell->set_attribute("ColSpan", (int) $a_colspans[$ckey]);
339  } else {
340  if ($cell->has_attribute("ColSpan")) {
341  $cell->remove_attribute("ColSpan");
342  }
343  }
344  if ((int) $a_rowspans[$ckey] > 1) {
345  $cell->set_attribute("RowSpan", (int) $a_rowspans[$ckey]);
346  } else {
347  if ($cell->has_attribute("RowSpan")) {
348  $cell->remove_attribute("RowSpan");
349  }
350  }
351  }
352  $x++;
353  }
354  $y++;
355  }
356  }
357  $this->fixHideAndSpans();
358  }
359 
365  public function fixHideAndSpans()
366  {
367 
368  // first: get max x and y
369  $max_x = $max_y = 0;
370  $y = 0;
371  $rows = $this->tab_node->child_nodes();
372 
373  foreach ($rows as $row) {
374  if ($row->node_name() == "TableRow") {
375  $x = 0;
376  $cells = $row->child_nodes();
377  foreach ($cells as $cell) {
378  if ($cell->node_name() == "TableData") {
379  $max_x = max($max_x, $x);
380  $max_y = max($max_y, $y);
381  }
382  $x++;
383  }
384  $y++;
385  }
386  }
387 
388  // second: fix hidden/colspans for all cells
389  $y = 0;
390  $rows = $this->tab_node->child_nodes();
391  foreach ($rows as $row) {
392  if ($row->node_name() == "TableRow") {
393  $x = 0;
394  $cells = $row->child_nodes();
395  foreach ($cells as $cell) {
396  if ($cell->node_name() == "TableData") {
397  $cspan = max(1, (int) $cell->get_attribute("ColSpan"));
398  $rspan = max(1, (int) $cell->get_attribute("RowSpan"));
399 
400  // if col or rowspan is to high: reduce it to the max
401  if ($cspan > $max_x - $x + 1) {
402  $cell->set_attribute("ColSpan", $max_x - $x + 1);
403  $cspan = $max_x - $x + 1;
404  }
405  if ($rspan > $max_y - $y + 1) {
406  $cell->set_attribute("RowSpan", $max_y - $y + 1);
407  $rspan = $max_y - $y + 1;
408  }
409 
410  // check hidden status
411  if ($this->checkCellHidden($colspans, $rowspans, $x, $y)) {
412  // hidden: set hidden flag, remove col and rowspan
413  $cell->set_attribute("Hidden", "Y");
414  $cspan = 1;
415  $rspan = 1;
416  if ($cell->has_attribute("ColSpan")) {
417  $cell->remove_attribute("ColSpan");
418  }
419  if ($cell->has_attribute("RowSpan")) {
420  $cell->remove_attribute("RowSpan");
421  }
422  $this->makeEmptyCell($cell);
423  } else {
424  // not hidden: remove hidden flag if existing
425  if ($cell->has_attribute("Hidden")) {
426  $cell->remove_attribute("Hidden");
427  }
428  }
429 
430  $colspans[$x][$y] = $cspan;
431  $rowspans[$x][$y] = $rspan;
432  }
433  $x++;
434  }
435  $y++;
436  }
437  }
438  }
439 
440 
444  public function makeEmptyCell($td_node)
445  {
446  // delete children of paragraph node
447  $children = $td_node->child_nodes();
448  for ($i = 0; $i < count($children); $i++) {
449  $td_node->remove_child($children[$i]);
450  }
451  }
452 
456  public function checkCellHidden($colspans, $rowspans, $x, $y)
457  {
458  for ($i = 0; $i <= $x; $i++) {
459  for ($j = 0; $j <= $y; $j++) {
460  if ($i != $x || $j != $y) {
461  if ((($i + $colspans[$i][$j] > $x) &&
462  ($j + $rowspans[$i][$j] > $y))) {
463  return true;
464  }
465  }
466  }
467  }
468  return false;
469  }
470 
476  public function getAllCellClasses()
477  {
478  $classes = array();
479  $rows = $this->tab_node->child_nodes();
480  foreach ($rows as $row) {
481  if ($row->node_name() == "TableRow") {
482  $cells = $row->child_nodes();
483  foreach ($cells as $cell) {
484  if ($cell->node_name() == "TableData") {
485  $classes[$cell->get_attribute("HierId") . ":" . $cell->get_attribute("PCID")]
486  = $cell->get_attribute("Class");
487  }
488  }
489  }
490  }
491 
492  return $classes;
493  }
494 
500  public function getAllCellAlignments()
501  {
502  $classes = array();
503  $rows = $this->tab_node->child_nodes();
504  foreach ($rows as $row) {
505  if ($row->node_name() == "TableRow") {
506  $cells = $row->child_nodes();
507  foreach ($cells as $cell) {
508  if ($cell->node_name() == "TableData") {
509  $classes[$cell->get_attribute("HierId") . ":" . $cell->get_attribute("PCID")]
510  = $cell->get_attribute("HorizontalAlign");
511  }
512  }
513  }
514  }
515 
516  return $classes;
517  }
518 
524  public function getAllCellSpans()
525  {
526  $spans = array();
527  $rows = $this->tab_node->child_nodes();
528  $y = 0;
529  $max_x = 0;
530  $max_y = 0;
531  foreach ($rows as $row) {
532  if ($row->node_name() == "TableRow") {
533  $x = 0;
534  $cells = $row->child_nodes();
535  foreach ($cells as $cell) {
536  if ($cell->node_name() == "TableData") {
537  $spans[$cell->get_attribute("HierId") . ":" . $cell->get_attribute("PCID")]
538  = array("x" => $x, "y" => $y, "colspan" => $cell->get_attribute("ColSpan"),
539  "rowspan" => $cell->get_attribute("RowSpan"));
540  $max_x = max($max_x, $x);
541  $max_y = max($max_y, $y);
542  }
543  $x++;
544  }
545  $y++;
546  }
547  }
548  foreach ($spans as $k => $v) {
549  $spans[$k]["max_x"] = $max_x;
550  $spans[$k]["max_y"] = $max_y;
551  }
552 
553  return $spans;
554  }
555 
561  public function getAllCellWidths()
562  {
563  $widths = array();
564  $rows = $this->tab_node->child_nodes();
565  foreach ($rows as $row) {
566  if ($row->node_name() == "TableRow") {
567  $cells = $row->child_nodes();
568  foreach ($cells as $cell) {
569  if ($cell->node_name() == "TableData") {
570  $widths[$cell->get_attribute("HierId") . ":" . $cell->get_attribute("PCID")]
571  = $cell->get_attribute("Width");
572  }
573  }
574  }
575  }
576 
577  return $widths;
578  }
579 
583  public function setTDClass($a_hier_id, $a_class, $a_pc_id = "")
584  {
585  $xpc = xpath_new_context($this->dom);
586  if ($a_pc_id == "") {
587  $path = "//TableData[@HierId = '" . $a_hier_id . "']";
588  } else {
589  $path = "//TableData[@PCID = '" . $a_pc_id . "']";
590  }
591  $res = xpath_eval($xpc, $path);
592  if (count($res->nodeset) == 1) {
593  if ($a_class != "") {
594  $res->nodeset[0]->set_attribute("Class", $a_class);
595  } else {
596  if ($res->nodeset[0]->has_attribute("Class")) {
597  $res->nodeset[0]->remove_attribute("Class");
598  }
599  }
600  }
601  }
602 
606  public function setTDAlignment($a_hier_id, $a_class, $a_pc_id = "")
607  {
608  $xpc = xpath_new_context($this->dom);
609  if ($a_pc_id == "") {
610  $path = "//TableData[@HierId = '" . $a_hier_id . "']";
611  } else {
612  $path = "//TableData[@PCID = '" . $a_pc_id . "']";
613  }
614  $res = xpath_eval($xpc, $path);
615  if (count($res->nodeset) == 1) {
616  if ($a_class != "") {
617  $res->nodeset[0]->set_attribute("HorizontalAlign", $a_class);
618  } else {
619  if ($res->nodeset[0]->has_attribute("HorizontalAlign")) {
620  $res->nodeset[0]->remove_attribute("HorizontalAlign");
621  }
622  }
623  }
624  }
625 
629  public function getCaption()
630  {
631  $hier_id = $this->getHierId();
632  if (!empty($hier_id)) {
633  $xpc = xpath_new_context($this->dom);
634  $path = "//PageContent[@HierId = '" . $hier_id . "']/Table/Caption";
635  $res = xpath_eval($xpc, $path);
636 
637  if (count($res->nodeset) == 1) {
638  return $res->nodeset[0]->get_content();
639  }
640  }
641  }
642 
646  public function getCaptionAlign()
647  {
648  $hier_id = $this->getHierId();
649  if (!empty($hier_id)) {
650  $xpc = xpath_new_context($this->dom);
651  $path = "//PageContent[@HierId = '" . $hier_id . "']/Table/Caption";
652  $res = xpath_eval($xpc, $path);
653  if (count($res->nodeset) == 1) {
654  return $res->nodeset[0]->get_attribute("Align");
655  }
656  }
657  }
658 
662  public function setCaption($a_content, $a_align)
663  {
664  if ($a_content != "") {
666  $this->dom,
667  $this->tab_node,
668  "Caption",
669  array("Summary", "TableRow"),
670  $a_content,
671  array("Align" => $a_align)
672  );
673  } else {
674  ilDOMUtil::deleteAllChildsByName($this->tab_node, array("Caption"));
675  }
676  }
677 
678 
679  public function importTableAttributes(&$node)
680  {
681  /*echo "importing table attributes";
682  var_dump($tableNode);*/
683  if ($node->has_attributes()) {
684  foreach ($node->attributes() as $n) {
685  switch (strtolower($n->node_name())) {
686  case "border":
687  $this->setBorder($this->extractText($n));
688  break;
689  case "align":
690  $this->setHorizontalAlign(ucfirst(strtolower($this->extractText($n))));
691  break;
692  case "cellspacing":
693  $this->setCellSpacing($this->extractText($n));
694  break;
695  case "cellpadding":
696  $this->setCellPadding($this->extractText($n));
697  break;
698  case "width":
699  $this->setWidth($this->extractText($n));
700  break;
701 
702  }
703  }
704  }
705  }
706 
707 
708  public function importCellAttributes(&$node, &$par)
709  {
710  /*echo "importing table attributes";
711  var_dump($tableNode);*/
712  if ($node->has_attributes()) {
713  foreach ($node->attributes() as $n) {
714  switch (strtolower($n->node_name())) {
715  case "class":
716  $par->set_attribute("Class", $this->extractText($n));
717  break;
718  case "width":
719  $par->set_attribute("Width", $this->extractText($n));
720  break;
721  }
722  }
723  }
724  }
725 
726 
727  public function importRow($lng, &$node)
728  {
729  /*echo "add Row";
730  var_dump($node);*/
731 
732  $aRow = $this->addRow();
733 
734  if ($node->has_child_nodes()) {
735  foreach ($node->child_nodes() as $n) {
736  if ($n->node_type() == XML_ELEMENT_NODE &&
737  strcasecmp($n->node_name(), "td") == 0) {
738  $this->importCell($lng, $n, $aRow);
739  }
740  }
741  }
742  }
743 
744  public function importCell($lng, &$cellNode, &$aRow)
745  {
746  /*echo "add Cell";
747  var_dump($cellNode);*/
748  $aCell = $this->addCell($aRow);
749  $par = new ilPCParagraph($this->getPage());
750  $par->createAtNode($aCell);
751  $par->setText($par->input2xml($this->extractText($cellNode)));
752  $par->setCharacteristic("TableContent");
753  $par->setLanguage($lng);
754  $this->importCellAttributes($cellNode, $aCell);
755  }
756 
757  public function extractText(&$node)
758  {
759  $owner_document = $node->owner_document();
760  $children = $node->child_nodes();
761  $total_children = count($children);
762  for ($i = 0; $i < $total_children; $i++) {
763  $cur_child_node = $children[$i];
764  $output .= $owner_document->dump_node($cur_child_node);
765  }
766  return $output;
767  }
768 
769  public function importHtml($lng, $htmlTable)
770  {
771  $dummy = ilUtil::stripSlashes($htmlTable, false);
772  //echo htmlentities($dummy);
773  $dom = @domxml_open_mem($dummy, DOMXML_LOAD_PARSING, $error);
774 
775  if ($dom) {
776  $xpc = @xpath_new_context($dom);
777  // extract first table object
778  $path = "//table[1] | //Table[1]";
779  $res = @xpath_eval($xpc, $path);
780 
781  if (count($res->nodeset) == 0) {
782  $error = "Could not find a table root node";
783  }
784 
785  if (empty($error)) {
786  for ($i = 0; $i < count($res->nodeset); $i++) {
787  $node = $res->nodeset[$i];
788 
790 
791  if ($node->has_child_nodes()) {
792  foreach ($node->child_nodes() as $n) {
793  if ($n->node_type() == XML_ELEMENT_NODE &&
794  strcasecmp($n->node_name(), "tr") == 0) {
795  $this->importRow($lng, $n);
796  }
797  }
798  }
799  }
800  }
801  $dom->free();
802  }
803  if (is_array($error)) {
804  $errmsg = "";
805  foreach ($error as $errorline) { # Loop through all errors
806  $errmsg .= "[" . $errorline['line'] . ", " . $errorline['col'] . "]: " . $errorline['errormessage'] . " at Node '" . $errorline['nodename'] . "'<br />";
807  }
808  } else {
809  $errmsg = $error;
810  }
811 
812  if (empty($errmsg)) {
813  return true;
814  }
815 
816  $_SESSION["message"] = $errmsg;
817  return false;
818  }
819 
823  public function setFirstRowStyle($a_class)
824  {
825  $childs = $this->tab_node->child_nodes();
826  foreach ($childs as $child) {
827  if ($child->node_name() == "TableRow") {
828  $gchilds = $child->child_nodes();
829  foreach ($gchilds as $gchild) {
830  if ($gchild->node_name() == "TableData") {
831  $gchild->set_attribute("Class", $a_class);
832  }
833  }
834  return;
835  }
836  }
837  }
838 
844  public function setClass($a_class)
845  {
846  $this->setTableAttribute("Class", $a_class);
847  }
848 
854  public function getClass()
855  {
856  return $this->getTableAttribute("Class");
857  }
858 
864  public function setTemplate($a_template)
865  {
866  $this->setTableAttribute("Template", $a_template);
867  }
868 
874  public function getTemplate()
875  {
876  return $this->getTableAttribute("Template");
877  }
878 
884  public function setHeaderRows($a_nr)
885  {
886  $this->setTableAttribute("HeaderRows", $a_nr);
887  }
888 
894  public function getHeaderRows()
895  {
896  return $this->getTableAttribute("HeaderRows");
897  }
898 
904  public function setFooterRows($a_nr)
905  {
906  $this->setTableAttribute("FooterRows", $a_nr);
907  }
908 
914  public function getFooterRows()
915  {
916  return $this->getTableAttribute("FooterRows");
917  }
918 
924  public function setHeaderCols($a_nr)
925  {
926  $this->setTableAttribute("HeaderCols", $a_nr);
927  }
928 
934  public function getHeaderCols()
935  {
936  return $this->getTableAttribute("HeaderCols");
937  }
938 
944  public function setFooterCols($a_nr)
945  {
946  $this->setTableAttribute("FooterCols", $a_nr);
947  }
948 
954  public function getFooterCols()
955  {
956  return $this->getTableAttribute("FooterCols");
957  }
958 
965  protected function setTableAttribute($a_attr, $a_value)
966  {
967  if (!empty($a_value)) {
968  $this->tab_node->set_attribute($a_attr, $a_value);
969  } else {
970  if ($this->tab_node->has_attribute($a_attr)) {
971  $this->tab_node->remove_attribute($a_attr);
972  }
973  }
974  }
975 
981  public function getTableAttribute($a_attr)
982  {
983  if (is_object($this->tab_node)) {
984  return $this->tab_node->get_attribute($a_attr);
985  }
986  }
987 
992  public static function getLangVars()
993  {
994  return array("ed_insert_dtable", "ed_insert_atable","ed_new_row_after", "ed_new_row_before",
995  "ed_new_col_after", "ed_new_col_before", "ed_delete_col",
996  "ed_delete_row", "ed_edit_data", "ed_row_up", "ed_row_down",
997  "ed_col_left", "ed_col_right");
998  }
999 
1000 
1007  public static function handleCopiedContent(DOMDocument $a_domdoc, $a_self_ass = true, $a_clone_mobs = false)
1008  {
1009  $xpath = new DOMXPath($a_domdoc);
1010  $nodes = $xpath->query("//Table");
1011  foreach ($nodes as $node) {
1012  $node->removeAttribute("Id");
1013  }
1014  }
1015 
1019  public function getModel()
1020  {
1021  $model = new \stdClass();
1022 
1023  $rows = $this->tab_node->child_nodes();
1024 
1025  $y = 0;
1026  foreach ($rows as $row) {
1027  if ($row->node_name() == "TableRow") {
1028  $x = 0;
1029  $cells = $row->child_nodes();
1030  foreach ($cells as $cell) {
1031  if ($cell->node_name() == "TableData") {
1032  $text = ilPCParagraph::xml2output(
1033  $this->getCellText($y, $x),
1034  true,
1035  false
1036  );
1037  $text = ilPCParagraphGUI::xml2outputJS($text);
1038  $model->content[$y][$x] = $text;
1039  }
1040  $x++;
1041  }
1042  $y++;
1043  }
1044  }
1045 
1046  return $model;
1047  }
1048 }
getFooterRows()
Get footer rows.
setTDSpans($a_colspans, $a_rowspans)
Set TDSpans.
getCaption()
get caption
static getLangVars()
Get lang vars needed for editing.
getTableAttribute($a_attr)
Get table tag attribute.
$data
Definition: storeScorm.php:23
extractText(&$node)
setHeaderRows($a_nr)
Set header rows.
create(&$a_pg_obj, $a_hier_id, $a_pc_id="")
getWidth()
get table width
$_SESSION["AccountId"]
xpath_new_context($dom_document)
setTDWidth($a_hier_id, $a_width, $a_pc_id="")
set width of table data cell
Class ilPCTable.
setHeaderCols($a_nr)
Set header cols.
static xml2outputJS($s_text)
Prepare content for js output.
domxml_open_mem($str, $mode=0, &$error=null)
xpath_eval($xpath_context, $eval_str, $contextnode=null)
static deleteAllChildsByName($a_parent, $a_node_names)
delete all childs of a node by names in $a_node_names
importCell($lng, &$cellNode, &$aRow)
Class ilPCParagraph.
static handleCopiedContent(DOMDocument $a_domdoc, $a_self_ass=true, $a_clone_mobs=false)
Handle copied content.
setType($a_type)
Set Type.
setLanguage($a_lang)
set table language
setCaption($a_content, $a_align)
set table caption
importCellAttributes(&$node, &$par)
init()
Init page content component.
static xml2output($a_text, $a_wysiwyg=false, $a_replace_lists=true, $unmask=true)
Converts xml from DB to output in edit textarea.
getCellText($i, $j)
Get cell text of row $i and cell $j.
Class ilPageContent.
& addCell(&$aRow, $a_data="", $a_lang="")
getTemplate()
Get template.
getClass()
Get characteristic of section.
addRows($a_nr_rows, $a_nr_cols)
add rows to table
importHtml($lng, $htmlTable)
setTableAttribute($a_attr, $a_value)
Set attribute of table tag.
setHorizontalAlign($a_halign)
set horizontal align
foreach($_POST as $key=> $value) $res
importRow($lng, &$node)
setTemplate($a_template)
Set template.
setCellSpacing($a_spacing)
set table cell spacing
$lng
setNode($a_node)
setFirstRowStyle($a_class)
Set first row td style.
setWidth($a_width)
set table width
getHorizontalAlign()
get table cell padding
setTDAlignment($a_hier_id, $a_class, $a_pc_id="")
set alignment of table data cell
getFooterCols()
Get footer cols.
importSpreadsheet($a_lang, $a_data)
import from table
$n
Definition: RandomTest.php:85
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
checkCellHidden($colspans, $rowspans, $x, $y)
Check hidden status.
getHeaderCols()
Get header cols.
const IL_INSERT_AFTER
getCellNode($i, $j, $create_if_not_exists=false)
Get cell paragraph node of row $i and cell $j.
getHierId()
Get hierarchical id.
setBorder($a_border)
set table border
makeEmptyCell($td_node)
Make cell empty.
getAllCellWidths()
Get all cell widhts.
getCellPadding()
get table cell padding
getCaptionAlign()
get caption alignment (Top | Bottom)
$rows
Definition: xhr_table.php:10
importTableAttributes(&$node)
getBorder()
get table border width
createPageContentNode($a_set_this_node=true)
Create page content node (always use this method first when adding a new element) ...
getAllCellSpans()
Get all cell spans.
setFooterRows($a_nr)
Set footer rows.
setCellPadding($a_padding)
set table cell padding
getAllCellAlignments()
Get all cell alignments.
const DOMXML_LOAD_PARSING
static setFirstOptionalElement( $doc, $parent_node, $a_node_name, $a_successors, $a_content, $a_attributes, $a_remove_childs=true)
searches for an element $a_node_name within the childs of $parent_node if no node is found...
getCellSpacing()
get table cell spacing
setFooterCols($a_nr)
Set footer cols.
getHeaderRows()
Get header rows.
getAllCellClasses()
Get all cell classes.
setClass($a_class)
Set Style Class of table.
$i
Definition: metadata.php:24
getLanguage()
get table language
setTDClass($a_hier_id, $a_class, $a_pc_id="")
set class of table data cell
fixHideAndSpans()
Fix Hide and Spans.