• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Zend/View/Helper/FormRadio.php

00001 <?php
00027 require_once 'Zend/View/Helper/FormElement.php';
00028 
00029 
00039 class Zend_View_Helper_FormRadio extends Zend_View_Helper_FormElement
00040 {
00045     protected $_inputType = 'radio';
00046 
00051     protected $_isArray = false;
00052 
00071     public function formRadio($name, $value = null, $attribs = null,
00072         $options = null, $listsep = "<br />\n")
00073     {
00074 
00075         $info = $this->_getInfo($name, $value, $attribs, $options, $listsep);
00076         extract($info); // name, value, attribs, options, listsep, disable
00077 
00078         // retrieve attributes for labels (prefixed with 'label_' or 'label')
00079         $label_attribs = array();
00080         foreach ($attribs as $key => $val) {
00081             $tmp    = false;
00082             $keyLen = strlen($key);
00083             if ((6 < $keyLen) && (substr($key, 0, 6) == 'label_')) {
00084                 $tmp = substr($key, 6);
00085             } elseif ((5 < $keyLen) && (substr($key, 0, 5) == 'label')) {
00086                 $tmp = substr($key, 5);
00087             }
00088 
00089             if ($tmp) {
00090                 // make sure first char is lowercase
00091                 $tmp[0] = strtolower($tmp[0]);
00092                 $label_attribs[$tmp] = $val;
00093                 unset($attribs[$key]);
00094             }
00095         }
00096 
00097         $labelPlacement = 'append';
00098         foreach ($label_attribs as $key => $val) {
00099             switch (strtolower($key)) {
00100                 case 'placement':
00101                     unset($label_attribs[$key]);
00102                     $val = strtolower($val);
00103                     if (in_array($val, array('prepend', 'append'))) {
00104                         $labelPlacement = $val;
00105                     }
00106                     break;
00107             }
00108         }
00109 
00110         // the radio button values and labels
00111         $options = (array) $options;
00112 
00113         // build the element
00114         $xhtml = '';
00115         $list  = array();
00116 
00117         // should the name affect an array collection?
00118         $name = $this->view->escape($name);
00119         if ($this->_isArray && ('[]' != substr($name, -2))) {
00120             $name .= '[]';
00121         }
00122 
00123         // ensure value is an array to allow matching multiple times
00124         $value = (array) $value;
00125 
00126         // XHTML or HTML end tag?
00127         $endTag = ' />';
00128         if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
00129             $endTag= '>';
00130         }
00131 
00132         // add radio buttons to the list.
00133         require_once 'Zend/Filter/Alnum.php';
00134         $filter = new Zend_Filter_Alnum();
00135         foreach ($options as $opt_value => $opt_label) {
00136 
00137             // Should the label be escaped?
00138             if ($escape) {
00139                 $opt_label = $this->view->escape($opt_label);
00140             }
00141 
00142             // is it disabled?
00143             $disabled = '';
00144             if (true === $disable) {
00145                 $disabled = ' disabled="disabled"';
00146             } elseif (is_array($disable) && in_array($opt_value, $disable)) {
00147                 $disabled = ' disabled="disabled"';
00148             }
00149 
00150             // is it checked?
00151             $checked = '';
00152             if (in_array($opt_value, $value)) {
00153                 $checked = ' checked="checked"';
00154             }
00155 
00156             // generate ID
00157             $optId = $id . '-' . $filter->filter($opt_value);
00158 
00159             // Wrap the radios in labels
00160             $radio = '<label'
00161                     . $this->_htmlAttribs($label_attribs) . ' for="' . $optId . '">'
00162                     . (('prepend' == $labelPlacement) ? $opt_label : '')
00163                     . '<input type="' . $this->_inputType . '"'
00164                     . ' name="' . $name . '"'
00165                     . ' id="' . $optId . '"'
00166                     . ' value="' . $this->view->escape($opt_value) . '"'
00167                     . $checked
00168                     . $disabled
00169                     . $this->_htmlAttribs($attribs)
00170                     . $endTag
00171                     . (('append' == $labelPlacement) ? $opt_label : '')
00172                     . '</label>';
00173 
00174             // add to the array of radio buttons
00175             $list[] = $radio;
00176         }
00177 
00178         // done!
00179         $xhtml .= implode($listsep, $list);
00180 
00181         return $xhtml;
00182     }
00183 }

Generated on Thu Apr 19 2012 17:01:18 for openbiz by  doxygen 1.7.2