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

Source for file ArrayRenderer.php

Documentation is available at ArrayRenderer.php

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  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. // | Author:  Alexey Borzov <avb@php.net>                                 |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: ArrayRenderer.php,v 1.2 2004/01/18 17:35:52 avb Exp $
  20. //
  21.  
  22. require_once 'HTML/Menu/Renderer.php';
  23.  
  24. /**
  25.  * The renderer that creates an array of visible menu entries.
  26.  * 
  27.  * The resultant array can be used with e.g. a template engine to produce
  28.  * a completely custom menu look.
  29.  * All menu types except 'rows' are "rendered" into a one-dimensional array
  30.  * of entries:
  31.  * array(
  32.  *    'entry1',
  33.  *    ...
  34.  *    'entryN'
  35.  * )
  36.  * while 'rows' produce a two-dimensional array:
  37.  * array(
  38.  *    array('entry 1 for row 1', ..., 'entry M_1 for row 1'),
  39.  *    ...
  40.  *    array('entry 1 for row N', ..., 'entry M_N for row 1')
  41.  * )
  42.  * Here entry is
  43.  * array(
  44.  *    'url'    => url element of menu entry
  45.  *    'title'  => title element of menu entry
  46.  *    'level'  => entry's depth in the tree structure
  47.  *    'type'   => type of entry, one of HTML_MENU_ENTRY_* constants
  48.  *    // if the nodes in the original menu array contained keys other
  49.  *    // than 'url', 'title' and 'sub', they will be copied here, too
  50.  * )
  51.  * 
  52.  * @version  $Revision: 1.2 $
  53.  * @author   Alexey Borzov <avb@php.net>
  54.  * @access   public
  55.  * @package  HTML_Menu
  56.  */
  57. {
  58.    /**
  59.     * Generated array
  60.     * @var array 
  61.     */
  62.     var $_ary = array();
  63.  
  64.    /**
  65.     * Array for the current "menu", that is moved into $_ary by finishMenu(),
  66.     * makes sense mostly for 'rows
  67.     * @var array 
  68.     */
  69.     var $_menuAry = array();
  70.  
  71.     function finishMenu($level)
  72.     {
  73.         if ('rows' == $this->_menuType{
  74.             $this->_ary[$this->_menuAry;
  75.         else {
  76.             $this->_ary   $this->_menuAry;
  77.         }
  78.         $this->_menuAry = array();
  79.     }
  80.  
  81.  
  82.     function renderEntry($node$level$type)
  83.     {
  84.         unset($node['sub']);
  85.         $node['level'$level;
  86.         $node['type']  $type;
  87.         $this->_menuAry[$node;
  88.     }
  89.  
  90.  
  91.    /**
  92.     * Returns the resultant array
  93.     * 
  94.     * @access public
  95.     * @return array 
  96.     */
  97.     function toArray()
  98.     {
  99.         return $this->_ary;
  100.     }
  101. }
  102. ?>

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