ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilDOMUtil Class Reference

class for DOM utilities More...

+ Collaboration diagram for ilDOMUtil:

Static Public Member Functions

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

Detailed Description

class for DOM utilities

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

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

Member Function Documentation

◆ addElementToList()

static ilDOMUtil::addElementToList (   $doc,
  $parent_node,
  $a_node_name,
  $a_successors,
  $a_content,
  $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 136 of file class.ilDOMUtil.php.

References $a_content, and set_attributes().

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

143  {
144  $search = $a_successors;
145 
146  $childs = $parent_node->child_nodes();
147  $cnt_childs = count($childs);
148  $found = false;
149  foreach ($childs as $child) {
150  $child_name = $child->node_name();
151  if (in_array($child_name, $search)) {
152  $found = true;
153  break;
154  }
155  }
156  // didn't successors -> append at the end
157  if (!$found) {
158  $new_node = $doc->create_element($a_node_name);
159  $new_node = $parent_node->append_child($new_node);
160  if ($a_content != "") {
161  $new_node->set_content($a_content);
162  }
163  ilDOMUtil::set_attributes($new_node, $a_attributes);
164  } else {
165  $new_node = $doc->create_element($a_node_name);
166  $new_node = $child->insert_before($new_node, $child);
167  if ($a_content != "") {
168  $new_node->set_content($a_content);
169  }
170  ilDOMUtil::set_attributes($new_node, $a_attributes);
171  }
172 
173  return $new_node;
174  }
static set_attributes($a_node, $a_attributes)
set attributes of a node
$a_content
Definition: workflow.php:93
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteAllChildsByName()

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

delete all childs of a node by names in $a_node_names

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

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

121  {
122  $childs = $a_parent->child_nodes();
123  foreach ($childs as $child) {
124  $child_name = $child->node_name();
125  if (in_array($child_name, $a_node_names)) {
126  $child->unlink_node();
127  }
128  }
129  }
+ Here is the caller graph for this function:

◆ set_attributes()

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

set attributes of a node

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

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

Referenced by addElementToList(), and setFirstOptionalElement().

105  {
106  foreach ($a_attributes as $attribute => $value) {
107  if ($value != "") {
108  $a_node->set_attribute($attribute, $value);
109  } else {
110  if ($a_node->has_attribute($attribute)) {
111  $a_node->remove_attribute($attribute);
112  }
113  }
114  }
115  }
+ Here is the caller graph for this function:

◆ setFirstOptionalElement()

static ilDOMUtil::setFirstOptionalElement (   $doc,
  $parent_node,
  $a_node_name,
  $a_successors,
  $a_content,
  $a_attributes,
  $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 42 of file class.ilDOMUtil.php.

References $a_content, $i, and set_attributes().

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

50  {
51  $search = $a_successors;
52  $search[] = $a_node_name;
53 
54  $childs = $parent_node->child_nodes();
55  $cnt_childs = count($childs);
56  $found = false;
57  //echo "A";
58  foreach ($childs as $child) {
59  $child_name = $child->node_name();
60  //echo "B$child_name";
61  if (in_array($child_name, $search)) {
62  //echo "C";
63  $found = true;
64  break;
65  }
66  }
67  // didn't find element
68  if (!$found) {
69  $new_node = &$doc->create_element($a_node_name);
70  $new_node = &$parent_node->append_child($new_node);
71  if ($a_content != "") {
72  $new_node->set_content($a_content);
73  }
74  ilDOMUtil::set_attributes($new_node, $a_attributes);
75  } else {
76  if ($child_name == $a_node_name) {
77  if ($a_remove_childs) {
78  $childs2 = $child->child_nodes();
79  for ($i = 0; $i < count($childs2); $i++) {
80  $child->remove_child($childs2[$i]);
81  }
82  }
83  if ($a_content != "") {
84  $child->set_content($a_content);
85  }
86  ilDOMUtil::set_attributes($child, $a_attributes);
87  } else {
88  $new_node = &$doc->create_element($a_node_name);
89  $new_node = &$child->insert_before($new_node, $child);
90  if ($a_content != "") {
91  $new_node->set_content($a_content);
92  }
93  ilDOMUtil::set_attributes($new_node, $a_attributes);
94  }
95  }
96  }
static set_attributes($a_node, $a_attributes)
set attributes of a node
$a_content
Definition: workflow.php:93
$i
Definition: disco.tpl.php:19
+ 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: