ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 150 of file class.ilDOMUtil.php.

References $a_content, and set_attributes().

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

152  {
153  $search = $a_successors;
154 
155  $childs = $parent_node->child_nodes();
156  $cnt_childs = count($childs);
157  $found = false;
158  foreach($childs as $child)
159  {
160  $child_name = $child->node_name();
161  if (in_array($child_name, $search))
162  {
163  $found = true;
164  break;
165  }
166  }
167  // didn't successors -> append at the end
168  if(!$found)
169  {
170  $new_node = $doc->create_element($a_node_name);
171  $new_node = $parent_node->append_child($new_node);
172  if ($a_content != "")
173  {
174  $new_node->set_content($a_content);
175  }
176  ilDOMUtil::set_attributes($new_node, $a_attributes);
177  }
178  else
179  {
180  $new_node = $doc->create_element($a_node_name);
181  $new_node = $child->insert_before($new_node, $child);
182  if ($a_content != "")
183  {
184  $new_node->set_content($a_content);
185  }
186  ilDOMUtil::set_attributes($new_node, $a_attributes);
187  }
188 
189  return $new_node;
190  }
static set_attributes($a_node, $a_attributes)
set attributes of a node
$a_content
Definition: workflow.php:94
+ 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 132 of file class.ilDOMUtil.php.

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

133  {
134  $childs = $a_parent->child_nodes();
135  foreach($childs as $child)
136  {
137  $child_name = $child->node_name();
138  if (in_array($child_name, $a_node_names))
139  {
140  $child->unlink_node();
141  }
142  }
143  }
+ 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 111 of file class.ilDOMUtil.php.

Referenced by addElementToList(), and setFirstOptionalElement().

112  {
113  foreach ($a_attributes as $attribute => $value)
114  {
115  if ($value != "")
116  {
117  $a_node->set_attribute($attribute, $value);
118  }
119  else
120  {
121  if ($a_node->has_attribute($attribute))
122  {
123  $a_node->remove_attribute($attribute);
124  }
125  }
126  }
127  }
+ 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, 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().

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