Files
luos/gulliver/system/class.tree.php

131 lines
3.6 KiB
PHP
Raw Normal View History

2010-12-02 23:34:41 +00:00
<?php
2010-12-02 23:34:41 +00:00
/**
*
* @package gulliver.system
2011-01-14 11:51:34 +00:00
*/
class PmTree extends Xml_Node
{
public $template = 'tree.html';
public $nodeType = 'base';
public $nodeClass = 'treeNode';
public $contentClass = 'treeContent';
public $width = '100%';
public $contentWidth = '360';
public $contracted = false;
public $showSign = true;
public $isChild = false;
public $plus = "<span style='position:absolute; width:16px;height:22px;cursor:pointer;'onclick='tree.expand(this.parentNode);'>&nbsp;</span>";
public $minus = "<span style='position:absolute; width:16px;height:22px;cursor:pointer' onclick='tree.contract(this.parentNode);'>&nbsp;</span>";
public $point = "<span style='position:absolute; width:5px;height:10px;cursor:pointer;' onclick='tree.select(this.parentNode);'>&nbsp;</span>";
2010-12-02 23:34:41 +00:00
/**
* Tree
*
* @param array $xmlnode default value NULL
2010-12-02 23:34:41 +00:00
*
2019-08-02 15:57:22 -04:00
* @return void
*/
2019-08-02 15:57:22 -04:00
public function __construct($xmlnode = null)
2010-12-02 23:34:41 +00:00
{
if (!isset($xmlnode)) {
return;
}
if (isset($xmlnode->attributes['nodeType'])) {
$this->nodeType = $xmlnode->attributes['nodeType'];
2010-12-02 23:34:41 +00:00
}
foreach ($xmlnode as $key => $value) {
if ($key === 'children') {
foreach ($xmlnode->children as $key => $value) {
$this->children[$key] = new PmTree($value->toTree());
}
} elseif ($key === 'attributes') {
foreach ($xmlnode->attributes as $key => $value) {
$this->{$key} = $value;
}
} else {
$this->{$key} = $value;
}
2010-12-02 23:34:41 +00:00
}
}
2010-12-02 23:34:41 +00:00
/**
* &addChild
*
* @param string $name
* @param string $label
* @param array $attributes
2010-12-02 23:34:41 +00:00
*
* @return object(Tree) $newNode
*/
public function &addChild($name, $label, $attributes = array())
2010-12-02 23:34:41 +00:00
{
$newNode = new PmTree(new Xml_Node($name, 'open', $label, $attributes));
$this->children[] = & $newNode;
return $newNode;
2010-12-02 23:34:41 +00:00
}
/**
* printPlus
*
* @return string '<span>...</span>'
*/
public function printPlus()
2010-12-02 23:34:41 +00:00
{
$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 = '';
}
2010-12-02 23:34:41 +00:00
}
return "<span class='treePlus' name='plus' style='display:$plus;'>{$this->plus}</span>" . "<span class='treeMinus' name='minus' style='display:$minus'>{$this->minus}</span>" . "<span class='treePointer' name='point' style='display:$point'>{$this->point}</span>";
2010-12-02 23:34:41 +00:00
}
2010-12-02 23:34:41 +00:00
/**
* printLabel
*
* @return $this->value
*/
public function printLabel()
2010-12-02 23:34:41 +00:00
{
return $this->value;
2010-12-02 23:34:41 +00:00
}
2010-12-02 23:34:41 +00:00
/**
* printContent
*
* @return string $html
*/
public function printContent()
2010-12-02 23:34:41 +00:00
{
$html = '';
$row = 0;
foreach ($this->children as $child) {
if ($row) {
$child->nodeClass = 'treeNodeAlternate';
}
$html .= $child->render();
$row = ($row + 1) % 2;
}
return $html;
2010-12-02 23:34:41 +00:00
}
2010-12-02 23:34:41 +00:00
/**
* render
*
2010-12-02 23:34:41 +00:00
* @return $obj->printObject( array( 'node' => &$this ) )
*/
public function render()
{
$obj = new objectTemplate($this->template);
return $obj->printObject(array('node' => &$this));
2010-12-02 23:34:41 +00:00
}
}