* accept( $visitor ); * echo (string) $visitor; // print the plot * ?> * * * @package Tree * @version //autogentag// */ class ezcTreeVisitorYUI implements ezcTreeVisitor { /** * Holds all the edges of the graph. * * @var array(string=>array(string)) */ protected $edges = array(); /** * Holds the root ID. * * @var string */ protected $root = null; /** * Holds the XML ID. * * @var string */ protected $xmlId; /** * Holds the XHTML class. * * @var string */ protected $class; /** * Whether the XML ID has been set. * * @var bool */ private $treeIdSet; /** * Holds the options for this class * * @var ezcTreeVisitorYUIOptions */ public $options; /** * Constructs a new ezcTreeVisitorYUI visualizer. * * @param string $xmlId * @param ezcTreeVisitorYUIOptions $options */ public function __construct( $xmlId, ezcTreeVisitorYUIOptions $options = null ) { if ( !is_string( $xmlId ) || strlen( $xmlId ) === 0 ) { throw new ezcBaseValueException( 'xmlId', $xmlId, 'non-empty string' ); } $this->xmlId = $xmlId; if ( $options === null ) { $this->options = new ezcTreeVisitorYUIOptions; } else { $this->options = $options; } } /** * Formats a node's data. * * 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. * * @param mixed $data * @param bool $highlight * @return string */ protected function formatData( $data, $highlight ) { $data = htmlspecialchars( $data ); return $data; } /** * Visits the node and sets the the member variables according to the node * type and contents. * * @param ezcTreeVisitable $visitable * @return bool */ public function visit( ezcTreeVisitable $visitable ) { if ( $visitable instanceof ezcTreeNode ) { if ( $this->root === null ) { $this->root = $visitable->id; } $parent = $visitable->fetchParent(); if ( $parent ) { $this->edges[$parent->id][] = array( $visitable->id, $visitable->data, $visitable->fetchPath() ); } } return true; } /** * 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 string $id * @param int $level * @param array(int=>bool) $levelLast * * @return string */ protected function doChildren( $id, $level = 0, $levelLast = array() ) { $text = ''; $children = $this->edges[$id]; $numChildren = count( $children ); if ( $numChildren > 0 ) { $text .= str_repeat( ' ', $level + 1 ); $idPart = ''; if ( $level !== 0 ) { $text .= "
\n"; } return $text; } /** * Returns the XHTML representation of a tree. * * @return string * @ignore */ public function __toString() { $tree = ''; $this->treeIdSet = false; $idPart = " id=\"{$this->xmlId}\""; $tree .= " END; } $tree .= "\n"; return $tree; } } ?>