ILIAS  trunk Revision v11.0_alpha-2658-ge2404539063
class.ilPCDataTable.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
29 class ilPCDataTable extends ilPCTable
30 {
31  public function init(): void
32  {
33  $this->setType("dtab");
34  }
35 
36  public function create(
37  ilPageObject $a_pg_obj,
38  string $a_hier_id,
39  string $a_pc_id = ""
40  ): void {
42  $a_hier_id,
43  $a_pc_id,
44  "Table",
45  ["Language" => "", "DataTable" => "y"]
46  );
47  }
48 
49 
50  public function makeEmptyCell(DomNode $td_node): void
51  {
52  // delete children of paragraph node
53  $this->dom_util->deleteAllChilds($td_node);
54 
55  // create page content and paragraph node here.
56  $pc_node = $this->getNewPageContentNode();
57  $pc_node = $td_node->appendChild($pc_node);
58  $par_node = $this->dom_doc->createElement("Paragraph");
59  $par_node = $pc_node->appendChild($par_node);
60  $par_node->setAttribute("Characteristic", "TableContent");
61  $par_node->setAttribute(
62  "Language",
63  $this->getLanguage()
64  );
65  }
66 
67 
72  public function setData(array $a_data)
73  {
74  $error = "";
75  if (is_array($a_data)) {
76  foreach ($a_data as $i => $row) {
77  if (is_array($row)) {
78  foreach ($row as $j => $cell) {
79  $temp_dom = $this->dom_util->docFromString(
80  '<?xml version="1.0" encoding="UTF-8"?><Paragraph>' . $cell . '</Paragraph>',
81  $error
82  );
83  $par_node = $this->getCellNode($i, $j, true);
84  // remove all childs
85  if (empty($error) && !is_null($par_node)) {
86  // delete children of paragraph node
87  $this->dom_util->deleteAllChilds($par_node);
88 
89  // copy new content children in paragraph node
90  $nodes = $this->dom_util->path(
91  $temp_dom,
92  "//Paragraph"
93  );
94 
95  if (count($nodes) == 1) {
96  $new_par_node = $nodes->item(0);
97  foreach ($new_par_node->childNodes as $c) {
98  $cloned_child = $c->cloneNode(true);
99  $cloned_child = $this->dom_doc->importNode($cloned_child, true);
100  $par_node->appendChild($cloned_child);
101  }
102  }
103  } else {
104  if (!empty($error)) {
105  return $error;
106  }
107  }
108  }
109  }
110  }
111  }
112  return true;
113  }
114 }
setType(string $a_type)
Set Type.
makeEmptyCell(DomNode $td_node)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
create(ilPageObject $a_pg_obj, string $a_hier_id, string $a_pc_id="")
getCellNode(int $i, int $j, bool $create_if_not_exists=false)
Get cell paragraph node of row $i and cell $j.
$c
Definition: deliver.php:25
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
setData(array $a_data)
Set data of cells.
Class ilPCDataTable.
createInitialChildNode(string $hier_id, string $pc_id, string $child, array $child_attributes=[])