--- ./old/Common.php 2003-07-03 19:45:39.000000000 +0200 +++ ./new/Common.php 2003-12-02 20:09:53.000000000 +0100 @@ -17,22 +17,27 @@ // +----------------------------------------------------------------------+ // // $Id: Common.php,v 1.31 2003/07/03 17:45:39 quipo Exp $ -require_once 'Tree/OptionsDB.php'; /** * common tree class, implements common functionality * - * this class extends Tree_OptionsDB so every class that extends this one can - * connect to a db and set options - * * @access public * @author Wolfram Kriesing * @version 2001/06/27 * @package Tree */ -class Tree_Common extends Tree_OptionsDB +class Tree_Common { /** + * @var array you need to overwrite this array and give the keys/ + * that are allowed + */ + //var $options = array(); + + var $_forceSetOption = false; + + + /** * put proper value-keys are given in each class, depending * on the implementation only some options are needed or allowed, * see the classes which extend this one @@ -592,7 +597,7 @@ // {{{ _getColName() /** - * this method retreives the real column name, as used in the DB + * this method retrieves the real column name, as used in the DB * since the internal names are fixed, to be portable between different * DB-column namings, we map the internal name to the real column name here * @@ -658,6 +663,176 @@ } // }}} + + + + + /*******************************************************************************/ + /************************ METHODS FROM Tree_Memory *****************************/ + /*******************************************************************************/ + + + // {{{ hasChildren() + + /** + * returns if the given element has any children + * + * @version 2001/12/17 + * @access public + * @author Wolfram Kriesing + * @param integer $id the id of the node to check for children + * @return boolean true if the node has children + */ + function hasChildren($id=0) + { + if (isset($this->data[$id]['children']) && + sizeof($this->data[$id]['children'])>0) { + return true; + } + return false; + } + + + + + + /*******************************************************************************/ + /************************ METHODS FROM Tree_Options ****************************/ + /*******************************************************************************/ + + + + // {{{ Tree_Options() + + /** + * this constructor sets the options, since i normally need this and + * in case the constructor doesnt need to do anymore i already have + * it done :-) + * + * @version 02/01/08 + * @access public + * @author Wolfram Kriesing + * @param array the key-value pairs of the options that shall be set + * @param boolean if set to true options are also set + * even if no key(s) was/were found in the options property + */ + function Tree_Options($options=array(), $force=false) + { + $this->_forceSetOption = $force; + if (is_array($options) && sizeof($options)) { + foreach ($options as $key=>$value) { + $this->setOption($key, $value); + } + } + } + + // }}} + // {{{ setOption() + + /** + * + * @access public + * @author Stig S. Baaken + * @param string the option name + * @param mixed the value for this option + * @param boolean if set to true options are also set + * even if no key(s) was/were found in the options property + */ + function setOption($option, $value, $force=false) + { + // if the value is an array extract the keys + // and apply only each value that is set + if (is_array($value)) { + // so we dont override existing options inside an array + // if an option is an array + foreach ($value as $key=>$aValue) { + $this->setOption(array($option,$key),$aValue); + } + return true; + } + + if (is_array($option)) { + $mainOption = $option[0]; + $options = "['".implode("']['",$option)."']"; + $evalCode = "\$this->options".$options." = \$value;"; + } else { + $evalCode = "\$this->options[\$option] = \$value;"; + $mainOption = $option; + } + + if ($this->_forceSetOption==true || + $force==true || isset($this->options[$mainOption])) { + eval($evalCode); + return true; + } + return false; + } + + // }}} + // {{{ setOptions() + + /** + * set a number of options which are simply given in an array + * + * @access public + * @param array the values to set + * @param boolean if set to true options are also set even if no key(s) + * was/were found in the options property + */ + function setOptions($options, $force=false) + { + if (is_array($options) && sizeof($options)) { + foreach ($options as $key=>$value) { + $this->setOption($key, $value, $force); + } + } + } + + // }}} + // {{{ getOption() + + /** + * + * @access public + * @author copied from PEAR: DB/commmon.php + * @param boolean true on success + */ + function getOption($option) + { + if (func_num_args() > 1 && + is_array($this->options[$option])) { + $args = func_get_args(); + $evalCode = "\$ret = \$this->options['". + implode("']['", $args) . "'];"; + eval($evalCode); + return $ret; + } + + if (isset($this->options[$option])) { + return $this->options[$option]; + } + return false; + } + + // }}} + // {{{ getOptions() + + /** + * returns all the options + * + * @version 02/05/20 + * @access public + * @author Wolfram Kriesing + * @return string all options as an array + */ + function getOptions() + { + return $this->options; + } + + // }}} + + } /*