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

Source for file Menu.php

Documentation is available at Menu.php

  1. <?php
  2. /**
  3.  * CNZ Framework
  4.  *
  5.  * A Framework for Creating and Using Complex Web Elements
  6.  *
  7.  * The purpose of this framework is to provide a library of high-level objects
  8.  * to facilitate common HTML coding tasks, such as menus, tables, and forms.
  9.  * The intent is to reduce repetitive HTML coding as much as possible, replacing
  10.  * it with a combination of configuration files and style sheets with
  11.  * standardized naming conventions.
  12.  *
  13.  * This framework is built on and requires the
  14.  * {@link http://framework.zend.com/ Zend Framework}.
  15.  *
  16.  * @category   Cnz
  17.  * @package    Cnz_Html
  18.  * @subpackage Menu
  19.  *
  20.  * @author    Lyle Frost <lfrost@cnz.com>
  21.  * @copyright Copyright (c) 2006-2007 Citadel Network <{@link http://www.citadelnetwork.com/}>
  22.  * @filesource
  23.  * @license   http://www.citadelnetwork.com/license/cnzframework New BSD License
  24.  * @version   $Id: Menu.php 27 2007-07-19 18:47:54Z lfrost $
  25.  */
  26.  
  27. /**
  28.  * Required classes.
  29.  *
  30.  * @ignore
  31.  */
  32. Zend_Loader::loadClass('Cnz_Html_Element');
  33. Zend_Loader::loadClass('Cnz_Html_Menu_Item');
  34.  
  35. /**
  36.  * HTML Menu class
  37.  *
  38.  * This class asserts that the most appropriate structure for a menu is an
  39.  * unordered list enclosed in a div.
  40.  *
  41.  * Each configuration item value is of the form text,link.  A blank item will
  42.  * cause a horizontal separator line to be created.  For multiple blank lines,
  43.  * give each line a label, but no link value (e.g., LINE1:).  If the text or
  44.  * link contains a colon, comma, or backslash, escape them with a backslash.
  45.  *
  46.  * Example INI (defaults shown as comments):
  47.  *
  48.  * <pre><samp>
  49.  * [HtmlMenuMain]
  50.  * list = "
  51.  *         Home:/,
  52.  *         About Us:/about/,
  53.  *         Contact Us:/contact/,
  54.  *         ,
  55.  *         Careers:/career/,
  56.  *         News:/news/,
  57.  *         Citadel Network:http\://www.citadelnetwork.com/
  58.  * "
  59.  * </samp></pre>
  60.  *
  61.  * Example PHP:
  62.  *
  63.  * <code>
  64.  * Cnz_Html::loadAndDisplay('Cnz_Html_Menu', array('name' => 'main', 'config' => true, 'style' => true));
  65.  * </code>
  66.  *
  67.  * Example CSS:
  68.  *
  69.  * <pre><samp>
  70.  * div.menu-main
  71.  * {
  72.  *         background-color:       #FFE4E1;
  73.  *         border-color:           inherit;
  74.  *         border-style:           ridge;
  75.  *         border-width:           0 0 3px 3px;
  76.  *         color:                  inherit;
  77.  *         clear:                  left;
  78.  *         float:                  left;
  79.  *         height:                 190px;
  80.  *         margin:                 0;
  81.  *         min-height:             400px;
  82.  *         padding:                10px 0 0 0;
  83.  *         width:                  134px;
  84.  * }
  85.  * ul.menu-main
  86.  * {
  87.  *         font-family:            Helvetica,Helv,Arial,sans-serif;
  88.  *         font-size:              small;
  89.  *         font-weight:            bold;
  90.  *         list-style-type:        none;
  91.  *         margin:                 0;
  92.  *         padding:                0 0 0 5px;
  93.  *         text-align:             left;
  94.  * }
  95.  * li.menu-main
  96.  * {
  97.  * }
  98.  * a[href].menu-main
  99.  * {
  100.  *         text-decoration:        none;
  101.  *         background-color:       inherit;
  102.  *         color:                  #901E78;
  103.  *         font-weight:            normal;
  104.  * }
  105.  * a[href]:hover.menu-main
  106.  * {
  107.  *         text-decoration:        underline;
  108.  *         background-color:       inherit;
  109.  *         color:                  #901E78;
  110.  *         font-weight:            bold;
  111.  * }
  112.  * hr.menu-main
  113.  * {
  114.  *         background-color:       inherit;
  115.  *         color:                  black;
  116.  *         margin:                 0;
  117.  *         padding:                0;
  118.  * }
  119.  * </samp></pre>
  120.  *
  121.  * Note that this class can also be used for horizontal menus by setting
  122.  * display:inline for &lt;li>.  Setting white-space:nowrap for &lt;ul> may also
  123.  * be desired for horizontal menus.
  124.  *
  125.  * @category   Cnz
  126.  * @package    Cnz_Html
  127.  * @subpackage Menu
  128.  */
  129. {
  130.     const HAS_CONFIG    = true;
  131.  
  132.     /**#@+ @var array */
  133.     private    $itemArray    array();
  134.     /**#@-*/
  135.  
  136.     /* Methods ===========================================================*/
  137.  
  138.     /**
  139.      * Option fields:
  140.      *   list         Menu item list
  141.      *
  142.      * Configuration fields:
  143.      *   list         Menu item list
  144.      *
  145.      * @param  array $options Options
  146.      */
  147.     public function __construct(array $options array())
  148.     {
  149.         parent::__construct($options);
  150.  
  151.         if (isset($options['list'])) $menu Cnz_Html::listToArray($options['list']);
  152.         else $menu Cnz_Html::listToArray($this->config->list);
  153.  
  154.         $count count($menu);
  155.         $i 0;
  156.         foreach ($menu as $text => $link)
  157.         {
  158.             $this->itemArray[$i++new Cnz_Html_Menu_Item($options$text$link);
  159.         }
  160.         return;
  161.     }
  162.  
  163.     /**
  164.      * @param  string $style Value for outermost style attribute
  165.      * @return void 
  166.      */
  167.     public function display($style NULL)
  168.     {
  169.         $is Cnz_Html::getIndentString();
  170.         $indent Cnz_Html::indentGenerate();
  171.  
  172.         echo $indent'<div class = "'$this->genStyles()'"';
  173.         echo ' id = "'$this->genId()'"';
  174.         if (!empty($style)) echo ' style = "'$style'"';
  175.         echo '>'"\n";
  176.         Cnz_Html::indentInc();
  177.         $indent Cnz_Html::indentGenerate();
  178.  
  179.         echo $indent'<ul class = "'$this->genStyles()'">'"\n";
  180.         Cnz_Html::indentInc();
  181.  
  182.         $count count($this->itemArray);
  183.         for ($i 0$i $count$i++)
  184.         {
  185.             $this->itemArray[$i]->display($this->name);
  186.         }
  187.  
  188.         Cnz_Html::indentDec();
  189.         $indent Cnz_Html::indentGenerate();
  190.         echo $indent'</ul>'"\n";
  191.  
  192.         Cnz_Html::indentDec();
  193.         $indent Cnz_Html::indentGenerate();
  194.         echo $indent'</div>'"\n";
  195.  
  196.         return;
  197.     }
  198. }

Documentation generated on Thu, 19 Jul 2007 15:02:13 -0400 by phpDocumentor 1.4.0RC2