ILIAS  release_8 Revision v8.23
ilDOMUtil Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilDOMUtil:

Static Public Member Functions

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, a new is created before the childs with names of $a_successors. More...
 
static set_attributes (php4DOMElement $a_node, array $a_attributes)
 set attributes of a node More...
 
static deleteAllChildsByName (php4DOMElement $a_parent, array $a_node_names)
 delete all childs of a node by names in $a_node_names More...
 
static addElementToList (php4DOMDocument $doc, php4DOMElement $parent_node, string $a_node_name, array $a_successors, string $a_content, array $a_attributes)
 Places a new node $a_node_name directly before nodes with names of $a_successors. More...
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning class for DOM utilities

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 24 of file class.ilDOMUtil.php.

Member Function Documentation

◆ addElementToList()

static ilDOMUtil::addElementToList ( php4DOMDocument  $doc,
php4DOMElement  $parent_node,
string  $a_node_name,
array  $a_successors,
string  $a_content,
array  $a_attributes 
)
static

Places a new node $a_node_name directly before nodes with names of $a_successors.

The content of the node is set to $a_content and the attributes to $a_attributes

Definition at line 128 of file class.ilDOMUtil.php.

References php4DOMNode\append_child(), php4DOMNode\child_nodes(), php4DOMDocument\create_element(), and set_attributes().

Referenced by ilMediaAliasItem\addMapArea(), ilPCInteractiveImage\addTriggerArea(), ilPCInteractiveImage\addTriggerMarker(), and ilMediaAliasItem\setParameters().

135  : php4DOMElement {
136  $search = $a_successors;
137  $child = null;
138  $childs = $parent_node->child_nodes();
139  $cnt_childs = count($childs);
140  $found = false;
141  foreach ($childs as $child) {
142  $child_name = $child->node_name();
143  if (in_array($child_name, $search)) {
144  $found = true;
145  break;
146  }
147  }
148  // didn't successors -> append at the end
149  $new_node = $doc->create_element($a_node_name);
150  if (!$found) {
151  $new_node = $parent_node->append_child($new_node);
152  } else {
153  $new_node = $child->insert_before($new_node, $child);
154  }
155  if ($a_content != "") {
156  $new_node->set_content($a_content);
157  }
158  ilDOMUtil::set_attributes($new_node, $a_attributes);
159 
160  return $new_node;
161  }
create_element(string $name)
append_child($newnode)
php4DomElement
static set_attributes(php4DOMElement $a_node, array $a_attributes)
set attributes of a node
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteAllChildsByName()

static ilDOMUtil::deleteAllChildsByName ( php4DOMElement  $a_parent,
array  $a_node_names 
)
static

delete all childs of a node by names in $a_node_names

Definition at line 110 of file class.ilDOMUtil.php.

References php4DOMNode\child_nodes().

Referenced by ilPCTabs\saveCaptions(), ilMediaAliasItem\setAreaExtLink(), ilMediaAliasItem\setAreaIntLink(), ilPCTable\setCaption(), and ilPCSection\setNoLink().

113  : void {
114  $childs = $a_parent->child_nodes();
115  foreach ($childs as $child) {
116  $child_name = $child->node_name();
117  if (in_array($child_name, $a_node_names)) {
118  $child->unlink_node();
119  }
120  }
121  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_attributes()

static ilDOMUtil::set_attributes ( php4DOMElement  $a_node,
array  $a_attributes 
)
static

set attributes of a node

Parameters
array$a_attributesattributes array (attribute_name => attribute_value pairs)

Definition at line 92 of file class.ilDOMUtil.php.

References php4DOMElement\has_attribute(), php4DOMElement\remove_attribute(), and php4DOMElement\set_attribute().

Referenced by addElementToList(), and setFirstOptionalElement().

95  : void {
96  foreach ($a_attributes as $attribute => $value) {
97  if ($value != "") {
98  $a_node->set_attribute($attribute, $value);
99  } else {
100  if ($a_node->has_attribute($attribute)) {
101  $a_node->remove_attribute($attribute);
102  }
103  }
104  }
105  }
set_attribute($name, $value)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFirstOptionalElement()

static ilDOMUtil::setFirstOptionalElement ( php4DOMDocument  $doc,
php4DOMElement  $parent_node,
string  $a_node_name,
array  $a_successors,
string  $a_content,
array  $a_attributes,
bool  $a_remove_childs = true 
)
static

searches for an element $a_node_name within the childs of $parent_node if no node is found, a new is created before the childs with names of $a_successors.

the content of the node is set to $a_content and the attributes to $a_attributes

Definition at line 32 of file class.ilDOMUtil.php.

References $i, php4DOMNode\append_child(), php4DOMNode\child_nodes(), php4DOMDocument\create_element(), and set_attributes().

Referenced by ilMediaAliasItem\addMapArea(), ilPCTabs\addTab(), ilPCTabs\saveCaptions(), ilMediaAliasItem\setAreaExtLink(), ilMediaAliasItem\setAreaIntLink(), ilPCMap\setCaption(), ilMediaAliasItem\setCaption(), ilPCTable\setCaption(), ilPCSection\setExtLink(), ilMediaAliasItem\setHeight(), ilMediaAliasItem\setHorizontalAlign(), ilPCSection\setIntLink(), ilPCMap\setLayout(), ilPCFileList\setListTitle(), ilMediaAliasItem\setTextRepresentation(), and ilMediaAliasItem\setWidth().

40  : void {
41  $search = $a_successors;
42  $search[] = $a_node_name;
43  $child_name = "";
44  $child = null;
45 
46  $childs = $parent_node->child_nodes();
47  $found = false;
48  foreach ($childs as $child) {
49  $child_name = $child->node_name();
50  //echo "B$child_name";
51  if (in_array($child_name, $search)) {
52  //echo "C";
53  $found = true;
54  break;
55  }
56  }
57  // didn't find element
58  if (!$found) {
59  $new_node = $doc->create_element($a_node_name);
60  $new_node = $parent_node->append_child($new_node);
61  if ($a_content != "") {
62  $new_node->set_content($a_content);
63  }
64  ilDOMUtil::set_attributes($new_node, $a_attributes);
65  } else {
66  if ($child_name == $a_node_name) {
67  if ($a_remove_childs) {
68  $childs2 = $child->child_nodes();
69  for ($i = 0; $i < count($childs2); $i++) {
70  $child->remove_child($childs2[$i]);
71  }
72  }
73  if ($a_content != "") {
74  $child->set_content($a_content);
75  }
76  ilDOMUtil::set_attributes($child, $a_attributes);
77  } else {
78  $new_node = $doc->create_element($a_node_name);
79  $new_node = $child->insert_before($new_node, $child);
80  if ($a_content != "") {
81  $new_node->set_content($a_content);
82  }
83  ilDOMUtil::set_attributes($new_node, $a_attributes);
84  }
85  }
86  }
create_element(string $name)
append_child($newnode)
$i
Definition: metadata.php:41
static set_attributes(php4DOMElement $a_node, array $a_attributes)
set attributes of a node
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: