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
00035 abstract class Mage_Eav_Model_Entity_Attribute_Frontend_Abstract implements Mage_Eav_Model_Entity_Attribute_Frontend_Interface
00036 {
00037
00038
00039
00040
00041
00042
00043 protected $_attribute;
00044
00045
00046
00047
00048
00049
00050
00051 public function setAttribute($attribute)
00052 {
00053 $this->_attribute = $attribute;
00054 return $this;
00055 }
00056
00057
00058
00059
00060
00061
00062 public function getAttribute()
00063 {
00064 return $this->_attribute;
00065 }
00066
00067
00068
00069
00070
00071
00072 public function getInputType()
00073 {
00074 return $this->getAttribute()->getFrontendInput();
00075 }
00076
00077
00078
00079
00080
00081
00082 public function getLabel()
00083 {
00084 $label = $this->getAttribute()->getFrontendLabel();
00085 if (is_null($label) || $label=='') {
00086 $label = $this->getAttribute()->getAttributeCode();
00087 }
00088 return $label;
00089 }
00090
00091 public function getValue(Varien_Object $object)
00092 {
00093 $value = $object->getData($this->getAttribute()->getAttributeCode());
00094 if (in_array($this->getConfigField('input'), array('select','boolean'))) {
00095 $valueOption = $this->getOption($value);
00096 if (!$valueOption) {
00097 $opt = new Mage_Eav_Model_Entity_Attribute_Source_Boolean();
00098 if ($options = $opt->getAllOptions()) {
00099 foreach ($options as $option) {
00100 if ($option['value'] == $value) {
00101 $valueOption = $option['label'];
00102 }
00103 }
00104 }
00105 }
00106 $value = $valueOption;
00107 }
00108 elseif ($this->getConfigField('input')=='multiselect') {
00109 $value = $this->getOption($value);
00110 if (is_array($value)) {
00111 $value = implode(', ', $value);
00112 }
00113 }
00114 return $value;
00115 }
00116
00117 public function isVisible()
00118 {
00119 return $this->getConfigField('frontend_visible');
00120 }
00121
00122 public function getClass()
00123 {
00124 $out = $this->getAttribute()->getFrontendClass();
00125 if ($this->getAttribute()->getIsRequired()) {
00126 $out .= ' required-entry';
00127 }
00128 return $out;
00129 }
00130
00131 public function getConfigField($fieldName)
00132 {
00133 return $this->getAttribute()->getData('frontend_'.$fieldName);
00134 }
00135
00136
00137
00138
00139
00140
00141 public function getSelectOptions()
00142 {
00143 return $this->getAttribute()->getSource()->getAllOptions();
00144 }
00145
00146 public function getOption($optionId)
00147 {
00148 if ($source = $this->getAttribute()->getSource()) {
00149 return $source->getOptionText($optionId);
00150 }
00151 return false;
00152 }
00153
00154
00155
00156
00157
00158
00159 public function getInputRendererClass() {
00160 if ($className = $this->getAttribute()->getData('frontend_input_renderer')) {
00161 return Mage::getConfig()->getBlockClassName($className);
00162 }
00163 return null;
00164 }
00165
00166 }