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

Source for file Radio.php

Documentation is available at Radio.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 Form
  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: Radio.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_Form_Item');
  33.  
  34. /**
  35.  * HTML Form Radio class
  36.  *
  37.  * This class automates the creation and display of a radio button group.
  38.  *
  39.  * Example INI:
  40.  *
  41.  * <pre><samp>
  42.  * item.contact_method.label   = "Contact Method"
  43.  * item.contact_method.type    = radio
  44.  * item.contact_method.list    = "
  45.  *     phone:Call me,
  46.  *     email:Email me
  47.  * "
  48.  * item.contact_method.initial = phone
  49.  * </samp></pre>
  50.  *
  51.  * If only a single field is specified for a list item, that is used for both
  52.  * the label and the value for that item.
  53.  *
  54.  * To use images, specify three fields <kbd>value:altText:filepath</kbd>.  If the
  55.  * filepath is relative, it is taken to be relative to the local image directory.
  56.  *
  57.  * @category   Cnz
  58.  * @package    Cnz_Html
  59.  * @subpackage Form
  60.  */
  61. {
  62.     /**#@+ @var array */
  63.  
  64.     /** Associative array value => label */
  65.     private $itemArray      NULL;
  66.  
  67.     /**#@-*/
  68.  
  69.     /**#@+ @var string */
  70.     private $br        false;
  71.     /**#@-*/
  72.  
  73.     /* Methods ===========================================================*/
  74.  
  75.     /**
  76.      * Option fields:
  77.      *   none
  78.      *
  79.      * Configuration fields:
  80.      *   br    Flag to enable br tag between radio buttons
  81.      *   list  Button list
  82.      *
  83.      * @param  array       $options Options
  84.      * @param  Zend_Config $config  Configuration
  85.      */
  86.     public function __construct(array $options array()Zend_Config $config NULL)
  87.     {
  88.         parent::__construct($options$config);
  89.         if (isset($config->list)) $this->itemArray Cnz_Html::listToArray($config->list);
  90.         if (isset($config->br)) $this->br Cnz_Html::configFlag($config->br);
  91.         return;
  92.     }
  93.  
  94.     /**
  95.      * @param  string $style Value for outermost style attribute
  96.      * @return void 
  97.      */
  98.     public function display($style NULL)
  99.     {
  100.         $is Cnz_Html::getIndentString();
  101.         $indent Cnz_Html::indentGenerate();
  102.  
  103.         echo $indent'<div class = "'$this->genStyles('label')'">';
  104.         if (!empty($this->label)) echo $this->label;
  105.         else echo '&nbsp;';
  106.         echo '</div>'"\n";
  107.  
  108.         $number 1;
  109.         echo $indent'<div class = "'$this->genStyles('field')'">'"\n";
  110.         foreach ($this->itemArray as $value => $label)
  111.         {
  112.             $image NULL;
  113.             if (is_array($label))
  114.             {
  115.                 $image $label[1];
  116.                 $label $label[0];
  117.             }
  118.             echo $indent$is'<input';
  119.             if (!empty($this->initial&& $this->initial == $value)
  120.             {
  121.                 echo ' checked = "checked"';
  122.             }
  123.             echo ' id = "'$this->genId($number)'" name = "'$this->name'" type = "radio" value = "'$value'"/>'"\n";
  124.             echo $indent$is'<label for = "'$this->genId($number)'">';
  125.             if (empty($image))
  126.             {
  127.                 echo $label;
  128.             }
  129.             else
  130.             {
  131.                 echo '<img alt = "['$label']" class = "'$this->genStyles()'" src = "';
  132.                 if (substr($src01!= '/'echo 'image/';
  133.                 echo $image'"/>';
  134.             }
  135.             echo '</label>';
  136.             if ($this->brecho '<br/>';
  137.             echo "\n";
  138.             $number++;
  139.         }
  140.         echo $indent'</div>'"\n";
  141.  
  142.         return;
  143.     }
  144. }

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