.
*
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
*
*/
/**
* @package gulliver.system
*/
G::LoadSystem('objectTemplate');
class Tree extends Xml_Node {
var $template = 'tree.html';
var $nodeType = 'base';
var $nodeClass = 'treeNode';
var $contentClass = 'treeContent';
var $width = '100%';
var $contentWidth = '360';
var $contracted = false;
var $showSign = true;
var $isChild = false;
var $plus = " ";
var $minus = " ";
var $point = " ";
/**
* Tree
*
* @param array $xmlnode default value NULL
*
* @return none
*/
function Tree( $xmlnode = NULL )
{
if (!isset($xmlnode))
return;
if (isset($xmlnode->attributes['nodeType']))
$this->nodeType=$xmlnode->attributes['nodeType'];
foreach($xmlnode as $key => $value) {
if ($key==='children') {
foreach( $xmlnode->children as $key => $value ) {
$this->children[ $key ] = new Tree( $value->toTree());
}
} elseif ($key==='attributes') {
foreach( $xmlnode->attributes as $key => $value ) {
$this->{$key} = $value;
}
}
else {
$this->{$key} = $value;
}
}
}
/**
* &addChild
*
* @param string $name
* @param string $label
* @param array $attributes
*
* @return object(Tree) $newNode
*/
function &addChild( $name, $label, $attributes = array() )
{
$newNode = new Tree(new Xml_Node($name, 'open', $label, $attributes));
$this->children[] =& $newNode;
return $newNode;
}
/**
* printPlus
*
* @return string '...'
*/
function printPlus()
{
$plus = 'none';
$minus = 'none';
$point = 'none';
if ($this->showSign) {
if ((sizeof($this->children)>0) && ($this->contracted)) {
$plus = '';
} elseif ((sizeof($this->children)>0) && (!$this->contracted)) {
$minus = '';
} else {
$point = '';
}
}
return "{$this->plus}".
"{$this->minus}".
"{$this->point}";
}
/**
* printLabel
*
* @return $this->value
*/
function printLabel()
{
return $this->value;
}
/**
* printContent
*
* @return string $html
*/
function printContent()
{
$html = '';
$row = 0;
foreach($this->children as $child) {
if ($row)
$child->nodeClass = 'treeNodeAlternate';
$html .= $child->render();
$row = ($row + 1) % 2;
}
return $html;
}
/**
* render
* @return $obj->printObject( array( 'node' => &$this ) )
*/
function render() {
$obj = new objectTemplate( $this->template );
return $obj->printObject( array( 'node' => &$this ) );
}
}