* @param array $params Any additional parameters the constructor
* needs.
*
- * @return Horde_Tree The singleton instance.
+ * @return Horde_Tree_Base The singleton instance.
* @throws Horde_Tree_Exception
*/
public function getTree($name, $renderer, array $params = array())
*/
protected function _generateUrlTag($node_id)
{
- return Horde::link(Horde::selfUrl()->add(self::TOGGLE . $this->_instance, $node_id));
+ return Horde::link(Horde::selfUrl()->add(Horde_Tree::TOGGLE . $this->_instance, $node_id));
}
/**
<?php
/**
- * The Horde_Core_Tree_Javascript:: class extends the Horde_Core_Tree_Html
- * class to provide a javascript rendering of a tree.
+ * The Horde_Core_Tree_Javascript:: class provides javascript rendering of a
+ * tree.
*
* Copyright 2003-2010 The Horde Project (http://www.horde.org/)
*
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Marko Djukic <marko@oblo.com>
- * @author Michael Slusarz <slusarz@curecanti.org>
+ * @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @package Core
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
- * @author Michael Slusarz <slusarz@curecanti.org>
+ * @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @package Core
*/
protected function _generateUrlTag($node_id)
{
- return Horde::link(Horde::selfUrl()->add(self::TOGGLE . $this->_instance, $node_id));
+ return Horde::link(Horde::selfUrl()->add(Horde_Tree::TOGGLE . $this->_instance, $node_id));
}
}
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @author Marko Djukic <marko@oblo.com>
+ * @author Michael Slusarz <slusarz@curecanti.org>
* @category Horde
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @package Tree
*/
-class Horde_Tree implements Countable
+class Horde_Tree
{
/* Display extra columns. */
const EXTRA_LEFT = 0;
const TOGGLE = 'ht_toggle_';
/**
- * Allowed parameters for nodes.
- *
- * @var array
- */
- protected $_allowed = array();
-
- /**
- * The name of this instance.
- *
- * @var string
- */
- protected $_instance = null;
-
- /**
- * Hash with header information.
- *
- * @var array
- */
- protected $_header = array();
-
- /**
- * An array containing all the tree nodes.
- *
- * @var array
- */
- protected $_nodes = array();
-
- /**
- * The top-level nodes in the tree.
- *
- * @var array
- */
- protected $_root_nodes = array();
-
- /**
- * Keep count of how many extra columns there are on the left side
- * of the node.
- *
- * @var integer
- */
- protected $_colsLeft = 0;
-
- /**
- * Keep count of how many extra columns there are on the right side
- * of the node.
- *
- * @var integer
- */
- protected $_colsRight = 0;
-
- /**
- * Option values.
- *
- * @var array
- */
- protected $_options = array(
- 'lines' => true
- );
-
- /**
- * Stores the sorting criteria temporarily.
- *
- * @var string
- */
- protected $_sortCriteria;
-
- /**
- * Should the tree be rendered statically?
- *
- * @var boolean
- */
- protected $_static = false;
-
- /**
* Attempts to return a concrete instance.
*
* @param string $name The name of this tree instance.
throw new Horde_Tree_Exception(__CLASS__ . ' renderer not found: ' . $renderer);
}
- /**
- * Constructor.
- *
- * @param string $name The name of this tree instance.
- * @param array $params Additional parameters.
- * <pre>
- * session - (string) The name of the session array key to store data.
- * If this is an empty string, session storage will be disabled.
- * DEFAULT: No session storage
- * </pre>
- */
- public function __construct($name, array $params = array())
- {
- $this->_instance = $name;
- $this->setOption($params);
-
- if (!empty($this->_options['session']) &&
- !isset($_SESSION[$this->_options['session']][$this->_instance])) {
- $_SESSION[$this->_options['session']][$this->_instance] = array();
- }
- }
-
- /**
- * Provide a simpler renderer to fallback to.
- *
- * @return string The next best renderer.
- * @throws Horde_Tree_Exception
- */
- public function fallback()
- {
- throw new Horde_Tree_Exception('No fallback renderer found.');
- }
-
- /**
- * Returns the tree.
- *
- * @param boolean $static If true the tree nodes can't be expanded and
- * collapsed and the tree gets rendered expanded.
- *
- * @return string The HTML code of the rendered tree.
- */
- public function getTree($static = false)
- {
- return '';
- }
-
- /**
- * Renders the tree.
- *
- * @param boolean $static If true the tree nodes can't be expanded and
- * collapsed and the tree gets rendered expanded.
- */
- public function renderTree($static = false)
- {
- echo $this->getTree($static);
- }
-
- /**
- * Sets an option.
- *
- * @param mixed $option The option name -or- an array of option
- * name/value pairs. See constructor for available
- * options.
- * @param mixed $value The option's value.
- */
- public function setOption($options, $value = null)
- {
- if (!is_array($options)) {
- $options = array($options => $value);
- }
-
- foreach ($options as $option => $value) {
- $this->_options[$option] = $value;
- }
- }
-
- /**
- * Gets an option's value.
- *
- * @param string $option The name of the option to fetch.
- *
- * @return mixed The option's value.
- */
- public function getOption($option)
- {
- return isset($this->_options[$option])
- ? $this->_options[$option]
- : null;
- }
-
- /**
- * Adds a node to the node tree array.
- *
- * @param string $id The unique node id.
- * @param string $parent The parent's unique node id.
- * @param string $label The text label for the node.
- * @param string $indent Deprecated, this is calculated automatically
- * based on the parent node.
- * @param boolean $expanded Is this level expanded or not.
- * @param array $params Any other parameters to set (@see
- * self::addNodeParams() for full details).
- * @param array $extra_right Any other columns to display to the right of
- * the tree.
- * @param array $extra_left Any other columns to display to the left of
- * the tree.
- */
- public function addNode($id, $parent, $label, $indent = null,
- $expanded = true, $params = array(),
- $extra_right = array(), $extra_left = array())
- {
- $nodeid = $this->_nodeId($id);
-
- if (!empty($this->_options['session'])) {
- $sess = &$_SESSION[$this->_options['session']][$this->_instance];
- $toggle_id = Horde_Util::getFormData(self::TOGGLE . $this->_instance);
-
- if ($nodeid == $toggle_id) {
- /* We have a URL toggle request for this node. */
- $expanded = $sess['expanded'][$nodeid] = isset($sess['expanded'][$id])
- /* Use session state if it is set. */
- ? (!$sess['expanded'][$nodeid])
- /* Otherwise use what was passed through the function. */
- : (!$expanded);
- } elseif (isset($sess['expanded'][$nodeid])) {
- /* If we have a saved session state use it. */
- $expanded = $sess['expanded'][$nodeid];
- }
- }
-
- $this->_nodes[$nodeid]['label'] = $label;
- $this->_nodes[$nodeid]['expanded'] = $expanded;
-
- /* If any params included here add them now. */
- if (!empty($params)) {
- $this->addNodeParams($id, $params);
- }
-
- /* If any extra columns included here add them now. */
- if (!empty($extra_right)) {
- $this->addNodeExtra($id, self::EXTRA_RIGHT, $extra_right);
- }
- if (!empty($extra_left)) {
- $this->addNodeExtra($id, self::EXTRA_LEFT, $extra_left);
- }
-
- if (is_null($parent)) {
- if (!in_array($nodeid, $this->_root_nodes)) {
- $this->_root_nodes[] = $nodeid;
- }
- } else {
- $parent = $this->_nodeId($parent);
- if (empty($this->_nodes[$parent]['children'])) {
- $this->_nodes[$parent]['children'] = array();
- }
- if (!in_array($nodeid, $this->_nodes[$parent]['children'])) {
- $this->_nodes[$parent]['children'][] = $nodeid;
- }
- }
- }
-
- /**
- * Adds additional parameters to a node.
- *
- * @param string $id The unique node id.
- * @param array $params Parameters to set (key/value pairs).
- */
- public function addNodeParams($id, $params = array())
- {
- $id = $this->_nodeId($id);
-
- if (!is_array($params)) {
- $params = array($params);
- }
-
- foreach ($params as $p_id => $p_val) {
- // Set only allowed and non-null params.
- if (!is_null($p_val) && in_array($p_id, $this->_allowed)) {
- $this->_nodes[$id][$p_id] = is_object($p_val)
- ? strval($p_val)
- : $p_val;
- }
- }
- }
-
- /**
- * Adds extra columns to be displayed to the side of the node.
- *
- * @param mixed $id The unique node id.
- * @param integer $side Which side to place the extra columns on.
- * @param array $extra Extra columns to display.
- */
- public function addNodeExtra($id, $side, $extra)
- {
- $id = $this->_nodeId($id);
-
- if (!is_array($extra)) {
- $extra = array($extra);
- }
-
- $col_count = count($extra);
-
- switch ($side) {
- case self::EXTRA_LEFT:
- $this->_nodes[$id]['extra'][self::EXTRA_LEFT] = $extra;
- if ($col_count > $this->_colsLeft) {
- $this->_colsLeft = $col_count;
- }
- break;
-
- case self::EXTRA_RIGHT:
- $this->_nodes[$id]['extra'][self::EXTRA_RIGHT] = $extra;
- if ($col_count > $this->_colsRight) {
- $this->_colsRight = $col_count;
- }
- break;
- }
- }
-
- /**
- * Sorts the tree by the specified node property.
- *
- * @param string $criteria The node property to sort by.
- * @param integer $id Used internally for recursion.
- */
- public function sort($criteria, $id = -1)
- {
- if (!isset($this->_nodes[$id]['children'])) {
- return;
- }
-
- if ($criteria == 'key') {
- ksort($this->_nodes[$id]['children']);
- } else {
- $this->_sortCriteria = $criteria;
- usort($this->_nodes[$id]['children'], array($this, 'sortHelper'));
- }
-
- foreach ($this->_nodes[$id]['children'] as $child) {
- $this->sort($criteria, $child);
- }
- }
-
- /**
- * Helper method for sort() to compare two tree elements.
- */
- public function sortHelper($a, $b)
- {
- if (!isset($this->_nodes[$a][$this->_sortCriteria])) {
- return 1;
- }
-
- if (!isset($this->_nodes[$b][$this->_sortCriteria])) {
- return -1;
- }
-
- return strcoll($this->_nodes[$a][$this->_sortCriteria],
- $this->_nodes[$b][$this->_sortCriteria]);
- }
-
- /**
- * Returns whether the specified node is currently expanded.
- *
- * @param mixed $id The unique node id.
- *
- * @return boolean True if the specified node is expanded.
- */
- public function isExpanded($id)
- {
- $id = $this->_nodeId($id);
-
- return isset($this->_nodes[$id])
- ? $this->_nodes[$id]['expanded']
- : false;
- }
-
- /**
- * Adds column headers to the tree table.
- *
- * @param array $header An array containing hashes with header
- * information.
- */
- public function setHeader($header)
- {
- $this->_header = $header;
- }
-
- /**
- * Set the indent level for each node in the tree.
- *
- * @param array $nodes TODO
- * @param integer $indent TODO
- */
- protected function _buildIndents($nodes, $indent = 0)
- {
- foreach ($nodes as $id) {
- $this->_nodes[$id]['indent'] = $indent;
- if (!empty($this->_nodes[$id]['children'])) {
- $this->_buildIndents($this->_nodes[$id]['children'], $indent + 1);
- }
- }
- }
-
- /**
- * Check the current environment to see if we can render the tree.
- *
- * @return boolean Whether or not this backend will function.
- */
- public function isSupported()
- {
- return true;
- }
-
- /**
- * Returns the escaped node ID.
- *
- * @param string $id Node ID.
- *
- * @return string Escaped node ID.
- */
- protected function _nodeId($id)
- {
- return rawurlencode($id);
- }
-
- /* Countable methods. */
-
- public function count()
- {
- return count($this->_nodes);
- }
-
}
--- /dev/null
+<?php
+/**
+ * The Horde_Tree_Base:: class provides the abstract interface that all
+ * drivers must derive from.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @license http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @package Tree
+ */
+abstract class Horde_Tree_Base implements Countable
+{
+ /**
+ * Allowed parameters for nodes.
+ *
+ * @var array
+ */
+ protected $_allowed = array();
+
+ /**
+ * The name of this instance.
+ *
+ * @var string
+ */
+ protected $_instance = null;
+
+ /**
+ * Hash with header information.
+ *
+ * @var array
+ */
+ protected $_header = array();
+
+ /**
+ * An array containing all the tree nodes.
+ *
+ * @var array
+ */
+ protected $_nodes = array();
+
+ /**
+ * The top-level nodes in the tree.
+ *
+ * @var array
+ */
+ protected $_root_nodes = array();
+
+ /**
+ * Keep count of how many extra columns there are on the left side
+ * of the node.
+ *
+ * @var integer
+ */
+ protected $_colsLeft = 0;
+
+ /**
+ * Keep count of how many extra columns there are on the right side
+ * of the node.
+ *
+ * @var integer
+ */
+ protected $_colsRight = 0;
+
+ /**
+ * Option values.
+ *
+ * @var array
+ */
+ protected $_options = array(
+ 'lines' => true
+ );
+
+ /**
+ * Stores the sorting criteria temporarily.
+ *
+ * @var string
+ */
+ protected $_sortCriteria;
+
+ /**
+ * Should the tree be rendered statically?
+ *
+ * @var boolean
+ */
+ protected $_static = false;
+
+ /**
+ * Constructor.
+ *
+ * @param string $name The name of this tree instance.
+ * @param array $params Additional parameters.
+ * <pre>
+ * session - (string) The name of the session array key to store data.
+ * If this is an empty string, session storage will be disabled.
+ * DEFAULT: No session storage
+ * </pre>
+ */
+ public function __construct($name, array $params = array())
+ {
+ $this->_instance = $name;
+ $this->setOption($params);
+
+ if (!empty($this->_options['session']) &&
+ !isset($_SESSION[$this->_options['session']][$this->_instance])) {
+ $_SESSION[$this->_options['session']][$this->_instance] = array();
+ }
+ }
+
+ /**
+ * Provide a simpler renderer to fallback to.
+ *
+ * @return string The next best renderer.
+ * @throws Horde_Tree_Exception
+ */
+ public function fallback()
+ {
+ throw new Horde_Tree_Exception('No fallback renderer found.');
+ }
+
+ /**
+ * Returns the tree.
+ *
+ * @param boolean $static If true the tree nodes can't be expanded and
+ * collapsed and the tree gets rendered expanded.
+ *
+ * @return string The HTML code of the rendered tree.
+ */
+ abstract public function getTree($static = false);
+
+ /**
+ * Renders the tree.
+ *
+ * @param boolean $static If true the tree nodes can't be expanded and
+ * collapsed and the tree gets rendered expanded.
+ */
+ public function renderTree($static = false)
+ {
+ echo $this->getTree($static);
+ }
+
+ /**
+ * Sets an option.
+ *
+ * @param mixed $option The option name -or- an array of option
+ * name/value pairs. See constructor for available
+ * options.
+ * @param mixed $value The option's value.
+ */
+ public function setOption($options, $value = null)
+ {
+ if (!is_array($options)) {
+ $options = array($options => $value);
+ }
+
+ foreach ($options as $option => $value) {
+ $this->_options[$option] = $value;
+ }
+ }
+
+ /**
+ * Gets an option's value.
+ *
+ * @param string $option The name of the option to fetch.
+ *
+ * @return mixed The option's value.
+ */
+ public function getOption($option)
+ {
+ return isset($this->_options[$option])
+ ? $this->_options[$option]
+ : null;
+ }
+
+ /**
+ * Adds a node to the node tree array.
+ *
+ * @param string $id The unique node id.
+ * @param string $parent The parent's unique node id.
+ * @param string $label The text label for the node.
+ * @param string $indent Deprecated, this is calculated automatically
+ * based on the parent node.
+ * @param boolean $expanded Is this level expanded or not.
+ * @param array $params Any other parameters to set (@see
+ * self::addNodeParams() for full details).
+ * @param array $extra_right Any other columns to display to the right of
+ * the tree.
+ * @param array $extra_left Any other columns to display to the left of
+ * the tree.
+ */
+ public function addNode($id, $parent, $label, $indent = null,
+ $expanded = true, $params = array(),
+ $extra_right = array(), $extra_left = array())
+ {
+ $nodeid = $this->_nodeId($id);
+
+ if (!empty($this->_options['session'])) {
+ $sess = &$_SESSION[$this->_options['session']][$this->_instance];
+ $toggle_id = Horde_Util::getFormData(Horde_Tree::TOGGLE . $this->_instance);
+
+ if ($nodeid == $toggle_id) {
+ /* We have a URL toggle request for this node. */
+ $expanded = $sess['expanded'][$nodeid] = isset($sess['expanded'][$id])
+ /* Use session state if it is set. */
+ ? (!$sess['expanded'][$nodeid])
+ /* Otherwise use what was passed through the function. */
+ : (!$expanded);
+ } elseif (isset($sess['expanded'][$nodeid])) {
+ /* If we have a saved session state use it. */
+ $expanded = $sess['expanded'][$nodeid];
+ }
+ }
+
+ $this->_nodes[$nodeid]['label'] = $label;
+ $this->_nodes[$nodeid]['expanded'] = $expanded;
+
+ /* If any params included here add them now. */
+ if (!empty($params)) {
+ $this->addNodeParams($id, $params);
+ }
+
+ /* If any extra columns included here add them now. */
+ if (!empty($extra_right)) {
+ $this->addNodeExtra($id, Horde_Tree::EXTRA_RIGHT, $extra_right);
+ }
+ if (!empty($extra_left)) {
+ $this->addNodeExtra($id, Horde_Tree::EXTRA_LEFT, $extra_left);
+ }
+
+ if (is_null($parent)) {
+ if (!in_array($nodeid, $this->_root_nodes)) {
+ $this->_root_nodes[] = $nodeid;
+ }
+ } else {
+ $parent = $this->_nodeId($parent);
+ if (empty($this->_nodes[$parent]['children'])) {
+ $this->_nodes[$parent]['children'] = array();
+ }
+ if (!in_array($nodeid, $this->_nodes[$parent]['children'])) {
+ $this->_nodes[$parent]['children'][] = $nodeid;
+ }
+ }
+ }
+
+ /**
+ * Adds additional parameters to a node.
+ *
+ * @param string $id The unique node id.
+ * @param array $params Parameters to set (key/value pairs).
+ */
+ public function addNodeParams($id, $params = array())
+ {
+ $id = $this->_nodeId($id);
+
+ if (!is_array($params)) {
+ $params = array($params);
+ }
+
+ foreach ($params as $p_id => $p_val) {
+ // Set only allowed and non-null params.
+ if (!is_null($p_val) && in_array($p_id, $this->_allowed)) {
+ $this->_nodes[$id][$p_id] = is_object($p_val)
+ ? strval($p_val)
+ : $p_val;
+ }
+ }
+ }
+
+ /**
+ * Adds extra columns to be displayed to the side of the node.
+ *
+ * @param mixed $id The unique node id.
+ * @param integer $side Which side to place the extra columns on.
+ * @param array $extra Extra columns to display.
+ */
+ public function addNodeExtra($id, $side, $extra)
+ {
+ $id = $this->_nodeId($id);
+
+ if (!is_array($extra)) {
+ $extra = array($extra);
+ }
+
+ $col_count = count($extra);
+
+ switch ($side) {
+ case Horde_Tree::EXTRA_LEFT:
+ $this->_nodes[$id]['extra'][Horde_Tree::EXTRA_LEFT] = $extra;
+ if ($col_count > $this->_colsLeft) {
+ $this->_colsLeft = $col_count;
+ }
+ break;
+
+ case Horde_Tree::EXTRA_RIGHT:
+ $this->_nodes[$id]['extra'][Horde_Tree::EXTRA_RIGHT] = $extra;
+ if ($col_count > $this->_colsRight) {
+ $this->_colsRight = $col_count;
+ }
+ break;
+ }
+ }
+
+ /**
+ * Sorts the tree by the specified node property.
+ *
+ * @param string $criteria The node property to sort by.
+ * @param integer $id Used internally for recursion.
+ */
+ public function sort($criteria, $id = -1)
+ {
+ if (!isset($this->_nodes[$id]['children'])) {
+ return;
+ }
+
+ if ($criteria == 'key') {
+ ksort($this->_nodes[$id]['children']);
+ } else {
+ $this->_sortCriteria = $criteria;
+ usort($this->_nodes[$id]['children'], array($this, 'sortHelper'));
+ }
+
+ foreach ($this->_nodes[$id]['children'] as $child) {
+ $this->sort($criteria, $child);
+ }
+ }
+
+ /**
+ * Helper method for sort() to compare two tree elements.
+ */
+ public function sortHelper($a, $b)
+ {
+ if (!isset($this->_nodes[$a][$this->_sortCriteria])) {
+ return 1;
+ }
+
+ if (!isset($this->_nodes[$b][$this->_sortCriteria])) {
+ return -1;
+ }
+
+ return strcoll($this->_nodes[$a][$this->_sortCriteria],
+ $this->_nodes[$b][$this->_sortCriteria]);
+ }
+
+ /**
+ * Returns whether the specified node is currently expanded.
+ *
+ * @param mixed $id The unique node id.
+ *
+ * @return boolean True if the specified node is expanded.
+ */
+ public function isExpanded($id)
+ {
+ $id = $this->_nodeId($id);
+
+ return isset($this->_nodes[$id])
+ ? $this->_nodes[$id]['expanded']
+ : false;
+ }
+
+ /**
+ * Adds column headers to the tree table.
+ *
+ * @param array $header An array containing hashes with header
+ * information.
+ */
+ public function setHeader($header)
+ {
+ $this->_header = $header;
+ }
+
+ /**
+ * Set the indent level for each node in the tree.
+ *
+ * @param array $nodes TODO
+ * @param integer $indent TODO
+ */
+ protected function _buildIndents($nodes, $indent = 0)
+ {
+ foreach ($nodes as $id) {
+ $this->_nodes[$id]['indent'] = $indent;
+ if (!empty($this->_nodes[$id]['children'])) {
+ $this->_buildIndents($this->_nodes[$id]['children'], $indent + 1);
+ }
+ }
+ }
+
+ /**
+ * Check the current environment to see if we can render the tree.
+ *
+ * @return boolean Whether or not this backend will function.
+ */
+ public function isSupported()
+ {
+ return true;
+ }
+
+ /**
+ * Returns the escaped node ID.
+ *
+ * @param string $id Node ID.
+ *
+ * @return string Escaped node ID.
+ */
+ protected function _nodeId($id)
+ {
+ return rawurlencode($id);
+ }
+
+ /* Countable methods. */
+
+ public function count()
+ {
+ return count($this->_nodes);
+ }
+
+}
<?php
/**
- * The Horde_Tree_Html:: class extends the Horde_Tree class to provide
- * HTML specific rendering functions.
+ * The Horde_Tree_Html:: class provides HTML specific rendering functions.
*
* Copyright 2003-2010 The Horde Project (http://www.horde.org/)
*
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @package Tree
*/
-class Horde_Tree_Html extends Horde_Tree
+class Horde_Tree_Html extends Horde_Tree_Base
{
/**
- * Node list.
- *
- * @var array
- */
- protected $_nodes = array();
-
- /**
* Node position list.
*
* @var array
* for any given cell of content. */
$column = 0;
- if (isset($node['extra'][self::EXTRA_LEFT])) {
- $extra = $node['extra'][self::EXTRA_LEFT];
+ if (isset($node['extra'][Horde_Tree::EXTRA_LEFT])) {
+ $extra = $node['extra'][Horde_Tree::EXTRA_LEFT];
$cMax = count($extra);
while ($column < $cMax) {
$line .= $this->_addColumn($column) . $extra[$column] . '</span>';
$line .= '</span>';
- if (isset($node['extra'][self::EXTRA_RIGHT])) {
- $extra = $node['extra'][self::EXTRA_RIGHT];
+ if (isset($node['extra'][Horde_Tree::EXTRA_RIGHT])) {
+ $extra = $node['extra'][Horde_Tree::EXTRA_RIGHT];
$cMax = count($extra);
for ($c = 0, $cMax = count($extra); $c < $cMax; ++$c) {
$line .= $this->_addColumn($column++) . $extra[$c] . '</span>';
protected function _generateUrlTag($node_id)
{
$url = new Horde_Url($_SERVER['PHP_SELF']);
- return $url->add(self::TOGGLE . $this->_instance, $node_id)->link();
+ return $url->add(Horde_Tree::TOGGLE . $this->_instance, $node_id)->link();
}
/**
<?php
/**
- * The Horde_Tree_Select:: class extends the Horde_Tree class to provide
- * <option> tag rendering.
+ * The Horde_Tree_Select:: class provides <option> tag rendering.
*
* Copyright 2005-2010 The Horde Project (http://www.horde.org/)
*
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @package Tree
*/
-class Horde_Tree_Select extends Horde_Tree
+class Horde_Tree_Select extends Horde_Tree_Base
{
/**
* Allowed parameters for nodes.
/**
* Returns the tree.
*
+ * @param boolean $static If true the tree nodes can't be expanded and
+ * collapsed and the tree gets rendered expanded.
+ * This option has no effect in this driver.
+ *
* @return string The HTML code of the rendered tree.
*/
- public function getTree()
+ public function getTree($static = false)
{
$this->_buildIndents($this->_root_nodes);
<?php
/**
- * The Horde_Tree_Simplehtml:: class extends the Horde_Tree class to provide
- * a simple HTML rendering of a tree (no graphics).
+ * The Horde_Tree_Simplehtml:: class provides simple HTML rendering of a tree
+ * (no graphics).
*
* Copyright 2010 The Horde Project (http://www.horde.org/)
*
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @package Tree
*/
-class Horde_Tree_Simplehtml extends Horde_Tree
+class Horde_Tree_Simplehtml extends Horde_Tree_Base
{
/**
* Allowed parameters for nodes.
$output = '<div' .
(empty($node['class']) ? '' : ' class="' . $node['class'] . '"') .
'>';
- if (isset($node['extra'][self::EXTRA_LEFT])) {
- $output .= implode(' ', $node['extra'][self::EXTRA_LEFT]);
+ if (isset($node['extra'][Horde_Tree::EXTRA_LEFT])) {
+ $output .= implode(' ', $node['extra'][Horde_Tree::EXTRA_LEFT]);
}
$output .= str_repeat(' ', $node['indent'] * 2);
$output .= empty($node['url'])
? $node['label']
: '<a href="' . strval($node['url']) . '">' . $node['label'] . '</a>';
- if (isset($node['extra'][self::EXTRA_RIGHT])) {
- $output .= implode(' ', $node['extra'][self::EXTRA_RIGHT]);
+ if (isset($node['extra'][Horde_Tree::EXTRA_RIGHT])) {
+ $output .= implode(' ', $node['extra'][Horde_Tree::EXTRA_RIGHT]);
}
$output .= '</div>';
protected function _generateUrlTag($node_id)
{
$url = new Horde_Url($_SERVER['PHP_SELF']);
- return $url->add(self::TOGGLE . $this->_instance, $node_id)->link();
+ return $url->add(Horde_Tree::TOGGLE . $this->_instance, $node_id)->link();
}
}
<api>beta</api>
</stability>
<license uri="http://www.gnu.org/copyleft/gpl.html">GPL</license>
- <notes>* Add simple HTML renderer.
+ <notes>* Split driver code from main class into Base class.
+ * Add simple HTML renderer.
* Remove dependency on horde/Core.
* Move javascript renderer to horde/Core.
* Add Horde_Tree_Exception::.
<dir name="lib">
<dir name="Horde">
<dir name="Tree">
+ <file name="Base.php" role="php" />
<file name="Exception.php" role="php" />
<file name="Html.php" role="php" />
<file name="Select.php" role="php" />
</dependencies>
<phprelease>
<filelist>
+ <install name="lib/Horde/Tree/Base.php" as="Horde/Tree/Base.php" />
<install name="lib/Horde/Tree/Exception.php" as="Horde/Tree/Exception.php" />
<install name="lib/Horde/Tree/Html.php" as="Horde/Tree/Html.php" />
<install name="lib/Horde/Tree/Select.php" as="Horde/Tree/Select.php" />
$this->recent = array();
$this->unseen = 0;
- if ($name instanceof Horde_Tree) {
+ if ($name instanceof Horde_Tree_Base) {
$tree = $name;
$indent = $opts['indent'];
$parent = $opts['parent'];
<?php
/**
- * The IMP_Tree_Flist class extends the Horde_Tree_Select class to provide
- * output of an IMP dropdown folder list.
+ * The IMP_Tree_Flist class provides an IMP dropdown folder list.
*
* Copyright 2010 The Horde Project (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
*
- * @author Michael Slusarz <slusarz@curecanti.org>
+ * @author Michael Slusarz <slusarz@horde.org>
* @category IMP
* @license http://www.fsf.org/copyleft/lgpl.html GPL
* @package Tree
/**
* Returns the tree.
*
+ * @param boolean $static If true the tree nodes can't be expanded and
+ * collapsed and the tree gets rendered expanded.
+ * This option has no effect in this driver.
+ *
* @return string The HTML code of the rendered tree.
*/
- public function getTree()
+ public function getTree($static = false)
{
global $conf, $injector, $registry;