Apache Zeta Components Manual :: File Source for xhtml.php
Source for file xhtml.php
Documentation is available at xhtml.php
* File containing the ezcTreeVisitorXHTML class.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @version //autogentag//
* An implementation of the ezcTreeVisitor interface that generates
* an XHTML representatation of a tree structure.
* $options = new ezcTreeVisitorXHTMLOptions;
* $options->xmlId = 'menu_tree';
* $visitor = new ezcTreeVisitorXHTML( $options );
* $tree->accept( $visitor );
* echo (string) $visitor; // print the plot
* Shows (something like):
* @version //autogentag//
* Holds all the edges of the graph.
* @var array(string=>array(string))
* Whether the XML ID has been set.
* Holds the options for this class
* @var ezcTreeVisitorXHTMLOptions
* Constructs a new ezcTreeVisitorXHTML visualizer.
* @param ezcTreeVisitorXHTMLOptions $options
public function __construct( ezcTreeVisitorXHTMLOptions $options =
null )
* It is just a simple method, that provide an easy way to change the way
* on how data is formatted when this class is extended. The data is passed
* in the $data argument, and whether the node should be highlighted is
* passed in the $highlight argument.
protected function formatData( $data, $highlight )
return $highlight ?
"<div class=\"highlight\">$data</div>" :
$data;
* Visits the node and sets the the member variables according to the node
* @param ezcTreeVisitable $visitable
public function visit( ezcTreeVisitable $visitable )
if ( $visitable instanceof
ezcTree )
if ( $this->root ===
null )
$this->root =
$visitable->id;
$parent =
$visitable->fetchParent();
$this->edges[$parent->id][] =
array( $visitable->id, $visitable->data, $visitable->fetchPath() );
* Formats the path to the node
$path =
$child[2]->nodes;
if ( !$this->options->displayRootNode )
if ( $this->options->selectedNodeLink )
* Loops over the children of the node with ID $id.
* This methods loops over all the node's children and adds the correct
* layout for each node depending on the state that is collected in the
* $level and $levelLast variables.
* @param array(int=>bool) $levelLast
protected function doChildren( $id, $level =
0, $levelLast =
array() )
$children =
$this->edges[$id];
$numChildren =
count( $children );
$idPart =
$this->options->xmlId ?
" id=\"{$this->options->xmlId}\"
" : '';
$text .= "<ul{
$idPart}>\n
";
foreach ( $children as $child )
$text .= str_repeat( ' ', $level + 2 );
$data =
$this->formatData( $child[1], in_array( $child[0], $this->options->highlightNodeIds ) );
$linkStart =
$linkEnd =
'';
$linkStart = "<a href=\"{
$path}\">
";
if ( in_array( $child[0], $this->options->subtreeHighlightNodeIds ) )
$highlightPart = ' class="highlight"';
if ( isset( $this->edges[$child[0]] ) )
$text .= "<li{
$highlightPart}>{
$linkStart}{
$data}{
$linkEnd}\n
";
$text .= $this->doChildren( $child[0], $level +
2, $levelLast );
$text .=
str_repeat( ' ', $level +
2 );
$text .= "<li{
$highlightPart}>{
$linkStart}{
$data}{
$linkEnd}</li>\n
";
$text .= str_repeat( ' ', $level + 1 );
* Returns the XHTML representation of a tree.
public function __toString()
$this->treeIdSet =
false;
if ( $this->options->displayRootNode )
$idPart = $this->options->xmlId ?
" id=\"{
$this->options->xmlId}\"
" : '';
$tree .= "<ul{
$idPart}>\n
";
$tree .= "<li>{
$this->root}</li>\n
";
if ( $this->options->displayRootNode )