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_Backend_Abstract implements Mage_Eav_Model_Entity_Attribute_Backend_Interface
00036 {
00037
00038
00039
00040
00041
00042 protected $_attribute;
00043
00044
00045
00046
00047
00048
00049 protected $_valueId;
00050
00051
00052
00053
00054
00055
00056 protected $_table;
00057
00058
00059
00060
00061
00062
00063 protected $_entityIdField;
00064
00065
00066
00067
00068
00069
00070 protected $_defaultValue = null;
00071
00072
00073
00074
00075
00076
00077
00078 public function setAttribute($attribute)
00079 {
00080 $this->_attribute = $attribute;
00081 return $this;
00082 }
00083
00084
00085
00086
00087
00088
00089 public function getAttribute()
00090 {
00091 return $this->_attribute;
00092 }
00093
00094
00095
00096
00097
00098
00099 public function getType()
00100 {
00101 return $this->getAttribute()->getBackendType();
00102 }
00103
00104
00105
00106
00107
00108
00109 public function isStatic()
00110 {
00111 return $this->getAttribute()->isStatic();
00112 }
00113
00114
00115
00116
00117
00118
00119 public function getTable()
00120 {
00121 if (empty($this->_table)) {
00122 if ($this->isStatic()) {
00123 $this->_table = $this->getAttribute()->getEntityType()->getValueTablePrefix();
00124 } elseif ($this->getAttribute()->getBackendTable()) {
00125 $this->_table = $this->getAttribute()->getBackendTable();
00126 } else {
00127 $entity = $this->getAttribute()->getEntity();
00128 $this->_table = $entity->getValueTablePrefix()
00129 .'_'.$this->getType();
00130 }
00131 }
00132
00133 return $this->_table;
00134 }
00135
00136
00137
00138
00139
00140
00141 public function getEntityIdField()
00142 {
00143 if (empty($this->_entityIdField)) {
00144 if ($this->getAttribute()->getEntityIdField()) {
00145 $this->_entityIdField = $this->getAttribute()->getEntityIdField();
00146 } else {
00147 $this->_entityIdField = $this->getAttribute()->getEntityType()->getValueEntityIdField();
00148 }
00149 }
00150 return $this->_entityIdField;
00151 }
00152
00153 public function setValueId($valueId)
00154 {
00155 $this->_valueId = $valueId;
00156 return $this;
00157 }
00158
00159 public function getValueId()
00160 {
00161 return $this->_valueId;
00162 }
00163
00164 public function getDefaultValue()
00165 {
00166 if (is_null($this->_defaultValue)) {
00167 if ($this->getAttribute()->getDefaultValue()) {
00168 $this->_defaultValue = $this->getAttribute()->getDefaultValue();
00169 } else {
00170 $this->_defaultValue = "";
00171 }
00172 }
00173 return $this->_defaultValue;
00174 }
00175
00176 public function validate($object)
00177 {
00178 $attrCode = $this->getAttribute()->getAttributeCode();
00179 if ($this->getAttribute()->getIsRequired() && !$object->getData($attrCode)) {
00180 return false;
00181 }
00182 $value = $object->getData($this->getAttribute()->getAttributeCode());
00183 if ($this->getAttribute()->getIsUnique() && !$this->getAttribute()->getIsRequired() && ($value == '' || $this->getAttribute()->isValueEmpty($value))) {
00184 return true;
00185 }
00186
00187 if ($this->getAttribute()->getIsUnique()) {
00188 if (!$this->getAttribute()->getEntity()->checkAttributeUniqueValue($this->getAttribute(), $object)) {
00189 $label = $this->getAttribute()->getFrontend()->getLabel();
00190 Mage::throwException(Mage::helper('eav')->__('Value of attribute "%s" must be unique', $label));
00191 }
00192 }
00193 return true;
00194 }
00195
00196 public function afterLoad($object)
00197 {
00198
00199 }
00200
00201 public function beforeSave($object)
00202 {
00203 $attrCode = $this->getAttribute()->getAttributeCode();
00204 if (!$object->hasData($attrCode) && $this->getDefaultValue()) {
00205 $object->setData($attrCode, $this->getDefaultValue());
00206 }
00207 }
00208
00209 public function afterSave($object)
00210 {
00211
00212 }
00213
00214 public function beforeDelete($object)
00215 {
00216
00217 }
00218
00219 public function afterDelete($object)
00220 {
00221
00222 }
00223 }