00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Varien_Data_Form_Element_Radios extends Varien_Data_Form_Element_Abstract
00035 {
00036 public function __construct($attributes=array())
00037 {
00038 parent::__construct($attributes);
00039 $this->setType('radios');
00040 }
00041
00042 public function getSeparator()
00043 {
00044 $separator = $this->getData('separator');
00045 if (is_null($separator)) {
00046 $separator = ' ';
00047 }
00048 return $separator;
00049 }
00050
00051 public function getElementHtml()
00052 {
00053 $html = '';
00054 $value = $this->getValue();
00055 if ($values = $this->getValues()) {
00056 foreach ($values as $option) {
00057 $html.= $this->_optionToHtml($option, $value);
00058 }
00059 }
00060 $html.= $this->getAfterElementHtml();
00061 return $html;
00062 }
00063
00064 protected function _optionToHtml($option, $selected)
00065 {
00066 $html = '<input type="radio"'.$this->serialize(array('name', 'class', 'style'));
00067 if (is_array($option)) {
00068 $html.= 'value="'.$this->_escape($option['value']).'" id="'.$this->getHtmlId().$option['value'].'"';
00069 if ($option['value'] == $selected) {
00070 $html.= ' checked="checked"';
00071 }
00072 $html.= ' />';
00073 $html.= '<label class="inline" for="'.$this->getHtmlId().$option['value'].'">'.$option['label'].'</label>';
00074 }
00075 elseif ($option instanceof Varien_Object) {
00076 $html.= 'id="'.$this->getHtmlId().$option->getValue().'"'.$option->serialize(array('label', 'title', 'value', 'class', 'style'));
00077 if (in_array($option->getValue(), $selected)) {
00078 $html.= ' checked="checked"';
00079 }
00080 $html.= ' />';
00081 $html.= '<label class="inline" for="'.$this->getHtmlId().$option->getValue().'">'.$option->getLabel().'</label>';
00082 }
00083 $html.= $this->getSeparator() . "\n";
00084 return $html;
00085 }
00086 }