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

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

00001 <?php
00026 require_once 'Zend/View/Helper/HtmlElement.php';
00027 
00037 abstract class Zend_View_Helper_FormElement extends Zend_View_Helper_HtmlElement
00038 {
00042     protected $_translator;
00043 
00049     public function getTranslator()
00050     {
00051          return $this->_translator;
00052     }
00053 
00060     public function setTranslator($translator = null)
00061     {
00062         if (null === $translator) {
00063             $this->_translator = null;
00064         } elseif ($translator instanceof Zend_Translate_Adapter) {
00065             $this->_translator = $translator;
00066         } elseif ($translator instanceof Zend_Translate) {
00067             $this->_translator = $translator->getAdapter();
00068         } else {
00069             require_once 'Zend/Form/Exception.php';
00070             throw new Zend_Form_Exception('Invalid translator specified');
00071         }
00072          return $this;
00073     }
00074 
00089     protected function _getInfo($name, $value = null, $attribs = null,
00090         $options = null, $listsep = null
00091     ) {
00092         // the baseline info.  note that $name serves a dual purpose;
00093         // if an array, it's an element info array that will override
00094         // these baseline values.  as such, ignore it for the 'name'
00095         // if it's an array.
00096         $info = array(
00097             'name'    => is_array($name) ? '' : $name,
00098             'id'      => is_array($name) ? '' : $name,
00099             'value'   => $value,
00100             'attribs' => $attribs,
00101             'options' => $options,
00102             'listsep' => $listsep,
00103             'disable' => false,
00104             'escape'  => true,
00105         );
00106 
00107         // override with named args
00108         if (is_array($name)) {
00109             // only set keys that are already in info
00110             foreach ($info as $key => $val) {
00111                 if (isset($name[$key])) {
00112                     $info[$key] = $name[$key];
00113                 }
00114             }
00115         }
00116 
00117         // force attribs to an array, per note from Orjan Persson.
00118         settype($info['attribs'], 'array');
00119 
00120         // Normalize readonly tag
00121         if (isset($info['attribs']['readonly'])
00122             && $info['attribs']['readonly'] != 'readonly')
00123         {
00124             $info['attribs']['readonly'] = 'readonly';
00125         }
00126 
00127         // Disable attribute
00128         if (isset($info['attribs']['disable'])
00129             && is_scalar($info['attribs']['disable']))
00130         {
00131             // disable the element
00132             $info['disable'] = (bool)$info['attribs']['disable'];
00133             unset($info['attribs']['disable']);
00134         } elseif (isset($info['attribs']['disable'])
00135             && is_array($info['attribs']['disable']))
00136         {
00137             $info['disable'] = $info['attribs']['disable'];
00138             unset($info['attribs']['disable']);
00139         }
00140 
00141         // Set ID for element
00142         if (isset($info['attribs']['id'])) {
00143             $info['id'] = (string) $info['attribs']['id'];
00144         } elseif (!isset($info['attribs']['id']) && !empty($info['name'])) {
00145             $id = $info['name'];
00146             if (substr($id, -2) == '[]') {
00147                 $id = substr($id, 0, strlen($id) - 2);
00148             }
00149             if (strstr($id, ']')) {
00150                 $id = trim($id, ']');
00151                 $id = str_replace('][', '-', $id);
00152                 $id = str_replace('[', '-', $id);
00153             }
00154             $info['id'] = $id;
00155         }
00156 
00157         // Determine escaping from attributes
00158         if (isset($info['attribs']['escape'])) {
00159             $info['escape'] = (bool) $info['attribs']['escape'];
00160         }
00161 
00162         // Determine listsetp from attributes
00163         if (isset($info['attribs']['listsep'])) {
00164             $info['listsep'] = (string) $info['attribs']['listsep'];
00165         }
00166 
00167         // Remove attribs that might overwrite the other keys. We do this LAST
00168         // because we needed the other attribs values earlier.
00169         foreach ($info as $key => $val) {
00170             if (isset($info['attribs'][$key])) {
00171                 unset($info['attribs'][$key]);
00172             }
00173         }
00174 
00175         // done!
00176         return $info;
00177     }
00178 
00195     protected function _hidden($name, $value = null, $attribs = null)
00196     {
00197         return '<input type="hidden"'
00198              . ' name="' . $this->view->escape($name) . '"'
00199              . ' value="' . $this->view->escape($value) . '"'
00200              . $this->_htmlAttribs($attribs) . $this->getClosingBracket();
00201     }
00202 }

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