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

Source for file Output.php

Documentation is available at Output.php

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PEAR :: DB_NestedSet_Output                                          |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 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: Daniel Khan <dk@webcluster.at>                              |
  17. // |          Jason Rust  <jason@rustyparts.com>                          |
  18. // +----------------------------------------------------------------------+
  19. // $Id: Output.php 199223 2005-10-25 23:34:10Z datenpunk $
  20. //
  21.  
  22. require_once 'PEAR.php';
  23.  
  24. // {{{ constants
  25.  
  26. define('NESEO_ERROR_NO_METHOD',    'E1000');
  27. define('NESEO_DRIVER_NOT_FOUND',   'E1100');
  28. define('NESEO_ERROR_NO_OPTIONS',   'E2100');
  29.  
  30. // }}}
  31. // {{{ DB_NestedSet_Output:: class
  32.  
  33. /**
  34. * DB_NestedSet_Output is a unified API for other output drivers
  35. * Status is beta
  36. *
  37. * At the moment PEAR::HTML_TreeMenu written by Jason Rust is supported
  38. * A driver for treemenu.org will follow soon.
  39. *
  40. * Usage example:
  41. *
  42. * require_once('DB_NestedSet/NestedSet/Output.php');
  43. * $icon         = 'folder.gif';
  44. * $expandedIcon = 'folder-expanded.gif';
  45. * // get data (important to fetch it as an array, using the true flag)
  46. * $data = $NeSe->getAllNodes(true);
  47. * // change the events for one of the elements
  48. * $data[35]['events'] = array('onexpand' => 'alert("we expanded!");');
  49. * // add links to each item
  50. * foreach ($data as $a_data) {
  51. *   $a_data['link'] = 'http://foo.com/foo.php?' . $a_data['id'];
  52. * }
  53. * $params = array(
  54. * 'structure' => $data,
  55. * 'options' => array(
  56. * 'icon' => $icon,
  57. * 'expandedIcon' => $expandedIcon,
  58. * ),
  59. * 'textField' => 'name',
  60. * 'linkField' => 'link',
  61. * );
  62. * $menu =& DB_NestedSet_Output::factory('TreeMenu', $params);
  63. * $menu->printListbox();
  64. *
  65. @author       Daniel Khan <dk@webcluster.at>
  66. @package      DB_NestedSet
  67. @version      $Revision: 199223 $
  68. @access       public
  69. *
  70. */
  71.  
  72. // }}}
  73.     // {{{ properties
  74.  
  75.     /**
  76.     * @var object The tree menu structure
  77.     * @access private
  78.     */
  79.     var $_structTreeMenu    = false;
  80.  
  81.     /**
  82.     * @var array Array of options to be passed to the ouput methods
  83.     * @access public
  84.     */
  85.     var $options    = array();
  86.  
  87.     // }}}
  88.     // {{{ factory()
  89.  
  90.     /**
  91.     * Returns a output driver object
  92.     *
  93.     * @param array $params A DB_NestedSet nodeset
  94.     * @param string $driver (optional) The driver, such as TreeMenu (default)
  95.     *
  96.     * @access public
  97.     * @return object The DB_NestedSet_Ouput object
  98.     */
  99.     function &factory ($params$driver 'TreeMenu'{
  100.  
  101.         $path dirname(__FILE__).'/'.$driver.'.php';
  102.         if(is_dir($path|| !file_exists($path)) {
  103.             PEAR::raiseError("The output driver '$driver' wasn't found"NESEO_DRIVER_NOT_FOUNDPEAR_ERROR_TRIGGERE_USER_ERROR);
  104.         }
  105.  
  106.         require_once($path);
  107.         $driverClass 'DB_NestedSet_'.$driver;
  108.         $cls = new $driverClass($params);
  109.         return $cls;
  110.     }
  111.  
  112.     // }}}
  113.     // {{{ setOptions()
  114.  
  115.     /**
  116.     * Set's options for a specific output group (printTree, printListbox)
  117.     * This enables you to set specific options for each output method
  118.     *
  119.     * @param string $group Output group ATM 'printTree' or 'printListbox'
  120.     * @param array $options Hash with options
  121.     *
  122.     * @access public
  123.     * @return bool 
  124.     */
  125.     function setOptions($group$options{
  126.         $this->options[$group$options;
  127.         return true;
  128.     }
  129.  
  130.     // }}}
  131.     // {{{ _getOptions()
  132.  
  133.     /**
  134.     * Get's all option for a specific output group (printTree, printListbox)
  135.     *
  136.     * @param string $group Output group ATM 'printTree' or 'printListbox'
  137.     *
  138.     * @access private
  139.     * @return array Options
  140.     */
  141.     function _getOptions($group{
  142.  
  143.         if (!isset($this->options[$group])) {
  144.             return array();
  145.         }
  146.         return $this->options[$group];
  147.     }
  148.  
  149.     // }}}
  150.     // {{{ printTree()
  151.  
  152.     /**
  153.     * Print's the current tree using the output driver
  154.     * Overriden by the driver class
  155.     *
  156.     * @access public
  157.     */
  158.     function printTree({
  159.         PEAR::raiseError("Method not available for this driver"NESEO_ERROR_NO_METHODPEAR_ERROR_TRIGGERE_USER_ERROR);
  160.     }
  161.  
  162.     // }}}
  163.     // {{{ printListbox()
  164.  
  165.     /**
  166.     * Print's a listbox representing the current tree
  167.     * Overriden by the driver class
  168.     *
  169.     * @access public
  170.     */
  171.     function printListbox({
  172.         PEAR::raiseError("Method not available for this driver"NESEO_ERROR_NO_METHODPEAR_ERROR_TRIGGERE_USER_ERROR);
  173.     }
  174.  
  175.     // }}}
  176.  
  177.     // {{{ toHTML()
  178.  
  179.     /**
  180.      * Returns the HTML for the DHTML-menu. This method can be
  181.      * used instead of printMenu() to use the menu system
  182.      * with a template system.
  183.      *
  184.      * @access public
  185.      * @return string The HTML for the menu
  186.      * @author Emanuel Zueger
  187.      */
  188.     function tree_toHTML({
  189.         PEAR::raiseError("Method not available for this driver"NESEO_ERROR_NO_METHODPEAR_ERROR_TRIGGERE_USER_ERROR);
  190.     }
  191.  
  192.     // }}}
  193.     // {{{ listbox_toHTML()
  194.  
  195.     /**
  196.      * Returns the HTML for the listbox. This method can be
  197.      * used instead of printListbox() to use the menu system
  198.      * with a template system.
  199.      *
  200.      * @access public
  201.      * @return string The HTML for the listbox
  202.      * @author Emanuel Zueger
  203.      */
  204.     function listbox_toHTML({
  205.         PEAR::raiseError("Method not available for this driver"NESEO_ERROR_NO_METHODPEAR_ERROR_TRIGGERE_USER_ERROR);
  206.     }
  207.     // }}}
  208.     // {{{ getStructure()
  209.  
  210.     /**
  211.      *
  212.      * @access public
  213.      * @return mixed 
  214.      */
  215.     function returnStructure({
  216.         PEAR::raiseError("Method not available for this driver"NESEO_ERROR_NO_METHODPEAR_ERROR_TRIGGERE_USER_ERROR);
  217.     }
  218.     // }}}
  219. }
  220. ?>

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