Apache Zeta Components Manual :: File Source for yui.php
Source for file yui.php
Documentation is available at yui.php
* File containing the ezcTreeVisitorYUI 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, as YUI wants.
* See {@link http://developer.yahoo.com/yui/menu}.
* $visitor = new ezcTreeVisitorYUI( 'menu' );
* $tree->accept( $visitor );
* echo (string) $visitor; // print the plot
* @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 ezcTreeVisitorYUIOptions
* Constructs a new ezcTreeVisitorYUI visualizer.
* @param ezcTreeVisitorYUIOptions $options
public function __construct( $xmlId, ezcTreeVisitorYUIOptions $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 )
* Visits the node and sets the the member variables according to the node
* @param ezcTreeVisitable $visitable
public function visit( ezcTreeVisitable $visitable )
if ( $this->root ===
null )
$this->root =
$visitable->id;
$parent =
$visitable->fetchParent();
$this->edges[$parent->id][] =
array( $visitable->id, $visitable->data, $visitable->fetchPath() );
* 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 );
$text .=
"<div id='{$id}' class='yuimenu'>\n";
$text .=
"<div class='bd'>\n";
foreach ( $children as $child )
$path =
$child[2]->nodes;
if ( !$this->options->displayRootNode )
if ( $this->options->selectedNodeLink )
$yuiItemClass =
$level ==
0 ?
'yuimenubaritem' :
'yuimenuitem';
$yuiItemLabelClass =
$level ==
0 ?
'yuimenubaritemlabel' :
'yuimenuitemlabel';
$highlightPart =
' highlight';
$linkStart =
"<a class='{$yuiItemLabelClass}{$highlightPart}' href='{$path}'>";
if ( isset
( $this->edges[$child[0]] ) )
$text .=
"<li class='{$yuiItemClass}'>{$linkStart}{$data}{$linkEnd}\n";
$text .=
$this->doChildren( $child[0], $level +
4, $levelLast );
$text .=
"<li class='{$yuiItemClass}'>{$linkStart}{$data}{$linkEnd}</li>\n";
* Returns the XHTML representation of a tree.
public function __toString()
$this->treeIdSet =
false;
$idPart =
" id=\"{$this->xmlId}\"
";
$tree .= "<div{
$idPart} class='yuimenubar yuimenubarnav'>\n
";
if ( $this->options->displayRootNode )
<li class='yuimenubaritem'><a class='yuimenubaritemlabel' href='/Hominoidea/Hylobatidae'>{
$this->root}</a>
if ( $this->options->displayRootNode )