Definition at line 35 of file Abstract.php.
_afterDelete | ( | Varien_Object $ | object | ) | [protected] |
After delete entity process
Varien_Object | $object |
Definition at line 1327 of file Abstract.php.
01328 { 01329 $this->walkAttributes('backend/afterDelete', array($object)); 01330 }
_afterLoad | ( | Varien_Object $ | object | ) | [protected] |
After Load Entity process
Varien_Object | $object |
Definition at line 1287 of file Abstract.php.
01288 { 01289 $this->walkAttributes('backend/afterLoad', array($object)); 01290 }
_afterSave | ( | Varien_Object $ | object | ) | [protected] |
After Save Entity process
Varien_Object | $object |
Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Category, Mage_Catalog_Model_Resource_Eav_Mysql4_Product, Mage_Customer_Model_Entity_Address, and Mage_Customer_Model_Entity_Customer.
Definition at line 1307 of file Abstract.php.
01308 { 01309 $this->walkAttributes('backend/afterSave', array($object)); 01310 }
_afterSetConfig | ( | ) | [protected] |
After set config process
Definition at line 1367 of file Abstract.php.
01368 { 01369 return $this; 01370 // Varien_Profiler::start(__METHOD__); 01371 // 01372 // $defaultAttributes = $this->_getDefaultAttributes(); 01373 // $defaultAttributes[] = $this->getEntityIdField(); 01374 // 01375 // $attributes = $this->getAttributesByCode(); 01376 // foreach ($defaultAttributes as $attr) { 01377 // if (empty($attributes[$attr]) && !$this->getAttribute($attr)) { 01378 // $attribute = Mage::getModel($this->getEntityType()->getAttributeModel()); 01379 // $attribute->setAttributeCode($attr) 01380 // ->setBackendType('static') 01381 // ->setEntityType($this->getEntityType()) 01382 // ->setEntityTypeId($this->getEntityType()->getId()); 01383 // $this->addAttribute($attribute); 01384 // } 01385 // } 01386 // Varien_Profiler::stop(__METHOD__); 01387 // return $this; 01388 }
_beforeDelete | ( | Varien_Object $ | object | ) | [protected] |
Before Delete Entity process
Varien_Object | $object |
Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Category.
Definition at line 1317 of file Abstract.php.
01318 { 01319 $this->walkAttributes('backend/beforeDelete', array($object)); 01320 }
_beforeSave | ( | Varien_Object $ | object | ) | [protected] |
Before delete Entity process
Varien_Object | $object |
Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Category, Mage_Catalog_Model_Resource_Eav_Mysql4_Product, and Mage_Customer_Model_Entity_Customer.
Definition at line 1297 of file Abstract.php.
01298 { 01299 $this->walkAttributes('backend/beforeSave', array($object)); 01300 }
_collectSaveData | ( | $ | newObject | ) | [protected] |
Prepare entity object data for save
result array structure: array ( 'newObject', 'entityRow', 'insert', 'update', 'delete' )
Varien_Object | $newObject |
get current data in db for this entity
drop attributes that are unknown in new data not needed after introduction of partial entity loading
Check attribute information
if attribute is static add to entity row and continue
Check comparability for attribute value
Definition at line 938 of file Abstract.php.
00939 { 00940 $newData = $newObject->getData(); 00941 $entityId = $newObject->getData($this->getEntityIdField()); 00942 if (!empty($entityId)) { 00943 /** 00944 * get current data in db for this entity 00945 */ 00946 /*$className = get_class($newObject); 00947 $origObject = new $className(); 00948 $origObject->setData(array()); 00949 $this->load($origObject, $entityId); 00950 $origData = $origObject->getOrigData();*/ 00951 $origData = $this->_getOrigObject($newObject)->getOrigData(); 00952 00953 /** 00954 * drop attributes that are unknown in new data 00955 * not needed after introduction of partial entity loading 00956 */ 00957 foreach ($origData as $k=>$v) { 00958 if (!array_key_exists($k, $newData)) { 00959 unset($origData[$k]); 00960 } 00961 } 00962 } 00963 00964 foreach ($newData as $k=>$v) { 00965 /** 00966 * Check attribute information 00967 */ 00968 if (is_numeric($k) || is_array($v)) { 00969 continue; 00970 throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Invalid data object key')); 00971 } 00972 00973 $attribute = $this->getAttribute($k); 00974 if (empty($attribute)) { 00975 continue; 00976 } 00977 00978 $attrId = $attribute->getAttributeId(); 00979 00980 /** 00981 * if attribute is static add to entity row and continue 00982 */ 00983 if ($this->isAttributeStatic($k)) { 00984 $entityRow[$k] = $this->_prepareStaticValue($k, $v); 00985 continue; 00986 } 00987 00988 /** 00989 * Check comparability for attribute value 00990 */ 00991 if (isset($origData[$k])) { 00992 if ($attribute->isValueEmpty($v)) { 00993 $delete[$attribute->getBackend()->getTable()][] = array( 00994 'attribute_id' => $attrId, 00995 'value_id' => $attribute->getBackend()->getValueId() 00996 ); 00997 } 00998 elseif ($v!==$origData[$k]) { 00999 $update[$attrId] = array( 01000 'value_id' => $attribute->getBackend()->getValueId(), 01001 'value' => $v, 01002 ); 01003 } 01004 } 01005 elseif (!$attribute->isValueEmpty($v)) { 01006 $insert[$attrId] = $v; 01007 } 01008 } 01009 01010 $result = compact('newObject', 'entityRow', 'insert', 'update', 'delete'); 01011 return $result; 01012 }
_construct | ( | ) | [protected] |
Resource initialization
Reimplemented from Mage_Core_Model_Resource_Abstract.
Definition at line 161 of file Abstract.php.
_deleteAttributes | ( | $ | object, | |
$ | table, | |||
$ | info | |||
) | [protected] |
Delete entity attribute values
Varien_Object | $object | |
string | $table | |
array | $info |
Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Abstract.
Definition at line 1183 of file Abstract.php.
01184 { 01185 $valueIds = array(); 01186 foreach ($info as $itemData) { 01187 $valueIds[] = $itemData['value_id']; 01188 } 01189 if (!empty($valueIds)) { 01190 $condition = $this->_getWriteAdapter()->quoteInto('value_id IN (?)', $valueIds); 01191 $this->_getWriteAdapter()->delete($table, $condition); 01192 } 01193 return $this; 01194 }
_getDefaultAttributeModel | ( | ) | [protected] |
Retrieve Default attribute model
Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Abstract.
Definition at line 1337 of file Abstract.php.
01338 { 01339 return Mage_Eav_Model_Entity::DEFAULT_ATTRIBUTE_MODEL; 01340 }
_getDefaultAttributes | ( | ) | [protected] |
Retrieve default entity attributes
Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Product, and Mage_Customer_Model_Entity_Customer.
Definition at line 1347 of file Abstract.php.
01348 { 01349 return array('entity_type_id', 'attribute_set_id', 'created_at', 'updated_at', 'parent_id', 'increment_id'); 01350 }
_getLoadAttributesSelect | ( | $ | object, | |
$ | table | |||
) | [protected] |
Retrieve select object for loading entity attributes values
Varien_Object | $object | |
mixed | $rowId |
Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Abstract.
Definition at line 864 of file Abstract.php.
00865 { 00866 $select = $this->_read->select() 00867 ->from($table) 00868 ->where($this->getEntityIdField() . '=?', $object->getId()); 00869 return $select; 00870 }
_getLoadRowSelect | ( | $ | object, | |
$ | rowId | |||
) | [protected] |
Retrieve select object for loading base entity row
Varien_Object | $object | |
mixed | $rowId |
Reimplemented in Mage_Customer_Model_Entity_Customer, and Mage_Sales_Model_Entity_Quote.
Definition at line 848 of file Abstract.php.
00849 { 00850 $select = $this->_read->select() 00851 ->from($this->getEntityTable()) 00852 ->where($this->getEntityIdField()."=?", $rowId); 00853 00854 return $select; 00855 }
_getOrigObject | ( | $ | object | ) | [protected] |
Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Abstract.
Definition at line 918 of file Abstract.php.
00919 { 00920 $className = get_class($object); 00921 $origObject = new $className(); 00922 $origObject->setData(array()); 00923 $this->load($origObject, $object->getData($this->getEntityIdField())); 00924 return $origObject; 00925 }
_getReadAdapter | ( | ) | [protected] |
Retrieve connection for read data
Reimplemented from Mage_Core_Model_Resource_Abstract.
Definition at line 171 of file Abstract.php.
_getStaticFieldProperties | ( | $ | field | ) | [protected] |
Retrieve static field properties
string | $field |
Definition at line 1020 of file Abstract.php.
01021 { 01022 if (empty($this->_describeTable[$this->getEntityTable()])) { 01023 $this->_describeTable[$this->getEntityTable()] = $this->_getWriteAdapter()->describeTable($this->getEntityTable()); 01024 } 01025 01026 if (isset($this->_describeTable[$this->getEntityTable()][$field])) { 01027 return $this->_describeTable[$this->getEntityTable()][$field]; 01028 } 01029 01030 return false; 01031 }
_getWriteAdapter | ( | ) | [protected] |
Retrieve connection for write data
Reimplemented from Mage_Core_Model_Resource_Abstract.
Definition at line 181 of file Abstract.php.
_insertAttribute | ( | $ | object, | |
$ | attribute, | |||
$ | value | |||
) | [protected] |
Insert entity attribute value
Varien_Object | $object | |
Mage_Eav_Model_Entity_Attribute_Abstract | $attribute | |
mixed | $value |
Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Abstract.
Definition at line 1129 of file Abstract.php.
01130 { 01131 $entityIdField = $attribute->getBackend()->getEntityIdField(); 01132 $row = array( 01133 $entityIdField => $object->getId(), 01134 'entity_type_id'=> $object->getEntityTypeId(), 01135 'attribute_id' => $attribute->getId(), 01136 'value' => $this->_prepareValueForSave($value, $attribute), 01137 ); 01138 $this->_getWriteAdapter()->insert($attribute->getBackend()->getTable(), $row); 01139 return $this; 01140 }
_isApplicableAttribute | ( | $ | object, | |
$ | attribute | |||
) | [protected] |
Check whether the attribute is Applicable to the object
Varien_Object | $object | |
Mage_Eav_Model_Entity_Attribute_Abstract | $attribute |
Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Abstract.
Definition at line 530 of file Abstract.php.
_prepareStaticValue | ( | $ | key, | |
$ | value | |||
) | [protected] |
Prepare static value for save
string | $key | |
mixed | $value |
Definition at line 1040 of file Abstract.php.
01041 { 01042 $fieldProp = $this->_getStaticFieldProperties($key); 01043 01044 if (!$fieldProp) { 01045 return $value; 01046 } 01047 01048 if ($fieldProp['DATA_TYPE'] == 'decimal') { 01049 $value = Mage::app()->getLocale()->getNumber($value); 01050 } 01051 01052 return $value; 01053 }
_prepareValueForSave | ( | $ | value, | |
Mage_Eav_Model_Entity_Attribute_Abstract $ | attribute | |||
) | [protected] |
Prepare value for save
mixed | $value | |
Mage_Eav_Model_Entity_Attribute_Abstract | $attribute |
Definition at line 1167 of file Abstract.php.
01168 { 01169 if ($attribute->getBackendType() == 'decimal') { 01170 return Mage::app()->getLocale()->getNumber($value); 01171 } 01172 return $value; 01173 }
_processSaveData | ( | $ | saveData | ) | [protected] |
Save object collected data
array | $saveData array('newObject', 'entityRow', 'insert', 'update', 'delete') |
Process base row
insert attribute values
update attribute values
delete empty attribute values
Definition at line 1061 of file Abstract.php.
01062 { 01063 extract($saveData); 01064 $insertEntity = true; 01065 $entityIdField = $this->getEntityIdField(); 01066 $entityId = $newObject->getId(); 01067 $condition = $this->_getWriteAdapter()->quoteInto("$entityIdField=?", $entityId); 01068 01069 if (!empty($entityId)) { 01070 $select = $this->_getWriteAdapter()->select() 01071 ->from($this->getEntityTable(), $entityIdField) 01072 ->where($condition); 01073 if ($this->_getWriteAdapter()->fetchOne($select)) { 01074 $insertEntity = false; 01075 } 01076 } 01077 01078 /** 01079 * Process base row 01080 */ 01081 if ($insertEntity) { 01082 $this->_getWriteAdapter()->insert($this->getEntityTable(), $entityRow); 01083 $entityId = $this->_getWriteAdapter()->lastInsertId(); 01084 $newObject->setId($entityId); 01085 } else { 01086 $this->_getWriteAdapter()->update($this->getEntityTable(), $entityRow, $condition); 01087 } 01088 01089 /** 01090 * insert attribute values 01091 */ 01092 if (!empty($insert)) { 01093 foreach ($insert as $attrId=>$value) { 01094 $attribute = $this->getAttribute($attrId); 01095 $this->_insertAttribute($newObject, $attribute, $value); 01096 } 01097 } 01098 01099 /** 01100 * update attribute values 01101 */ 01102 if (!empty($update)) { 01103 foreach ($update as $attrId=>$v) { 01104 $attribute = $this->getAttribute($attrId); 01105 $this->_updateAttribute($newObject, $attribute, $v['value_id'], $v['value']); 01106 } 01107 } 01108 01109 /** 01110 * delete empty attribute values 01111 */ 01112 if (!empty($delete)) { 01113 foreach ($delete as $table=>$values) { 01114 $this->_deleteAttributes($newObject, $table, $values); 01115 } 01116 } 01117 01118 return $this; 01119 }
_setAttribteValue | ( | $ | object, | |
$ | valueRow | |||
) | [protected] |
Initialize attribute value for object
Varien_Object | $object | |
array | $valueRow |
Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Abstract.
Definition at line 879 of file Abstract.php.
00880 { 00881 if ($attribute = $this->getAttribute($valueRow['attribute_id'])) { 00882 $attributeCode = $attribute->getAttributeCode(); 00883 $object->setData($attributeCode, $valueRow['value']); 00884 $attribute->getBackend()->setValueId($valueRow['value_id']); 00885 } 00886 return $this; 00887 }
_updateAttribute | ( | $ | object, | |
$ | attribute, | |||
$ | valueId, | |||
$ | value | |||
) | [protected] |
Update entity attribute value
Varien_Object | $object | |
Mage_Eav_Model_Entity_Attribute_Abstract | $attribute | |
mixed | $valueId | |
mixed | $value |
Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Abstract.
Definition at line 1151 of file Abstract.php.
01152 { 01153 $this->_getWriteAdapter()->update($attribute->getBackend()->getTable(), 01154 array('value' => $this->_prepareValueForSave($value, $attribute)), 01155 'value_id='.(int)$valueId 01156 ); 01157 return $this; 01158 }
addAttribute | ( | Mage_Eav_Model_Entity_Attribute_Abstract $ | attribute | ) |
Adding attribute to entity
Mage_Eav_Model_Entity_Attribute_Abstract | $attribute |
Definition at line 395 of file Abstract.php.
00396 { 00397 $attribute->setEntity($this); 00398 $attributeCode = $attribute->getAttributeCode(); 00399 00400 $this->_attributesByCode[$attributeCode] = $attribute; 00401 00402 if ($attribute->isStatic()) { 00403 $this->_staticAttributes[$attributeCode] = $attribute; 00404 } else { 00405 $this->_attributesById[$attribute->getId()] = $attribute; 00406 $this->_attributesByTable[$attribute->getBackendTable()][$attributeCode] = $attribute; 00407 } 00408 return $this; 00409 }
attributesCompare | ( | $ | attribute1, | |
$ | attribute2 | |||
) |
Definition at line 506 of file Abstract.php.
00507 { 00508 $sortPath = 'attribute_set_info/' . $this->_sortingSetId . '/sort'; 00509 $groupSortPath = 'attribute_set_info/' . $this->_sortingSetId . '/group_sort'; 00510 00511 $sort1 = ($attribute1->getData($groupSortPath) * 1000) + ($attribute1->getData($sortPath) * 0.0001); 00512 $sort2 = ($attribute2->getData($groupSortPath) * 1000) + ($attribute2->getData($sortPath) * 0.0001); 00513 00514 if ($sort1 > $sort2) { 00515 return 1; 00516 } elseif ($sort1 < $sort2) { 00517 return -1; 00518 } 00519 00520 return 0; 00521 }
checkAttributeUniqueValue | ( | Mage_Eav_Model_Entity_Attribute_Abstract $ | attribute, | |
$ | object | |||
) |
Enter description here...
Mage_Eav_Model_Entity_Attribute_Abstract | $attribute | |
Varien_Object | $object |
Definition at line 752 of file Abstract.php.
00753 { 00754 if ($attribute->getBackend()->getType()==='static') { 00755 $select = $this->_getWriteAdapter()->select() 00756 ->from($this->getEntityTable(), $this->getEntityIdField()) 00757 ->where('entity_type_id=?', $this->getTypeId()) 00758 ->where($attribute->getAttributeCode().'=?', $object->getData($attribute->getAttributeCode())); 00759 } else { 00760 $select = $this->_getWriteAdapter()->select() 00761 ->from($attribute->getBackend()->getTable(), $attribute->getBackend()->getEntityIdField()) 00762 ->where('entity_type_id=?', $this->getTypeId()) 00763 ->where('attribute_id=?', $attribute->getId()) 00764 ->where('value=?', $object->getData($attribute->getAttributeCode())); 00765 } 00766 $data = $this->_getWriteAdapter()->fetchCol($select); 00767 00768 if ($object->getId()) { 00769 if (isset($data[0])) { 00770 return $data[0] == $object->getId(); 00771 } 00772 return true; 00773 } 00774 else { 00775 return !count($data); 00776 } 00777 }
delete | ( | $ | object | ) |
Delete entity using current object's data
Definition at line 1258 of file Abstract.php.
01259 { 01260 if (is_numeric($object)) { 01261 $id = (int)$object; 01262 } elseif ($object instanceof Varien_Object) { 01263 $id = (int)$object->getId(); 01264 } 01265 01266 $this->_beforeDelete($object); 01267 01268 try { 01269 $this->_getWriteAdapter()->delete($this->getEntityTable(), $this->getEntityIdField()."=".$id); 01270 $this->loadAllAttributes($object); 01271 foreach ($this->getAttributesByTable() as $table=>$attributes) { 01272 $this->_getWriteAdapter()->delete($table, $this->getEntityIdField()."=".$id); 01273 } 01274 } catch (Exception $e) { 01275 throw $e; 01276 } 01277 01278 $this->_afterDelete($object); 01279 return $this; 01280 }
getAttribute | ( | $ | attribute | ) |
Retrieve attribute instance by name, id or config node
This will add the attribute configuration to entity's attributes cache
If attribute is not found false is returned
string|integer|Mage_Core_Model_Config_Element | $attribute |
Definition at line 325 of file Abstract.php.
00326 { 00327 if (is_numeric($attribute)) { 00328 $attributeId = $attribute; 00329 00330 if (isset($this->_attributesById[$attributeId])) { 00331 return $this->_attributesById[$attributeId]; 00332 } 00333 $attributeInstance = Mage::getSingleton('eav/config')->getAttribute($this->getEntityType(), $attributeId); 00334 if ($attributeInstance) { 00335 $attributeCode = $attributeInstance->getAttributeCode(); 00336 } 00337 00338 } elseif (is_string($attribute)) { 00339 $attributeCode = $attribute; 00340 00341 if (isset($this->_attributesByCode[$attributeCode])) { 00342 return $this->_attributesByCode[$attributeCode]; 00343 } 00344 $attributeInstance = Mage::getSingleton('eav/config') 00345 ->getAttribute($this->getEntityType(), $attributeCode); 00346 if (!$attributeInstance->getAttributeCode() && in_array($attribute, $this->getDefaultAttributes())) { 00347 $attributeInstance 00348 ->setAttributeCode($attribute) 00349 ->setBackendType(Mage_Eav_Model_Entity_Attribute_Abstract::TYPE_STATIC) 00350 ->setIsGlobal(1) 00351 ->setEntity($this) 00352 ->setEntityType($this->getEntityType()) 00353 ->setEntityTypeId($this->getEntityType()->getId()); 00354 } 00355 } elseif ($attribute instanceof Mage_Eav_Model_Entity_Attribute_Abstract) { 00356 00357 $attributeInstance = $attribute; 00358 $attributeCode = $attributeInstance->getAttributeCode(); 00359 if (isset($this->_attributesByCode[$attributeCode])) { 00360 return $this->_attributesByCode[$attributeCode]; 00361 } 00362 } 00363 00364 if (empty($attributeInstance) 00365 || !($attributeInstance instanceof Mage_Eav_Model_Entity_Attribute_Abstract) 00366 || (!$attributeInstance->getId() && !in_array($attributeInstance->getAttributeCode(), $this->getDefaultAttributes())) 00367 ) { 00368 return false; 00369 } 00370 00371 $attribute = $attributeInstance; 00372 00373 if (empty($attributeId)) { 00374 $attributeId = $attribute->getAttributeId(); 00375 } 00376 00377 if (!$attribute->getAttributeCode()) { 00378 $attribute->setAttributeCode($attributeCode); 00379 } 00380 if (!$attribute->getAttributeModel()) { 00381 $attribute->setAttributeModel($this->_getDefaultAttributeModel()); 00382 } 00383 00384 $this->addAttribute($attribute); 00385 00386 return $attribute; 00387 }
getAttributesByCode | ( | ) |
getAttributesById | ( | ) |
getAttributesByTable | ( | ) |
getDefaultAttributes | ( | ) |
Retrieve default entity static attributes
Definition at line 1357 of file Abstract.php.
01357 { 01358 return array_unique(array_merge($this->_getDefaultAttributes(), array($this->getEntityIdField()))); 01359 }
getDefaultAttributeSourceModel | ( | ) |
Enter description here...
Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Product.
Definition at line 784 of file Abstract.php.
00785 { 00786 return Mage_Eav_Model_Entity::DEFAULT_SOURCE_MODEL; 00787 }
getEntityIdField | ( | ) |
Get entity id field name in entity table
Definition at line 654 of file Abstract.php.
00655 { 00656 if (empty($this->_entityIdField)) { 00657 $this->_entityIdField = $this->getEntityType()->getEntityIdField(); 00658 if (empty($this->_entityIdField)) { 00659 $this->_entityIdField = Mage_Eav_Model_Entity::DEFAULT_ENTITY_ID_FIELD; 00660 } 00661 } 00662 return $this->_entityIdField; 00663 }
getEntityTable | ( | ) |
Get entity table name
Definition at line 637 of file Abstract.php.
00638 { 00639 if (empty($this->_entityTable)) { 00640 $table = $this->getEntityType()->getEntityTable(); 00641 if (empty($table)) { 00642 $table = Mage_Eav_Model_Entity::DEFAULT_ENTITY_TABLE; 00643 } 00644 $this->_entityTable = Mage::getSingleton('core/resource')->getTableName($table); 00645 } 00646 return $this->_entityTable; 00647 }
getEntityType | ( | ) |
Retrieve current entity config
Definition at line 247 of file Abstract.php.
00248 { 00249 if (empty($this->_type)) { 00250 throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Entity is not initialized')); 00251 } 00252 return $this->_type; 00253 }
getIdFieldName | ( | ) |
For compatibility with Mage_Core_Model_Abstract
Definition at line 211 of file Abstract.php.
00212 { 00213 return $this->getEntityIdField(); 00214 }
getReadConnection | ( | ) |
Retrieve read DB connection
Definition at line 191 of file Abstract.php.
00192 { 00193 return $this->_getReadAdapter(); 00194 }
getSortedAttributes | ( | $ | setId = null |
) |
Retrieve sorted attributes
int | $setId |
Definition at line 483 of file Abstract.php.
00484 { 00485 $attributes = $this->getAttributesByCode(); 00486 if (is_null($setId)) { 00487 $setId = $this->getEntityType()->getDefaultAttributeSetId(); 00488 } 00489 00490 // initialize set info 00491 Mage::getSingleton('eav/entity_attribute_set') 00492 ->addSetInfo($this->getEntityType(), $attributes, $setId); 00493 00494 foreach ($attributes as $code => $attribute) { 00495 /* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */ 00496 if (!$attribute->isInSet($setId)) { 00497 unset($attributes[$code]); 00498 } 00499 } 00500 00501 $this->_sortingSetId = $setId; 00502 uasort($attributes, array($this, 'attributesCompare')); 00503 return $attributes; 00504 }
getTable | ( | $ | alias | ) |
Enter description here...
string | $alias |
Definition at line 222 of file Abstract.php.
00223 { 00224 return Mage::getSingleton('core/resource')->getTableName($alias); 00225 }
getType | ( | ) |
Get entity type name
Definition at line 260 of file Abstract.php.
00261 { 00262 return $this->getEntityType()->getEntityTypeCode(); 00263 }
getTypeId | ( | ) |
Get entity type id
Definition at line 270 of file Abstract.php.
00271 { 00272 return (int)$this->getEntityType()->getEntityTypeId(); 00273 }
getValueEntityIdField | ( | ) |
Get default entity id field name in attribute values tables
Definition at line 670 of file Abstract.php.
00671 { 00672 return $this->getEntityIdField(); 00673 }
getValueTablePrefix | ( | ) |
Get prefix for value tables
entity type prefix include DB table name prefix
Definition at line 680 of file Abstract.php.
00681 { 00682 if (empty($this->_valueTablePrefix)) { 00683 $prefix = (string)$this->getEntityType()->getValueTablePrefix(); 00684 if (!empty($prefix)) { 00685 $this->_valueTablePrefix = $prefix; 00686 /** 00687 * entity type prefix include DB table name prefix 00688 */ 00689 //Mage::getSingleton('core/resource')->getTableName($prefix); 00690 } else { 00691 $this->_valueTablePrefix = $this->getEntityTable(); 00692 } 00693 } 00694 return $this->_valueTablePrefix; 00695 }
getWriteConnection | ( | ) |
Retrieve write DB connection
Definition at line 201 of file Abstract.php.
00202 { 00203 return $this->_getWriteAdapter(); 00204 }
isAttributeStatic | ( | $ | attribute | ) |
Check whether the attribute is a real field in entity table
integer|string|Mage_Eav_Model_Entity_Attribute_Abstract | $attribute |
Definition at line 704 of file Abstract.php.
00705 { 00706 $attrInstance = $this->getAttribute($attribute); 00707 return $attrInstance && $attrInstance->getBackend()->isStatic(); 00708 }
isPartialLoad | ( | $ | flag = null |
) |
Enter description here...
boolean | $flag |
Definition at line 417 of file Abstract.php.
00418 { 00419 $result = $this->_isPartialLoad; 00420 if (!is_null($flag)) { 00421 $this->_isPartialLoad = $flag; 00422 } 00423 return $result; 00424 }
isPartialSave | ( | $ | flag = null |
) |
Enter description here...
boolean | $flag |
Definition at line 432 of file Abstract.php.
00433 { 00434 $result = $this->_isPartialSave; 00435 if (!is_null($flag)) { 00436 $this->_isPartialSave = $flag; 00437 } 00438 return $result; 00439 }
load | ( | $ | object, | |
$ | entityId, | |||
$ | attributes = array() | |||
) |
Load entity's attributes into the object
Varien_Object | $object | |
integer | $entityId | |
array|null | $attributes |
Load object base row data
Load data for entity attributes
Definition at line 797 of file Abstract.php.
00798 { 00799 Varien_Profiler::start('__EAV_LOAD_MODEL__'); 00800 /** 00801 * Load object base row data 00802 */ 00803 $select = $this->_getLoadRowSelect($object, $entityId); 00804 $row = $this->_getReadAdapter()->fetchRow($select); 00805 //$object->setData($row); 00806 if (is_array($row)) { 00807 $object->addData($row); 00808 } 00809 00810 if (empty($attributes)) { 00811 $this->loadAllAttributes($object); 00812 } else { 00813 foreach ($attributes as $attrCode) { 00814 $this->getAttribute($attrCode); 00815 } 00816 } 00817 00818 /** 00819 * Load data for entity attributes 00820 */ 00821 Varien_Profiler::start('__EAV_LOAD_MODEL_ATTRIBUTES__'); 00822 foreach ($this->getAttributesByTable() as $table=>$attributes) { 00823 $select = $this->_getLoadAttributesSelect($object, $table); 00824 $values = $this->_getReadAdapter()->fetchAll($select); 00825 00826 foreach ($values as $valueRow) { 00827 $this->_setAttribteValue($object, $valueRow); 00828 } 00829 } 00830 Varien_Profiler::stop('__EAV_LOAD_MODEL_ATTRIBUTES__'); 00831 00832 $object->setOrigData(); 00833 Varien_Profiler::start('__EAV_LOAD_MODEL_AFTER_LOAD__'); 00834 $this->_afterLoad($object); 00835 Varien_Profiler::stop('__EAV_LOAD_MODEL_AFTER_LOAD__'); 00836 00837 Varien_Profiler::stop('__EAV_LOAD_MODEL__'); 00838 return $this; 00839 }
loadAllAttributes | ( | $ | object = null |
) |
Retrieve configuration for all attributes
Check and init default attributes
Definition at line 446 of file Abstract.php.
00447 { 00448 $attributeCodes = Mage::getSingleton('eav/config') 00449 ->getEntityAttributeCodes($this->getEntityType(), $object); 00450 00451 /** 00452 * Check and init default attributes 00453 */ 00454 $defaultAttributes = $this->getDefaultAttributes(); 00455 foreach ($defaultAttributes as $attributeCode) { 00456 $attributeIndex = array_search($attributeCode, $attributeCodes); 00457 if ($attributeIndex !== false) { 00458 $this->getAttribute($attributeCodes[$attributeIndex]); 00459 unset($attributeCodes[$attributeIndex]); 00460 } else { 00461 $attribute = Mage::getModel($this->getEntityType()->getAttributeModel()); 00462 $attribute->setAttributeCode($attributeCode) 00463 ->setBackendType('static') 00464 ->setEntityType($this->getEntityType()) 00465 ->setEntityTypeId($this->getEntityType()->getId()); 00466 $this->addAttribute($attribute); 00467 } 00468 } 00469 00470 foreach ($attributeCodes as $code) { 00471 $this->getAttribute($code); 00472 } 00473 00474 return $this; 00475 }
save | ( | Varien_Object $ | object | ) |
Save entity's attributes into the object's resource
Varien_Object | $object |
Definition at line 895 of file Abstract.php.
00896 { 00897 if ($object->isDeleted()) { 00898 return $this->delete($object); 00899 } 00900 00901 if (!$this->isPartialSave()) { 00902 $this->loadAllAttributes($object); 00903 } 00904 00905 if (!$object->getEntityTypeId()) { 00906 $object->setEntityTypeId($this->getTypeId()); 00907 } 00908 00909 $object->setParentId((int) $object->getParentId()); 00910 00911 $this->_beforeSave($object); 00912 $this->_processSaveData($this->_collectSaveData($object)); 00913 $this->_afterSave($object); 00914 00915 return $this; 00916 }
saveAttribute | ( | Varien_Object $ | object, | |
$ | attributeCode | |||
) |
Save attribute
Varien_Object | $object | |
string | $attributeCode |
Definition at line 1203 of file Abstract.php.
01204 { 01205 $attribute = $this->getAttribute($attributeCode); 01206 $backend = $attribute->getBackend(); 01207 $table = $backend->getTable(); 01208 $entity = $attribute->getEntity(); 01209 $entityIdField = $entity->getEntityIdField(); 01210 01211 $row = array( 01212 'entity_type_id' => $entity->getTypeId(), 01213 'attribute_id' => $attribute->getId(), 01214 $entityIdField=> $object->getData($entityIdField), 01215 ); 01216 01217 $newValue = $object->getData($attributeCode); 01218 if ($attribute->isValueEmpty($newValue)) { 01219 $newValue = null; 01220 } 01221 01222 $whereArr = array(); 01223 foreach ($row as $field => $value) { 01224 $whereArr[] = $this->_read->quoteInto("$field=?", $value); 01225 } 01226 $where = '('.join(') AND (', $whereArr).')'; 01227 01228 $this->_getWriteAdapter()->beginTransaction(); 01229 01230 try { 01231 $select = $this->_getWriteAdapter()->select() 01232 ->from($table, 'value_id') 01233 ->where($where); 01234 $origValueId = $this->_getWriteAdapter()->fetchOne($select); 01235 01236 if ($origValueId === false && !is_null($newValue)) { 01237 $this->_insertAttribute($object, $attribute, $newValue); 01238 $backend->setValueId($this->_getWriteAdapter()->lastInsertId()); 01239 } elseif ($origValueId !== false && !is_null($newValue)) { 01240 $this->_updateAttribute($object, $attribute, $origValueId, $newValue); 01241 } elseif ($origValueId !== false && is_null($newValue)) { 01242 $this->_getWriteAdapter()->delete($table, $where); 01243 } 01244 $this->_getWriteAdapter()->commit(); 01245 } catch (Exception $e) { 01246 $this->_getWriteAdapter()->rollback(); 01247 throw $e; 01248 } 01249 01250 return $this; 01251 }
setConnection | ( | Zend_Db_Adapter_Abstract $ | read, | |
Zend_Db_Adapter_Abstract $ | write = null | |||
) |
Set connections for entity operations
Zend_Db_Adapter_Abstract | $read | |
Zend_Db_Adapter_Abstract | $write |
Definition at line 151 of file Abstract.php.
00152 { 00153 $this->_read = $read; 00154 $this->_write = $write ? $write : $read; 00155 return $this; 00156 }
setNewIncrementId | ( | Varien_Object $ | object | ) |
Enter description here...
Varien_Object | $object |
Definition at line 730 of file Abstract.php.
00731 { 00732 if ($object->getIncrementId()) { 00733 return $this; 00734 } 00735 00736 $incrementId = $this->getEntityType()->fetchNewIncrementId($object->getStoreId()); 00737 00738 if (false!==$incrementId) { 00739 $object->setIncrementId($incrementId); 00740 } 00741 00742 return $this; 00743 }
setType | ( | $ | type | ) |
Set configuration for the entity
Accepts config node or name of entity type
string|Mage_Eav_Model_Entity_Type | $type |
Definition at line 235 of file Abstract.php.
00236 { 00237 $this->_type = Mage::getSingleton('eav/config')->getEntityType($type); 00238 $this->_afterSetConfig(); 00239 return $this; 00240 }
unsetAttributes | ( | $ | attributes = null |
) |
Unset attributes
If NULL or not supplied removes configuration of all attributes If string - removes only one, if array - all specified
array|string|null | $attributes |
Definition at line 284 of file Abstract.php.
00285 { 00286 if (is_null($attributes)) { 00287 $this->_attributesByCode = array(); 00288 $this->_attributesById = array(); 00289 $this->_attributesByTable = array(); 00290 return $this; 00291 } 00292 00293 if (is_string($attributes)) { 00294 $attributes = array($attributes); 00295 } 00296 00297 if (!is_array($attributes)) { 00298 throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Unknown parameter')); 00299 } 00300 00301 foreach ($attributes as $attrCode) { 00302 if (!isset($this->_attributesByCode[$attrCode])) { 00303 continue; 00304 } 00305 00306 $attr = $this->getAttribute($attrCode); 00307 unset($this->_attributesById[$attr->getId()]); 00308 unset($this->_attributesByTable[$attr->getBackend()->getTable()][$attrCode]); 00309 unset($this->_attributesByCode[$attrCode]); 00310 } 00311 00312 return $this; 00313 }
validate | ( | $ | object | ) |
Validate all object's attributes against configuration
Varien_Object | $object |
Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Product.
Definition at line 716 of file Abstract.php.
00717 { 00718 $this->loadAllAttributes($object); 00719 $this->walkAttributes('backend/validate', array($object)); 00720 00721 return $this; 00722 }
Walk through the attributes and run method with optional arguments
Returns array with results for each attribute
if $method is in format "part/method" will run method on specified part for example: $this->walkAttributes('backend/validate');
string | $method | |
array | $args | |
array | $part attribute, backend, frontend, source |
Definition at line 548 of file Abstract.php.
00549 { 00550 $methodArr = explode('/', $partMethod); 00551 switch (sizeof($methodArr)) { 00552 case 1: 00553 $part = 'attribute'; 00554 $method = $methodArr[0]; 00555 break; 00556 00557 case 2: 00558 $part = $methodArr[0]; 00559 $method = $methodArr[1]; 00560 break; 00561 } 00562 $results = array(); 00563 foreach ($this->getAttributesByCode() as $attrCode=>$attribute) { 00564 00565 if (isset($args[0]) && is_object($args[0]) && !$this->_isApplicableAttribute($args[0], $attribute)) { 00566 continue; 00567 } 00568 00569 switch ($part) { 00570 case 'attribute': 00571 $instance = $attribute; 00572 break; 00573 00574 case 'backend': 00575 $instance = $attribute->getBackend(); 00576 break; 00577 00578 case 'frontend': 00579 $instance = $attribute->getFrontend(); 00580 break; 00581 00582 case 'source': 00583 $instance = $attribute->getSource(); 00584 break; 00585 } 00586 00587 try { 00588 $results[$attrCode] = call_user_func_array(array($instance, $method), $args); 00589 } 00590 catch (Mage_Eav_Model_Entity_Attribute_Exception $e) { 00591 throw $e; 00592 } 00593 catch (Exception $e) { 00594 $exception = new Mage_Eav_Model_Entity_Attribute_Exception($e->getMessage()); 00595 $exception->setAttributeCode($attrCode)->setPart($part); 00596 throw $exception; 00597 } 00598 } 00599 return $results; 00600 }
$_attributesByCode = array() [protected] |
Definition at line 72 of file Abstract.php.
$_attributesById = array() [protected] |
Definition at line 65 of file Abstract.php.
$_attributesByTable = array() [protected] |
Definition at line 79 of file Abstract.php.
$_describeTable = array() [protected] |
Definition at line 100 of file Abstract.php.
$_entityIdField [protected] |
Definition at line 107 of file Abstract.php.
$_entityTable [protected] |
Definition at line 93 of file Abstract.php.
$_isPartialLoad = false [protected] |
Definition at line 128 of file Abstract.php.
$_isPartialSave = false [protected] |
Definition at line 135 of file Abstract.php.
$_read [protected] |
Definition at line 44 of file Abstract.php.
$_sortingSetId = null [protected] |
Definition at line 142 of file Abstract.php.
$_staticAttributes = array() [protected] |
Definition at line 86 of file Abstract.php.
$_type [protected] |
Definition at line 58 of file Abstract.php.
$_valueEntityIdField [protected] |
Definition at line 114 of file Abstract.php.
$_valueTablePrefix [protected] |
Definition at line 121 of file Abstract.php.
$_write [protected] |
Definition at line 51 of file Abstract.php.