Definition at line 36 of file Abstract.php.
_afterDelete | ( | Mage_Core_Model_Abstract $ | object | ) | [protected] |
Perform actions after object delete
Varien_Object | $object |
Reimplemented in Mage_Admin_Model_Mysql4_Roles, Mage_Api_Model_Mysql4_Roles, Mage_Bundle_Model_Mysql4_Option, Mage_Core_Model_Mysql4_Store, Mage_Core_Model_Mysql4_Website, Mage_Customer_Model_Entity_Group, and Mage_Review_Model_Mysql4_Review.
Definition at line 597 of file Abstract.php.
_afterLoad | ( | Mage_Core_Model_Abstract $ | object | ) | [protected] |
Perform actions after object load
Varien_Object | $object |
Reimplemented in Mage_Admin_Model_Mysql4_User, Mage_Checkout_Model_Mysql4_Agreement, Mage_Cms_Model_Mysql4_Block, Mage_Cms_Model_Mysql4_Page, Mage_Core_Model_Mysql4_Translate_String, Mage_Rating_Model_Mysql4_Rating, and Mage_Review_Model_Mysql4_Review.
Definition at line 557 of file Abstract.php.
_afterSave | ( | Mage_Core_Model_Abstract $ | object | ) | [protected] |
Perform actions after object save
Varien_Object | $object |
Reimplemented in Mage_Admin_Model_Mysql4_Roles, Mage_Admin_Model_Mysql4_User, Mage_Api_Model_Mysql4_Roles, Mage_Bundle_Model_Mysql4_Option, Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Option_Value, Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Option, Mage_Checkout_Model_Mysql4_Agreement, Mage_Cms_Model_Mysql4_Block, Mage_Cms_Model_Mysql4_Page, Mage_Core_Model_Mysql4_Store_Group, Mage_Core_Model_Mysql4_Store, Mage_Core_Model_Mysql4_Translate_String, Mage_Core_Model_Mysql4_Website, Mage_Eav_Model_Mysql4_Entity_Attribute_Group, Mage_Eav_Model_Mysql4_Entity_Attribute_Set, Mage_Eav_Model_Mysql4_Entity_Attribute, Mage_Log_Model_Mysql4_Visitor, Mage_Newsletter_Model_Mysql4_Queue, Mage_Poll_Model_Mysql4_Poll_Vote, Mage_Poll_Model_Mysql4_Poll, Mage_Rating_Model_Mysql4_Rating, and Mage_Review_Model_Mysql4_Review.
Definition at line 577 of file Abstract.php.
_beforeDelete | ( | Mage_Core_Model_Abstract $ | object | ) | [protected] |
Perform actions before object delete
Varien_Object | $object |
Reimplemented in Mage_Customer_Model_Entity_Group, and Mage_Review_Model_Mysql4_Review.
Definition at line 587 of file Abstract.php.
_beforeSave | ( | Mage_Core_Model_Abstract $ | object | ) | [protected] |
Perform actions before object save
Varien_Object | $object |
Reimplemented in Mage_Admin_Model_Mysql4_Role, Mage_Admin_Model_Mysql4_Roles, Mage_Admin_Model_Mysql4_User, Mage_Api_Model_Mysql4_Acl_Role, Mage_Api_Model_Mysql4_Role, Mage_Api_Model_Mysql4_Roles, Mage_Api_Model_Mysql4_User, Mage_CatalogRule_Model_Mysql4_Rule, Mage_CatalogSearch_Model_Mysql4_Query, Mage_Checkout_Model_Mysql4_Agreement, Mage_Cms_Model_Mysql4_Block, Mage_Cms_Model_Mysql4_Page, Mage_Core_Model_Mysql4_Config_Data, Mage_Core_Model_Mysql4_Convert_History, Mage_Core_Model_Mysql4_Convert_Profile, Mage_Core_Model_Mysql4_Design, Mage_Core_Model_Mysql4_Store, Mage_Core_Model_Mysql4_Translate_String, Mage_Core_Model_Mysql4_Website, Mage_Dataflow_Model_Mysql4_Profile_History, Mage_Dataflow_Model_Mysql4_Profile, Mage_Eav_Model_Mysql4_Entity_Attribute_Group, Mage_Eav_Model_Mysql4_Entity_Attribute, Mage_Log_Model_Mysql4_Visitor, Mage_Newsletter_Model_Mysql4_Template, Mage_ProductAlert_Model_Mysql4_Price, Mage_ProductAlert_Model_Mysql4_Stock, Mage_Review_Model_Mysql4_Review, Mage_SalesRule_Model_Mysql4_Rule, and Mage_Tag_Model_Mysql4_Tag.
Definition at line 567 of file Abstract.php.
_checkUnique | ( | Mage_Core_Model_Abstract $ | object | ) | [protected] |
Check for unique values existence
Varien_Object | $object |
Mage_Core_Exception |
Definition at line 496 of file Abstract.php.
00497 { 00498 $existent = array(); 00499 $fields = $this->getUniqueFields(); 00500 if (!empty($fields)) { 00501 if (!is_array($fields)) { 00502 $this->_uniqueFields = array( 00503 array( 00504 'field' => $fields, 00505 'title' => $fields 00506 )); 00507 } 00508 00509 $data = new Varien_Object($this->_prepareDataForSave($object)); 00510 $select = $this->_getWriteAdapter()->select() 00511 ->from($this->getMainTable()); 00512 00513 foreach ($fields as $unique) { 00514 $select->reset(Zend_Db_Select::WHERE); 00515 00516 if (is_array($unique['field'])) { 00517 foreach ($unique['field'] as $field) { 00518 $select->where($field.'=?', $data->getData($field)); 00519 } 00520 } 00521 else { 00522 $select->where( $unique['field'] . ' = ?', $data->getData($unique['field']) ); 00523 } 00524 00525 if ($object->getId()) { 00526 $select->where($this->getIdFieldName().' != ?', $object->getId()); 00527 } 00528 00529 if ( $test = $this->_getWriteAdapter()->fetchRow($select) ) { 00530 $existent[] = $unique['title']; 00531 } 00532 } 00533 } 00534 00535 if (!empty($existent)) { 00536 if (count($existent) == 1 ) { 00537 $error = Mage::helper('core')->__('%s already exist', $existent[0]); 00538 } 00539 else { 00540 $error = Mage::helper('core')->__('%s already exists', implode(', ', $existent)); 00541 } 00542 Mage::throwException($error); 00543 } 00544 return $this; 00545 }
_getConnection | ( | $ | connectionName | ) | [protected] |
Get connection by name or type
string | $connectionName |
Definition at line 248 of file Abstract.php.
00249 { 00250 if (isset($this->_connections[$connectionName])) { 00251 return $this->_connections[$connectionName]; 00252 } 00253 if (!empty($this->_resourcePrefix)) { 00254 $this->_connections[$connectionName] = $this->_resources->getConnection( 00255 $this->_resourcePrefix.'_'.$connectionName); 00256 } else { 00257 $this->_connections[$connectionName] = $this->_resources->getConnection($connectionName); 00258 } 00259 00260 return $this->_connections[$connectionName]; 00261 }
_getLoadSelect | ( | $ | field, | |
$ | value, | |||
$ | object | |||
) | [protected] |
Retrieve select object for load object data
string | $field | |
mixed | $value |
Reimplemented in Mage_CatalogInventory_Model_Mysql4_Stock_Item, Mage_CatalogSearch_Model_Mysql4_Query, Mage_Checkout_Model_Mysql4_Agreement, Mage_Cms_Model_Mysql4_Block, Mage_Cms_Model_Mysql4_Page, Mage_Core_Model_Mysql4_Store, Mage_Core_Model_Mysql4_Translate_String, Mage_Core_Model_Mysql4_Url_Rewrite, Mage_Rating_Model_Mysql4_Rating, Mage_Review_Model_Mysql4_Review_Summary, Mage_Review_Model_Mysql4_Review, and Mage_Sales_Model_Mysql4_Quote.
Definition at line 329 of file Abstract.php.
00330 { 00331 $select = $this->_getReadAdapter()->select() 00332 ->from($this->getMainTable()) 00333 ->where($this->getMainTable().'.'.$field.'=?', $value); 00334 return $select; 00335 }
_getReadAdapter | ( | ) | [protected] |
Retrieve connection for read data
Reimplemented from Mage_Core_Model_Resource_Abstract.
Definition at line 268 of file Abstract.php.
00269 { 00270 return $this->_getConnection('read'); 00271 }
_getWriteAdapter | ( | ) | [protected] |
Retrieve connection for write data
Reimplemented from Mage_Core_Model_Resource_Abstract.
Definition at line 278 of file Abstract.php.
00279 { 00280 return $this->_getConnection('write'); 00281 }
_init | ( | $ | mainTable, | |
$ | idFieldName | |||
) | [protected] |
Standard resource model initialization
string | $mainTable | |
string | $idFieldName |
Definition at line 124 of file Abstract.php.
00125 { 00126 $this->_setMainTable($mainTable, $idFieldName); 00127 }
_initUniqueFields | ( | ) | [protected] |
Initialize unique fields
Reimplemented in Mage_Admin_Model_Mysql4_User, Mage_Api_Model_Mysql4_User, Mage_Core_Model_Mysql4_Store, Mage_Core_Model_Mysql4_Url_Rewrite, Mage_Core_Model_Mysql4_Website, Mage_Customer_Model_Entity_Group, Mage_Directory_Model_Mysql4_Country_Format, Mage_Eav_Model_Mysql4_Entity_Attribute, Mage_Poll_Model_Mysql4_Poll_Answer, Mage_Poll_Model_Mysql4_Poll, Mage_Rating_Model_Mysql4_Rating, Mage_Tag_Model_Mysql4_Tag, Mage_Tax_Model_Mysql4_Calculation_Rate, Mage_Tax_Model_Mysql4_Calculation_Rule, and Mage_Tax_Model_Mysql4_Class.
Definition at line 426 of file Abstract.php.
00427 { 00428 $this->_uniqueFields = array(); 00429 return $this; 00430 }
_prepareDataForSave | ( | Mage_Core_Model_Abstract $ | object | ) | [protected] |
Prepare data for save
Mage_Core_Model_Abstract | $object |
Reimplemented in Mage_Log_Model_Mysql4_Visitor, and Mage_Sales_Model_Mysql4_Abstract.
Definition at line 451 of file Abstract.php.
00452 { 00453 $data = array(); 00454 $fields = $this->_getWriteAdapter()->describeTable($this->getMainTable()); 00455 foreach (array_keys($fields) as $field) { 00456 if ($object->hasData($field)) { 00457 $fieldValue = $object->getData($field); 00458 if ($fieldValue instanceof Zend_Db_Expr) { 00459 $data[$field] = $fieldValue; 00460 } 00461 else { 00462 if (null !== $fieldValue) { 00463 $data[$field] = $this->_prepareValueForSave($fieldValue, $fields[$field]['DATA_TYPE']); 00464 } 00465 elseif (!empty($fields[$field]['NULLABLE'])) { 00466 $data[$field] = null; 00467 } 00468 } 00469 } 00470 } 00471 return $data; 00472 }
_prepareValueForSave | ( | $ | value, | |
$ | type | |||
) | [protected] |
Prepare value for save
mixed | $value | |
string | $type |
Definition at line 481 of file Abstract.php.
00482 { 00483 if ($type == 'decimal') { 00484 $value = Mage::app()->getLocale()->getNumber($value); 00485 } 00486 return $value; 00487 }
_setMainTable | ( | $ | mainTable, | |
$ | idFieldName = null | |||
) | [protected] |
Set main entity table name and primary key field name
If field name is ommited {table_name}_id will be used
string | $mainTable | |
string|null | $idFieldName |
Definition at line 175 of file Abstract.php.
00176 { 00177 $mainTableArr = explode('/', $mainTable); 00178 00179 if (!empty($mainTableArr[1])) { 00180 if (empty($this->_resourceModel)) { 00181 $this->_setResource($mainTableArr[0]); 00182 } 00183 $this->_setMainTable($mainTableArr[1], $idFieldName); 00184 } else { 00185 $this->_mainTable = $mainTable; 00186 if (is_null($idFieldName)) { 00187 $idFieldName = $mainTable.'_id'; 00188 } 00189 $this->_idFieldName = $idFieldName; 00190 } 00191 00192 return $this; 00193 }
_setResource | ( | $ | connections, | |
$ | tables = null | |||
) | [protected] |
Initialize connections and tables for this resource model
If one or both arguments are string, will be used as prefix If $tables is null and $connections is string, $tables will be the same
string|array | $connections | |
string|array|null | $tables |
Definition at line 139 of file Abstract.php.
00140 { 00141 $this->_resources = Mage::getSingleton('core/resource'); 00142 00143 if (is_array($connections)) { 00144 foreach ($connections as $k=>$v) { 00145 $this->_connections[$k] = $this->_resources->getConnection($v); 00146 } 00147 } 00148 elseif (is_string($connections)) { 00149 $this->_resourcePrefix = $connections; 00150 } 00151 00152 if (is_null($tables) && is_string($connections)) { 00153 $this->_resourceModel = $this->_resourcePrefix; 00154 } 00155 elseif (is_array($tables)) { 00156 foreach ($tables as $k=>$v) { 00157 $this->_tables[$k] = $this->_resources->getTableName($v); 00158 } 00159 } 00160 elseif (is_string($tables)) { 00161 $this->_resourceModel = $tables; 00162 } 00163 return $this; 00164 }
addUniqueField | ( | $ | field | ) |
Add unique field restriction
array|string | $field |
Definition at line 401 of file Abstract.php.
00402 { 00403 $this->_initUniqueFields(); 00404 if(is_array($this->_uniqueFields) ) { 00405 $this->_uniqueFields[] = $field; 00406 } 00407 return $this; 00408 }
afterLoad | ( | Mage_Core_Model_Abstract $ | object | ) |
delete | ( | Mage_Core_Model_Abstract $ | object | ) |
Delete the object
Varien_Object | $object |
Reimplemented in Mage_Admin_Model_Mysql4_User, and Mage_Api_Model_Mysql4_User.
Definition at line 384 of file Abstract.php.
00385 { 00386 $this->_beforeDelete($object); 00387 $this->_getWriteAdapter()->delete( 00388 $this->getMainTable(), 00389 $this->_getWriteAdapter()->quoteInto($this->getIdFieldName().'=?', $object->getId()) 00390 ); 00391 $this->_afterDelete($object); 00392 return $this; 00393 }
getChecksum | ( | $ | table | ) |
Retrieve table checksum
string | $table |
Reimplemented in Mage_Core_Model_Mysql4_Config.
Definition at line 608 of file Abstract.php.
00609 { 00610 if (!$this->_getConnection('read')) { 00611 return false; 00612 } 00613 00614 if (is_array($table)) { 00615 $table = implode(',', $table); 00616 } 00617 00618 $data = $this->_getConnection('read')->fetchAll('checksum table '.$table); 00619 $checksum = 0; 00620 foreach ($data as $row) { 00621 $checksum+= $row[self::CHECKSUM_KEY_NAME]; 00622 } 00623 return $checksum; 00624 }
getIdFieldName | ( | ) |
Get primary key field name
Definition at line 200 of file Abstract.php.
00201 { 00202 if (empty($this->_idFieldName)) { 00203 Mage::throwException(Mage::helper('core')->__('Empty identifier field name')); 00204 } 00205 return $this->_idFieldName; 00206 }
getMainTable | ( | ) |
Get main table name
Reimplemented in Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat.
Definition at line 213 of file Abstract.php.
00214 { 00215 if (empty($this->_mainTable)) { 00216 Mage::throwException(Mage::helper('core')->__('Empty main table name')); 00217 } 00218 return $this->getTable($this->_mainTable); 00219 }
getReadConnection | ( | ) |
Temporary resolving collection compatibility
Definition at line 288 of file Abstract.php.
00289 { 00290 return $this->_getReadAdapter(); 00291 }
getTable | ( | $ | entityName | ) |
Get table name for the entity
string | $entityName |
Definition at line 226 of file Abstract.php.
00227 { 00228 if (isset($this->_tables[$entityName])) { 00229 return $this->_tables[$entityName]; 00230 } 00231 if (strpos($entityName, '/')) { 00232 $this->_tables[$entityName] = $this->_resources->getTableName($entityName); 00233 } elseif (!empty($this->_resourceModel)) { 00234 $this->_tables[$entityName] = $this->_resources->getTableName( 00235 $this->_resourceModel.'/'.$entityName); 00236 } else { 00237 $this->_tables[$entityName] = $entityName; 00238 } 00239 return $this->_tables[$entityName]; 00240 }
getUniqueFields | ( | ) |
Get configuration of all unique fields
Definition at line 437 of file Abstract.php.
00438 { 00439 if (is_null($this->_uniqueFields)) { 00440 $this->_initUniqueFields(); 00441 } 00442 return $this->_uniqueFields; 00443 }
load | ( | Mage_Core_Model_Abstract $ | object, | |
$ | value, | |||
$ | field = null | |||
) |
Load an object
Mage_Core_Model_Abstract | $object | |
mixed | $value | |
string | $field field to load by (defaults to model id) |
Reimplemented in Mage_Admin_Model_Mysql4_Role, Mage_Admin_Model_Mysql4_User, Mage_Api_Model_Mysql4_Role, Mage_Api_Model_Mysql4_User, Mage_CatalogSearch_Model_Mysql4_Query, Mage_Cms_Model_Mysql4_Block, Mage_Cms_Model_Mysql4_Page, and Mage_Core_Model_Mysql4_Translate_String.
Definition at line 301 of file Abstract.php.
00302 { 00303 if (is_null($field)) { 00304 $field = $this->getIdFieldName(); 00305 } 00306 00307 $read = $this->_getReadAdapter(); 00308 if ($read && !is_null($value)) { 00309 $select = $this->_getLoadSelect($field, $value, $object); 00310 $data = $read->fetchRow($select); 00311 00312 if ($data) { 00313 $object->setData($data); 00314 } 00315 } 00316 00317 $this->_afterLoad($object); 00318 00319 return $this; 00320 }
resetUniqueField | ( | ) |
Reset unique fields restrictions
Definition at line 415 of file Abstract.php.
00416 { 00417 $this->_uniqueFields = array(); 00418 return $this; 00419 }
save | ( | Mage_Core_Model_Abstract $ | object | ) |
Save object object data
Mage_Core_Model_Abstract | $object |
Not auto increment primary key support
Definition at line 343 of file Abstract.php.
00344 { 00345 if ($object->isDeleted()) { 00346 return $this->delete($object); 00347 } 00348 00349 $this->_beforeSave($object); 00350 $this->_checkUnique($object); 00351 00352 if (!is_null($object->getId())) { 00353 $condition = $this->_getWriteAdapter()->quoteInto($this->getIdFieldName().'=?', $object->getId()); 00354 /** 00355 * Not auto increment primary key support 00356 */ 00357 if ($this->_isPkAutoIncrement) { 00358 $this->_getWriteAdapter()->update($this->getMainTable(), $this->_prepareDataForSave($object), $condition); 00359 } else { 00360 $select = $this->_getWriteAdapter()->select($this->getMainTable(), array($this->getIdFieldName())) 00361 ->where($condition); 00362 if ($this->_getWriteAdapter()->fetchOne($select) !== false) { 00363 $this->_getWriteAdapter()->update($this->getMainTable(), $this->_prepareDataForSave($object), $condition); 00364 } else { 00365 $this->_getWriteAdapter()->insert($this->getMainTable(), $this->_prepareDataForSave($object)); 00366 } 00367 } 00368 } else { 00369 $this->_getWriteAdapter()->insert($this->getMainTable(), $this->_prepareDataForSave($object)); 00370 $object->setId($this->_getWriteAdapter()->lastInsertId($this->getMainTable())); 00371 } 00372 00373 $this->_afterSave($object); 00374 00375 return $this; 00376 }
$_connections = array() [protected] |
Definition at line 59 of file Abstract.php.
$_idFieldName [protected] |
Definition at line 87 of file Abstract.php.
$_isPkAutoIncrement = true [protected] |
Definition at line 94 of file Abstract.php.
$_mainTable [protected] |
Definition at line 80 of file Abstract.php.
$_mainTableFields [protected] |
Definition at line 96 of file Abstract.php.
$_resourceModel [protected] |
Definition at line 66 of file Abstract.php.
$_resourcePrefix [protected] |
Definition at line 52 of file Abstract.php.
$_resources [protected] |
Definition at line 45 of file Abstract.php.
$_tables = array() [protected] |
Definition at line 73 of file Abstract.php.
$_uniqueFields = null [protected] |
Definition at line 115 of file Abstract.php.
const CHECKSUM_KEY_NAME = 'Checksum' |
Definition at line 38 of file Abstract.php.