Framework  3.9
TreeNode Class Reference

TreeNode represents a node in the tree. More...

Public Member Functions

 TreeNode ($id, $title, $value="", $checked=false, $closedStyle="tree_node_closed", $openStyle="tree_node_open", $link=null, $target="")
 Create a new TreeNode. More...
 
 writeHTML ()
 Write the node out as HTML to the output buffer. More...
 
 add ($n)
 Add a child TreeNode (or an array of children) More...
 
 calculateOpenState ()
 Recursively determine whether the branch of the tree of which this node is the root should be displayed as open, based on the selection state of the node and its children. More...
 
 selectByValue ($value)
 

Public Attributes

 $children = array()
 
 $id
 
 $title
 
 $value
 
 $checked
 
 $closedStyle
 
 $openStyle
 
 $leafStyle
 
 $open
 
 $link
 
 $onDemand
 
 $disabled
 
 $target
 
 $extras
 Extra data/controls to be shown with this tree node. More...
 

Detailed Description

TreeNode represents a node in the tree.

Both leaf and branch nodes are represented using instances of this class. If a node is to be a branch, child TreeNodes can be added via the add() method.

Definition at line 61 of file tree.inc.

Member Function Documentation

◆ add()

TreeNode::add (   $n)

Add a child TreeNode (or an array of children)

Parameters
mixed$nthe child or children to add

Definition at line 251 of file tree.inc.

252  {
253  if (is_array($n))
254  {
255  for($i = 0; $i < count($n); ++$i)
256  {
257  $this->children[] = $n[$i];
258  }
259  }
260  else
261  {
262  $this->children[] = $n;
263  }
264  }

◆ calculateOpenState()

TreeNode::calculateOpenState ( )

Recursively determine whether the branch of the tree of which this node is the root should be displayed as open, based on the selection state of the node and its children.

Definition at line 271 of file tree.inc.

272  {
273  if ($this->open) return true;
274  if ($this->checked)
275  {
276  $this->open = true;
277  return true;
278  }
279 
280  $c = count($this->children);
281 
282  for($i = 0; $i < $c; ++$i)
283  {
284  if ($this->children[$i]->calculateOpenState())
285  {
286  $this->open = true;
287  return true;
288  }
289  }
290 
291  $this->open = false;
292  return false;
293  }
calculateOpenState()
Recursively determine whether the branch of the tree of which this node is the root should be display...
Definition: tree.inc:271

◆ selectByValue()

TreeNode::selectByValue (   $value)

Definition at line 295 of file tree.inc.

296  {
297  if ($value === '')
298  {
299  $this->checked = false;
300  }
301  else if ($this->value == $value)
302  {
303  $this->checked = true;
304  }
305 
306  $c = count($this->children);
307 
308  for($i = 0; $i < $c; ++$i)
309  {
310  $this->children[$i]->selectByValue($value);
311  }
312  }
$value
Definition: tree.inc:67

◆ TreeNode()

TreeNode::TreeNode (   $id,
  $title,
  $value = "",
  $checked = false,
  $closedStyle = "tree_node_closed",
  $openStyle = "tree_node_open",
  $link = null,
  $target = "" 
)

Create a new TreeNode.

Parameters
string$idthe ID for this node
string$titlethe Title text for this node
string$valuethe value for this node. If non-empty, a checkbox is generated when the node is displayed.
boolean$checkedflag indicating whether the node should display as selected
string$closedStyleCSS class to use when the node is closed.
string$openStyleCSS class to use when the node is open.
string$linkoptional hyperlink URL for the node.
string$targetoptional target to load the URL.

Definition at line 91 of file tree.inc.

92  {
93  $this->id = $id;
94  $this->title = $title;
95  $this->value = $value;
96  $this->checked = $checked;
97  $this->closedStyle = $closedStyle;
98  $this->openStyle = $openStyle;
99  $this->open = false;
100  $this->link = $link;
101  $this->leafStyle = "tree_node_leaf";
102  $this->onDemand = "";
103  $this->disabled = false;
104  $this->target = $target;
105  $this->extras = "";
106  }
$closedStyle
Definition: tree.inc:69
$link
Definition: tree.inc:73
$title
Definition: tree.inc:66
$openStyle
Definition: tree.inc:70
$target
Definition: tree.inc:76
$checked
Definition: tree.inc:68

◆ writeHTML()

TreeNode::writeHTML ( )

Write the node out as HTML to the output buffer.

This method recursively descends into all child nodes.

Definition at line 112 of file tree.inc.

113  {
114  global $_activeTree;
115 
116  $c = count($this->children);
117 
118  if ($this->link)
119  {
120  $title = "<a href='{$this->link}' target='{$this->target}'>{$this->title}</a>{$this->extras}";
121  }
122  else
123  {
124  $title = "<a href='#' onclick='";
125 
126  if ($_activeTree->onSelect)
127  {
128  $title .= "{$_activeTree->onSelect}(\"{$this->value}\");";
129  }
130  else if ($_activeTree->selectMode != 'navigation')
131  {
132  $title .= "new DOMEvent(event).stop(); Tree.toggleCheckbox(this, \"{$_activeTree->id}\", \"{$_activeTree->selectMode}\")";
133  }
134  $title .= "; return false'";
135 
136  if ($_activeTree->selectOnRightClick)
137  {
138  $title .= " oncontextmenu='Tree.selectCheckbox(this, \"{$_activeTree->id}\", \"{$_activeTree->selectOnRightClickMode}\");'";
139  }
140 
141  $title .= ">{$this->title}</a>{$this->extras}";
142  }
143 
144  if ($c == 0 && !$this->onDemand)
145  {
146  // Leaf node
147  echo "<div id='{$this->id}' class='{$this->leafStyle}'>";
148 
149  if (isset($this->value) && $this->value !== "" && $_activeTree->selectMode != 'navigation')
150  {
151 ?>
152  <input type="checkbox" class="checkbox" name="<? echo $this->id?>" value="<? echo $this->value?>"<?
153  if ($this->checked) echo " checked";
154  if ($this->disabled) echo " disabled";
155  if ($_activeTree->selectMode == "single")
156  {
157  echo " onclick=\"Tree.clearCheckBoxes('{$_activeTree->id}', this);";
158  if ($_activeTree->onSelect)
159  {
160  echo " {$_activeTree->onSelect}('{$this->value}');";
161  }
162  echo "\"";
163  }
164  else if ($_activeTree->onSelect)
165  {
166  echo " onclick=\"{$_activeTree->onSelect}('{$this->value}');\"";
167  }
168  ?>/>
169 <?
170  }
171 
172  echo "$title</div>";
173  }
174  else
175  {
176  if ($this->open)
177  {
178  $style = $this->openStyle;
179  $display = "block";
180  }
181  else
182  {
183  $style = $this->closedStyle;
184  $display = "none";
185  }
186 
187  if ($this->onDemand)
188  {
189  $cmd = "Tree.loadOnDemand('{$this->id}', '{$this->onDemand}');";
190 
191  if ($this->open)
192  {
193 ?>
194 <script type="text/javascript">
195  window.addEvent('domready', function() {Tree.loadOnDemand('<?echo $this->id?>', '<?echo $this->onDemand?>');});
196 </script>
197 <?
198  }
199  }
200  else
201  {
202  $cmd = "";
203  }
204 
205  $cmd .= "Tree.toggleFolder('{$this->id}', '{$this->openStyle}', '{$this->closedStyle}');";
206 ?>
207  <div id='<?echo $this->id?>' class='<?echo $style?>' onclick="<?echo $cmd ?>">
208 <?
209  if (isset($this->value) && $this->value !== "" && $_activeTree->selectMode != 'navigation')
210  {
211 ?>
212  <input type="checkbox" class="checkbox" name="<? echo $this->id?>" value="<? echo $this->value?>" <?
213  if ($this->checked) echo " checked";
214  if ($this->disabled) echo " disabled";
215  if ($_activeTree->selectMode == "single")
216  {
217  echo " onclick=\"Tree.clearCheckBoxes('{$_activeTree->id}', this);";
218  if ($_activeTree->onSelect)
219  {
220  echo " {$_activeTree->onSelect}('{$this->value}');";
221  }
222  echo "\"";
223  }
224  else if ($_activeTree->onSelect)
225  {
226  echo " onclick=\"{$_activeTree->onSelect}('{$this->value}');\"";
227  }
228  ?>/>
229 <?
230  }
231 ?>
232  <?echo $title?></div>
233  <div id='<?echo $this->id?>_contents' style='padding-left: <?echo $_activeTree->indent ?>; display: <? echo $display?>'>
234 
235 <?
236  for($i = 0; $i < $c; ++$i)
237  {
238  $this->children[$i]->writeHTML();
239  }
240 ?>
241  </div>
242 <?
243  }
244  }
$_activeTree
Global reference to currently drawing tree instance.
Definition: tree.inc:53

Member Data Documentation

◆ $checked

TreeNode::$checked

Definition at line 68 of file tree.inc.

◆ $children

TreeNode::$children = array()

Definition at line 63 of file tree.inc.

◆ $closedStyle

TreeNode::$closedStyle

Definition at line 69 of file tree.inc.

◆ $disabled

TreeNode::$disabled

Definition at line 75 of file tree.inc.

◆ $extras

TreeNode::$extras

Extra data/controls to be shown with this tree node.

Definition at line 77 of file tree.inc.

◆ $id

TreeNode::$id

Definition at line 65 of file tree.inc.

◆ $leafStyle

TreeNode::$leafStyle

Definition at line 71 of file tree.inc.

◆ $link

TreeNode::$link

Definition at line 73 of file tree.inc.

◆ $onDemand

TreeNode::$onDemand

Definition at line 74 of file tree.inc.

◆ $open

TreeNode::$open

Definition at line 72 of file tree.inc.

◆ $openStyle

TreeNode::$openStyle

Definition at line 70 of file tree.inc.

◆ $target

TreeNode::$target

Definition at line 76 of file tree.inc.

◆ $title

TreeNode::$title

Definition at line 66 of file tree.inc.

◆ $value

TreeNode::$value

Definition at line 67 of file tree.inc.


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