Tree
[ class tree: Tree ] [ index: Tree ] [ all elements ]

Source for file Common.php

Documentation is available at Common.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Wolfram Kriesing <wolfram@kriesing.de>                      |
  17. // +----------------------------------------------------------------------+
  18. //
  19. //  $Id: Common.php 320703 2011-12-08 22:08:40Z danielc $
  20.  
  21. require_once 'Tree/Tree.php';
  22. require_once 'Tree/Error.php';
  23.  
  24. /**
  25.  * common tree class, implements common functionality
  26.  *
  27.  *
  28.  * @access     public
  29.  * @author     Wolfram Kriesing <wolfram@kriesing.de>
  30.  * @version    2001/06/27
  31.  * @package    Tree
  32.  */
  33. {
  34.      /**
  35.      * @var array   you need to overwrite this array and give the keys/
  36.      *               that are allowed
  37.      */
  38.     var $_forceSetOption = false;
  39.  
  40.     /**
  41.      * put proper value-keys are given in each class, depending
  42.      * on the implementation only some options are needed or allowed,
  43.      * see the classes which extend this one
  44.      *
  45.      * @access public
  46.      * @var    array   saves the options passed to the constructor
  47.      */
  48.     var $options =  array();
  49.  
  50.  
  51.     // {{{ getChildId()
  52.  
  53.     /**
  54.      * @version    2002/01/18
  55.      * @access     public
  56.      * @author     Wolfram Kriesing <wolfram@kriesing.de>
  57.      */
  58.     function getChildId($id)
  59.     {
  60.         $child $this->getChild($id);
  61.         return $child['id'];
  62.     }
  63.  
  64.     // }}}
  65.     // {{{ getChildrenIds()
  66.  
  67.     /**
  68.      * get the ids of the children of the given element
  69.      *
  70.      * @version 2002/02/06
  71.      * @access  public
  72.      * @author  Wolfram Kriesing <wolfram@kriesing.de>
  73.      * @param   integer ID of the element that the children shall be
  74.      *                   retreived for
  75.      * @param   integer how many levels deep into the tree
  76.      * @return  mixed   an array of all the ids of the children of the element
  77.      *                   with id=$id, or false if there are no children
  78.      */
  79.     function getChildrenIds($id$levels = 1)
  80.     {
  81.         // returns false if no children exist
  82.         if (!($children $this->getChildren($id$levels))) {
  83.             return array();
  84.         }
  85.         // return an empty array, if you want to know
  86.         // if there are children, use hasChildren
  87.         if ($children && sizeof($children)) {
  88.             foreach ($children as $aChild{
  89.                 $childrenIds[$aChild['id'];
  90.             }
  91.         }
  92.  
  93.         return $childrenIds;
  94.     }
  95.  
  96.     // }}}
  97.     // {{{ getAllChildren()
  98.  
  99.     /**
  100.      * gets all the children and grand children etc.
  101.      *
  102.      * @version 2002/09/30
  103.      * @access  public
  104.      * @author  Wolfram Kriesing <wolfram@kriesing.de>
  105.      * @param   integer ID of the element that the children shall be
  106.      *                   retreived for
  107.      *
  108.      * @return  mixed   an array of all the children of the element with
  109.      *                   id=$id, or false if there are no children
  110.      */
  111.      // FIXXXME remove this method and replace it by getChildren($id,0)
  112.     function getAllChildren($id)
  113.     {
  114.         $retChildren = false;
  115.         if ($children $this->hasChildren($id)) {
  116.             $retChildren $this->_getAllChildren($id);
  117.         }
  118.         return $retChildren;
  119.     }
  120.  
  121.     // }}}
  122.     // {{{ _getAllChildren()
  123.  
  124.     /**
  125.      * this method gets all the children recursively
  126.      *
  127.      * @see getAllChildren()
  128.      * @version 2002/09/30
  129.      * @access  public
  130.      * @author  Wolfram Kriesing <wolfram@kriesing.de>
  131.      * @param   integer ID of the element that the children shall be
  132.      *                   retreived for
  133.      *
  134.      * @return  mixed   an array of all the ids of the children of the element
  135.      *                   with id=$id, or false if there are no children
  136.      */
  137.     function &_getAllChildren($id)
  138.     {
  139.         $retChildren = array();
  140.         if ($children $this->getChildren($id)) {
  141.             foreach ($children as $key => $aChild{
  142.                 $retChildren[&$children[$key];
  143.                 $retChildren array_merge($retChildren,
  144.                         $this->_getAllChildren($aChild['id']));
  145.             }
  146.         }
  147.         return $retChildren;
  148.     }
  149.  
  150.     // }}}
  151.     // {{{ getAllChildrenIds()
  152.  
  153.     /**
  154.      * gets all the children-ids and grand children-ids
  155.      *
  156.      * @version 2002/09/30
  157.      * @access  public
  158.      * @author  Kriesing <wolfram@kriesing.de>
  159.      * @param   integer ID of the element that the children shall
  160.      *           be retreived for
  161.      *
  162.      * @return  mixed   an array of all the ids of the children of the element
  163.      *                   with id=$id,
  164.      *                   or false if there are no children
  165.      */
  166.     function getAllChildrenIds($id)
  167.     {
  168.         $childrenIds = array();
  169.         if ($allChildren $this->getAllChildren($id)) {
  170.             $childrenIds = array();
  171.             foreach ($allChildren as $aNode{
  172.                 $childrenIds[$aNode['id'];
  173.             }
  174.         }
  175.         return $childrenIds;
  176.     }
  177.  
  178.     // }}}
  179.     // {{{ getParentId()
  180.  
  181.     /**
  182.      * get the id of the parent for the given element
  183.      *
  184.      * @version 2002/01/18
  185.      * @access  public
  186.      * @param   integer the id of the element for which the parentId
  187.      *                   shall be retreived
  188.      * @author Wolfram Kriesing <wolfram@kriesing.de>
  189.      */
  190.     function getParentId($id)
  191.     {
  192.         $parent $this->getParent($id);
  193.         return $parent['id'];
  194.     }
  195.  
  196.     // }}}
  197.     // {{{ getParents()
  198.  
  199.     /**
  200.      * this gets all the preceeding nodes, the parent and it's parent and so on
  201.      *
  202.      * @version 2002/08/19
  203.      * @access  public
  204.      * @author  Wolfram Kriesing <wolfram@kriesing.de>
  205.      * @param   integer the id of the element for which the parentId shall
  206.      *                   be retreived
  207.      * @return  array   of the parent nodes including the node with id $id
  208.      */
  209.     function getParents($id)
  210.     {
  211.         $path $this->getPath($id);
  212.         $parents = array();
  213.         if (sizeof($path)) {
  214.             foreach($path as $aNode{
  215.                 $parents[$aNode;
  216.             }
  217.         }
  218.         return $parents;
  219.     }
  220.  
  221.     // }}}
  222.     // {{{ getParentsIds()
  223.  
  224.     /**
  225.      * get the ids of the parents and all it's parents and so on
  226.      * it simply returns the ids of the elements returned by getParents()
  227.      *
  228.      * @see getParents()
  229.      * @version 2002/08/19
  230.      * @access  public
  231.      * @author  Wolfram Kriesing <wolfram@kriesing.de>
  232.      * @param   integer $id the id of the element for which the parentId
  233.      *           shall be retreived
  234.      *
  235.      * @return     array   of the ids
  236.      */
  237.     function getParentsIds($id)
  238.     {
  239.         $parents $this->getParents($id);
  240.         $parentsIds = array();
  241.         if (sizeof($parents)) {
  242.             foreach($parents as $aNode{
  243.                 $parentsIds[$aNode['id'];
  244.             }
  245.         }
  246.         return $parentsIds;
  247.     }
  248.  
  249.     // }}}
  250.     // {{{ getNextId()
  251.  
  252.     /**
  253.      * @version    2002/01/18
  254.      * @access     public
  255.      * @author     Wolfram Kriesing <wolfram@kriesing.de>
  256.      */
  257.     function getNextId($id)
  258.     {
  259.         $next $this->getNext($id);
  260.         return $next['id'];
  261.     }
  262.  
  263.     // }}}
  264.     // {{{ getPreviousId()
  265.  
  266.     /**
  267.      * @version    2002/01/18
  268.      * @access     public
  269.      * @author     Wolfram Kriesing <wolfram@kriesing.de>
  270.      */
  271.     function getPreviousId($id)
  272.     {
  273.         $previous $this->getPrevious($id);
  274.         return $previous['id'];
  275.     }
  276.  
  277.     // }}}
  278.     // {{{ getLeftId()
  279.  
  280.     /**
  281.      * @version    2002/01/18
  282.      * @access     public
  283.      * @author     Wolfram Kriesing <wolfram@kriesing.de>
  284.      */
  285.     function getLeftId($id)
  286.     {
  287.         $left $this->getLeft($id);
  288.         return $left['id'];
  289.     }
  290.  
  291.     // }}}
  292.     // {{{ getRightId()
  293.  
  294.     /**
  295.      * @version    2002/01/18
  296.      * @access     public
  297.      * @author     Wolfram Kriesing <wolfram@kriesing.de>
  298.      */
  299.     function getRightId($id)
  300.     {
  301.         $right $this->getRight($id);
  302.         return $right['id'];
  303.     }
  304.  
  305.     // }}}
  306.     // {{{ getFirstRootId()
  307.  
  308.     /**
  309.      * @version    2002/04/16
  310.      * @access     public
  311.      * @author     Wolfram Kriesing <wolfram@kriesing.de>
  312.      */
  313.     function getFirstRootId()
  314.     {
  315.         $firstRoot $this->getFirstRoot();
  316.         return $firstRoot['id'];
  317.     }
  318.  
  319.     // }}}
  320.     // {{{ getRootId()
  321.  
  322.     /**
  323.      * @version    2002/04/16
  324.      * @access     public
  325.      * @author     Wolfram Kriesing <wolfram@kriesing.de>
  326.      */
  327.     function getRootId()
  328.     {
  329.         $firstRoot $this->getRoot();
  330.         return $firstRoot['id'];
  331.     }
  332.  
  333.     // }}}
  334.     // {{{ getPathAsString()
  335.  
  336.     /**
  337.      * returns the path as a string
  338.      *
  339.      * @access  public
  340.      * @version 2002/03/28
  341.      * @access  public
  342.      * @author  Wolfram Kriesing <wolfram@kriesing.de>
  343.      * @param   mixed   $id     the id of the node to get the path for
  344.      * @param   integer If offset is positive, the sequence will
  345.      *                   start at that offset in the array .  If
  346.      *                   offset is negative, the sequence will start that far
  347.      *                   from the end of the array.
  348.      * @param   integer If length is given and is positive, then
  349.      *                   the sequence will have that many elements in it. If
  350.      *                   length is given and is negative then the
  351.      *                   sequence will stop that many elements from the end of
  352.      *                   the array. If it is omitted, then the sequence will
  353.      *                   have everything from offset up until the end
  354.      *                   of the array.
  355.      * @param   string  you can tell the key the path shall be used to be
  356.      *                   constructed with i.e. giving 'name' (=default) would
  357.      *                   use the value of the $element['name'] for the node-name
  358.      *                   (thanks to Michael Johnson).
  359.      *
  360.      * @return  array   this array contains all elements from the root
  361.      *                   to the element given by the id
  362.      */
  363.     function getPathAsString($id$seperator '/',
  364.                                 $offset = 0$length = 0$key 'name')
  365.     {
  366.         $path $this->getPath($id);
  367.         foreach ($path as $aNode{
  368.             $pathArray[$aNode[$key];
  369.         }
  370.  
  371.         if ($offset{
  372.             if ($length{
  373.                 $pathArray array_slice($pathArray$offset$length);
  374.             else {
  375.                 $pathArray array_slice($pathArray$offset);
  376.             }
  377.         }
  378.  
  379.         $pathString '';
  380.         if (sizeof($pathArray)) {
  381.             $pathString implode($seperator$pathArray);
  382.         }
  383.         return $pathString;
  384.     }
  385.  
  386.     // }}}
  387.  
  388.  
  389.     //
  390.     //  abstract methods, those should be overwritten by the implementing class
  391.     //
  392.  
  393.     // {{{ getPath()
  394.  
  395.     /**
  396.      * gets the path to the element given by its id
  397.      *
  398.      * @abstract
  399.      * @version 2001/10/10
  400.      * @access  public
  401.      * @author  Wolfram Kriesing <wolfram@kriesing.de>
  402.      * @param   mixed   $id     the id of the node to get the path for
  403.      * @return  array   this array contains all elements from the root
  404.      *                   to the element given by the id
  405.      */
  406.     function getPath($id)
  407.     {
  408.         return $this->_raiseError(TREE_ERROR_NOT_IMPLEMENTED,
  409.                 __FUNCTION____LINE__);
  410.     }
  411.  
  412.     // }}}
  413.     // {{{ _preparePath()
  414.  
  415.     /**
  416.      * gets the path to the element given by its id
  417.      *
  418.      * @version 2003/05/11
  419.      * @access  private
  420.      * @author  Wolfram Kriesing <wolfram@kriesing.de>
  421.      * @param   mixed   $id     the id of the node to get the path for
  422.      * @return  array   this array contains the path elements and the sublevels
  423.      *                   to substract if no $cwd has been given.
  424.      */
  425.     function _preparePath($path$cwd '/'$separator '/'){
  426.         $elems explode($separator$path);
  427.         $cntElems sizeof($elems);
  428.         // beginning with a slash
  429.         if (empty($elems[0])) {
  430.             $beginSlash = true;
  431.             array_shift($elems);
  432.             $cntElems--;
  433.         }
  434.         // ending with a slash
  435.         if (empty($elems[$cntElems-1])) {
  436.             $endSlash = true;
  437.             array_pop($elems);
  438.             $cntElems--;
  439.         }
  440.         // Get the real path, and the levels
  441.         // to substract if required
  442.         $down = 0;
  443.         while ($elems[0== '..'{
  444.             array_shift($elems);
  445.             $down++;
  446.         }
  447.         if ($down >= 0 && $cwd == '/'{
  448.             $down = 0;
  449.             $_elems = array();
  450.             $sublevel = 0;
  451.             $_elems = array();
  452.         else {
  453.             list($_elems$sublevel$this->_preparePath($cwd);
  454.         }
  455.         $i = 0;
  456.         foreach($elems as $val){
  457.             if (trim($val== ''{
  458.                 return $this->_raiseError(TREE_ERROR_INVALID_PATH,
  459.                             __FUNCTION____LINE__);
  460.             }
  461.             if ($val == '..'{
  462.                  if ($i == 0{
  463.                     $down++;
  464.                  else {
  465.                     $i--;
  466.                  }
  467.             else {
  468.                 $_elems[$i++$val;
  469.             }
  470.         }
  471.         if (sizeof($_elems< 1){
  472.             return $this->_raiseError(TREE_ERROR_EMPTY_PATH,
  473.                         __FUNCTION____LINE__);
  474.         }
  475.         return array($_elems$sublevel);
  476.     }
  477.  
  478.     // }}}
  479.     // {{{ getLevel()
  480.  
  481.     /**
  482.      * get the level, which is how far below the root the element
  483.      * with the given id is
  484.      *
  485.      * @abstract
  486.      * @version    2001/11/25
  487.      * @access     public
  488.      * @author     Wolfram Kriesing <wolfram@kriesing.de>
  489.      * @param      mixed   $id     the id of the node to get the level for
  490.      *
  491.      */
  492.     function getLevel($id)
  493.     {
  494.         return $this->_raiseError(TREE_ERROR_NOT_IMPLEMENTED,
  495.                         __FUNCTION____LINE__);
  496.     }
  497.  
  498.     // }}}
  499.     // {{{ isChildOf()
  500.  
  501.     /**
  502.      * returns if $childId is a child of $id
  503.      *
  504.      * @abstract
  505.      * @version    2002/04/29
  506.      * @access     public
  507.      * @author     Wolfram Kriesing <wolfram@kriesing.de>
  508.      * @param      int     id of the element
  509.      * @param      int     id of the element to check if it is a child
  510.      * @param      boolean if this is true the entire tree below is checked
  511.      * @return     boolean true if it is a child
  512.      */
  513.     function isChildOf($id$childId$checkAll = true)
  514.     {
  515.         return $this->_raiseError(TREE_ERROR_NOT_IMPLEMENTED,
  516.                     __FUNCTION____LINE__);
  517.     }
  518.  
  519.     // }}}
  520.     // {{{ getIdByPath()
  521.  
  522.     /**
  523.      *
  524.      *
  525.      */
  526.     function getIdByPath($path$startId = 0,
  527.                         $nodeName 'name'$seperator '/')
  528.     {
  529.         return $this->_raiseError(TREE_ERROR_NOT_IMPLEMENTED,
  530.                     __FUNCTION____LINE__);
  531.     }
  532.  
  533.     // }}}
  534.     // {{{ getDepth()
  535.  
  536.     /**
  537.      * return the maximum depth of the tree
  538.      *
  539.      * @version    2003/02/25
  540.      * @access     public
  541.      * @author     Wolfram Kriesing <wolfram@kriesing.de>
  542.      * @return     int     the depth of the tree
  543.      */
  544.     function getDepth()
  545.     {
  546.         return $this->_treeDepth;
  547.     }
  548.  
  549.     // }}}
  550.  
  551.     //
  552.     //  PRIVATE METHODS
  553.     //
  554.  
  555.     // {{{ _prepareResults()
  556.  
  557.     /**
  558.      * prepare multiple results
  559.      *
  560.      * @see        _prepareResult()
  561.      * @access     private
  562.      * @version    2002/03/03
  563.      * @author     Wolfram Kriesing <wolfram@kriesing.de>
  564.      * @param      array   the data to prepare
  565.      * @return     array   prepared results
  566.      */
  567.     function &_prepareResults($results)
  568.     {
  569.         $newResults = array();
  570.         foreach ($results as $key => $aResult{
  571.             $newResults[$key$this->_prepareResult($aResult);
  572.         }
  573.         return $newResults;
  574.     }
  575.  
  576.     // }}}
  577.     // {{{ _prepareResult()
  578.  
  579.     /**
  580.       * map back the index names to get what is expected
  581.       *
  582.       * @access     private
  583.       * @version    2002/03/03
  584.       * @author     Wolfram Kriesing <wolfram@kriesing.de>
  585.       * @param      array   a result
  586.       * @return     array   the prepared result
  587.       */
  588.     function _prepareResult($result)
  589.     {
  590.         $map $this->getOption('columnNameMaps');
  591.         if ($map{
  592.             foreach ($map as $key => $columnName{
  593.                 if (isset($result[$columnName])) {
  594.                     $temp $result[$columnName];   // remember the value from the old name
  595.                     unset($result[$columnName]);    // remove the old one
  596.                     $result[$key$temp;          // save it in the mapped col-name
  597.                 }
  598.             }
  599.         }
  600.         return $result;
  601.     }
  602.  
  603.     // }}}
  604.     // {{{ _getColName()
  605.  
  606.     /**
  607.      * this method retrieves the real column name, as used in the DB
  608.      * since the internal names are fixed, to be portable between different
  609.      * DB-column namings, we map the internal name to the real column name here
  610.      *
  611.      * @access     private
  612.      * @version    2002/03/02
  613.      * @author     Wolfram Kriesing <wolfram@kriesing.de>
  614.      * @param      string  the internal name used
  615.      * @return     string  the real name of the column
  616.      */
  617.     function _getColName($internalName)
  618.     {
  619.         if ($map $this->getOption('columnNameMaps')) {
  620.             if (isset($map[$internalName])) {
  621.                 return $map[$internalName];
  622.             }
  623.         }
  624.         return $internalName;
  625.     }
  626.  
  627.     // }}}
  628.     // {{{ _raiseError()
  629.  
  630.     /**
  631.      *
  632.      *
  633.      * @access     private
  634.      * @version    2002/03/02
  635.      * @author     Pierre-Alain Joye <paj@pearfr.org>
  636.      * @param      string  the error message
  637.      * @param      int     the line in which the error occured
  638.      * @param      mixed   the error mode
  639.      * @return     object  Tree_Error
  640.      */
  641.     function _raiseError($errorCode$msg ''$line = 0)
  642.     {
  643.         include_once 'Tree/Error.php';
  644.         return new Tree_Error(
  645.             $msg$line__FILE__$mode$this->dbh->last_query);
  646.     }
  647.  
  648.     // }}}
  649.     // {{{ _throwError()
  650.  
  651.     /**
  652.      *
  653.      *
  654.      * @access     private
  655.      * @version    2002/03/02
  656.      * @author     Wolfram Kriesing <wolfram@kriesing.de>
  657.      * @param      string  the error message
  658.      * @param      int     the line in which the error occured
  659.      * @param      mixed   the error mode
  660.      * @return     object  Tree_Error
  661.      */
  662.     function _throwError($msg$line$mode = null)
  663.     {
  664.         include_once 'Tree/Error.php';
  665.         if ($mode === null && $this->debug > 0{
  666.             $mode = PEAR_ERROR_PRINT;
  667.         }
  668.         return new Tree_Error(
  669.             $msg$line__FILE__$mode$this->dbh->last_query);
  670.     }
  671.  
  672.     // }}}
  673.  
  674.  
  675.     /*******************************************************************************/
  676.     /************************ METHODS FROM Tree_Memory *****************************/
  677.     /*******************************************************************************/
  678.  
  679.     /**
  680.      * returns if the given element has any children
  681.      *
  682.      * @version 2001/12/17
  683.      * @access  public
  684.      * @author  Wolfram Kriesing <wolfram@kriesing.de>
  685.      * @param   integer $id the id of the node to check for children
  686.      * @return  boolean true if the node has children
  687.      */
  688.     function hasChildren($id = 0)
  689.     {
  690.         if (isset($this->data[$id]['children']&&
  691.             sizeof($this->data[$id]['children']> 0{
  692.             return true;
  693.         }
  694.         return false;
  695.     }
  696.  
  697.  
  698.  
  699.  
  700.  
  701.     /*******************************************************************************/
  702.     /************************ METHODS FROM Tree_Options ****************************/
  703.     /*******************************************************************************/
  704.  
  705.  
  706.  
  707.     // {{{ Tree_Options()
  708.  
  709.     /**
  710.      * this constructor sets the options, since i normally need this and
  711.      * in case the constructor doesnt need to do anymore i already have
  712.      * it done :-)
  713.      *
  714.      * @version    02/01/08
  715.      * @access public
  716.      * @author Wolfram Kriesing <wolfram@kriesing.de>
  717.      * @param  array   the key-value pairs of the options that shall be set
  718.      * @param  boolean if set to true options are also set
  719.      *                  even if no key(s) was/were found in the options property
  720.      */
  721.     function Tree_Options($options=array()$force=false)
  722.     {
  723.         $this->_forceSetOption $force;
  724.         if (is_array($options&& sizeof($options)) {
  725.             foreach ($options as $key=>$value{
  726.                 $this->setOption($key$value);
  727.             }
  728.         }
  729.     }
  730.  
  731.     // }}}
  732.     // {{{ setOption()
  733.  
  734.     /**
  735.      *
  736.      * @access public
  737.      * @author Stig S. Baaken
  738.      * @param  string  the option name
  739.      * @param  mixed   the value for this option
  740.      * @param  boolean if set to true options are also set
  741.      *                  even if no key(s) was/were found in the options property
  742.      */
  743.     function setOption($option$value$force = false)
  744.     {
  745.         // if the value is an array extract the keys
  746.         // and apply only each value that is set
  747.         if (is_array($value)) {
  748.             // so we dont override existing options inside an array
  749.             // if an option is an array
  750.             foreach ($value as $key=>$aValue{
  751.                 $this->setOption(array($option,$key),$aValue);
  752.             }
  753.             return true;
  754.         }
  755.  
  756.         if (is_array($option)) {
  757.             $mainOption $option[0];
  758.             $options "['".implode("']['",$option)."']";
  759.             $evalCode "\$this->options".$options." = \$value;";
  760.         else {
  761.             $evalCode "\$this->options[\$option] = \$value;";
  762.             $mainOption $option;
  763.         }
  764.  
  765.         if ($this->_forceSetOption == true ||
  766.             $force == true || isset($this->options[$mainOption])) {
  767.             eval($evalCode);
  768.             return true;
  769.         }
  770.         return false;
  771.     }
  772.  
  773.     // }}}
  774.     // {{{ setOptions()
  775.  
  776.     /**
  777.      * set a number of options which are simply given in an array
  778.      *
  779.      * @access public
  780.      * @param  array   the values to set
  781.      * @param  boolean if set to true options are also set even if no key(s)
  782.      *                  was/were found in the options property
  783.      */
  784.     function setOptions($options$force = false)
  785.     {
  786.         if (is_array($options&& sizeof($options)) {
  787.             foreach ($options as $key => $value{
  788.                 $this->setOption($key$value$force);
  789.             }
  790.         }
  791.     }
  792.  
  793.     // }}}
  794.     // {{{ getOption()
  795.  
  796.     /**
  797.      *
  798.      * @access     public
  799.      * @author     copied from PEAR: DB/commmon.php
  800.      * @param      boolean true on success
  801.      */
  802.     function getOption($option)
  803.     {
  804.         if (func_num_args(> 1 &&
  805.             is_array($this->options[$option])) {
  806.             $args func_get_args();
  807.             $evalCode "\$ret = \$this->options['".
  808.                         implode("']['"$args"'];";
  809.             eval($evalCode);
  810.             return $ret;
  811.         }
  812.  
  813.         if (isset($this->options[$option])) {
  814.             return $this->options[$option];
  815.         }
  816.         return false;
  817.     }
  818.  
  819.     // }}}
  820.     // {{{ getOptions()
  821.  
  822.     /**
  823.      * returns all the options
  824.      *
  825.      * @version    02/05/20
  826.      * @access     public
  827.      * @author     Wolfram Kriesing <wolfram@kriesing.de>
  828.      * @return     string      all options as an array
  829.      */
  830.     function getOptions()
  831.     {
  832.         return $this->options;
  833.     }
  834.  
  835.     // }}}
  836. }
  837.  
  838. /*
  839.  * Local Variables:
  840.  * mode: php
  841.  * tab-width: 4
  842.  * c-basic-offset: 4
  843.  * End:
  844.  */

Documentation generated on Mon, 11 Mar 2019 15:47:03 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.