2010-12-02 23:34:41 +00:00
|
|
|
<?php
|
2013-03-14 14:50:58 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
/**
|
2012-10-18 10:54:46 -04:00
|
|
|
*
|
|
|
|
|
* @package gulliver.system
|
2011-01-14 11:51:34 +00:00
|
|
|
*/
|
2017-08-21 10:39:10 -04:00
|
|
|
class PmTree extends Xml_Node
|
2012-10-18 10:54:46 -04:00
|
|
|
{
|
2013-03-14 14:50:58 -04:00
|
|
|
|
|
|
|
|
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);'> </span>";
|
|
|
|
|
public $minus = "<span style='position:absolute; width:16px;height:22px;cursor:pointer' onclick='tree.contract(this.parentNode);'> </span>";
|
|
|
|
|
public $point = "<span style='position:absolute; width:5px;height:10px;cursor:pointer;' onclick='tree.select(this.parentNode);'> </span>";
|
2010-12-02 23:34:41 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tree
|
|
|
|
|
*
|
2012-10-18 10:54:46 -04:00
|
|
|
* @param array $xmlnode default value NULL
|
2010-12-02 23:34:41 +00:00
|
|
|
*
|
2019-08-02 15:57:22 -04:00
|
|
|
* @return void
|
2012-10-18 10:54:46 -04:00
|
|
|
*/
|
2019-08-02 15:57:22 -04:00
|
|
|
public function __construct($xmlnode = null)
|
2010-12-02 23:34:41 +00:00
|
|
|
{
|
2013-03-14 14:50:58 -04:00
|
|
|
if (!isset($xmlnode)) {
|
2012-10-18 10:54:46 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2013-03-14 14:50:58 -04:00
|
|
|
if (isset($xmlnode->attributes['nodeType'])) {
|
2012-10-18 10:54:46 -04:00
|
|
|
$this->nodeType = $xmlnode->attributes['nodeType'];
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-18 10:54:46 -04:00
|
|
|
foreach ($xmlnode as $key => $value) {
|
|
|
|
|
if ($key === 'children') {
|
|
|
|
|
foreach ($xmlnode->children as $key => $value) {
|
2017-08-21 10:39:10 -04:00
|
|
|
$this->children[$key] = new PmTree($value->toTree());
|
2012-10-18 10:54:46 -04:00
|
|
|
}
|
|
|
|
|
} elseif ($key === 'attributes') {
|
|
|
|
|
foreach ($xmlnode->attributes as $key => $value) {
|
|
|
|
|
$this->{$key} = $value;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->{$key} = $value;
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-10-18 10:54:46 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
/**
|
|
|
|
|
* &addChild
|
|
|
|
|
*
|
2012-10-18 10:54:46 -04:00
|
|
|
* @param string $name
|
|
|
|
|
* @param string $label
|
|
|
|
|
* @param array $attributes
|
2010-12-02 23:34:41 +00:00
|
|
|
*
|
|
|
|
|
* @return object(Tree) $newNode
|
2012-10-18 10:54:46 -04:00
|
|
|
*/
|
2013-03-14 14:50:58 -04:00
|
|
|
public function &addChild($name, $label, $attributes = array())
|
2010-12-02 23:34:41 +00:00
|
|
|
{
|
2017-08-21 10:39:10 -04:00
|
|
|
$newNode = new PmTree(new Xml_Node($name, 'open', $label, $attributes));
|
2012-10-18 10:54:46 -04:00
|
|
|
$this->children[] = & $newNode;
|
|
|
|
|
return $newNode;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* printPlus
|
|
|
|
|
*
|
|
|
|
|
* @return string '<span>...</span>'
|
2012-10-18 10:54:46 -04:00
|
|
|
*/
|
2013-03-14 14:50:58 -04:00
|
|
|
public function printPlus()
|
2010-12-02 23:34:41 +00:00
|
|
|
{
|
2012-10-18 10:54:46 -04:00
|
|
|
$plus = 'none';
|
|
|
|
|
$minus = 'none';
|
|
|
|
|
$point = 'none';
|
|
|
|
|
if ($this->showSign) {
|
2013-03-14 14:50:58 -04:00
|
|
|
if ((sizeof($this->children) > 0) && ($this->contracted)) {
|
2012-10-18 10:54:46 -04:00
|
|
|
$plus = '';
|
2013-03-14 14:50:58 -04:00
|
|
|
} elseif ((sizeof($this->children) > 0) && (!$this->contracted)) {
|
2012-10-18 10:54:46 -04:00
|
|
|
$minus = '';
|
|
|
|
|
} else {
|
|
|
|
|
$point = '';
|
|
|
|
|
}
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-18 10:54:46 -04: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
|
|
|
}
|
2012-10-18 10:54:46 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
/**
|
|
|
|
|
* printLabel
|
|
|
|
|
*
|
|
|
|
|
* @return $this->value
|
2012-10-18 10:54:46 -04:00
|
|
|
*/
|
2013-03-14 14:50:58 -04:00
|
|
|
public function printLabel()
|
2010-12-02 23:34:41 +00:00
|
|
|
{
|
2012-10-18 10:54:46 -04:00
|
|
|
return $this->value;
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-18 10:54:46 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
/**
|
|
|
|
|
* printContent
|
|
|
|
|
*
|
|
|
|
|
* @return string $html
|
2012-10-18 10:54:46 -04:00
|
|
|
*/
|
2013-03-14 14:50:58 -04:00
|
|
|
public function printContent()
|
2010-12-02 23:34:41 +00:00
|
|
|
{
|
2012-10-18 10:54:46 -04: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
|
|
|
}
|
2012-10-18 10:54:46 -04:00
|
|
|
|
2010-12-02 23:34:41 +00:00
|
|
|
/**
|
|
|
|
|
* render
|
2012-10-18 10:54:46 -04:00
|
|
|
*
|
2010-12-02 23:34:41 +00:00
|
|
|
* @return $obj->printObject( array( 'node' => &$this ) )
|
2012-10-18 10:54:46 -04:00
|
|
|
*/
|
2013-03-14 14:50:58 -04:00
|
|
|
public function render()
|
2012-10-18 10:54:46 -04:00
|
|
|
{
|
2013-03-14 14:50:58 -04:00
|
|
|
$obj = new objectTemplate($this->template);
|
|
|
|
|
return $obj->printObject(array('node' => &$this));
|
2010-12-02 23:34:41 +00:00
|
|
|
}
|
2012-10-18 10:54:46 -04:00
|
|
|
}
|