Public Member Functions | |
load (Mage_Core_Model_Abstract $object, $value, $field=null) | |
getIsUniqueBlockToStores (Mage_Core_Model_Abstract $object) | |
lookupStoreIds ($id) | |
Protected Member Functions | |
_construct () | |
_beforeSave (Mage_Core_Model_Abstract $object) | |
_afterSave (Mage_Core_Model_Abstract $object) | |
_afterLoad (Mage_Core_Model_Abstract $object) | |
_getLoadSelect ($field, $value, $object) |
Definition at line 35 of file Block.php.
_afterLoad | ( | Mage_Core_Model_Abstract $ | object | ) | [protected] |
Mage_Core_Model_Abstract | $object |
Reimplemented from Mage_Core_Model_Mysql4_Abstract.
Definition at line 93 of file Block.php.
00094 { 00095 $select = $this->_getReadAdapter()->select() 00096 ->from($this->getTable('cms/block_store')) 00097 ->where('block_id = ?', $object->getId()); 00098 00099 if ($data = $this->_getReadAdapter()->fetchAll($select)) { 00100 $storesArray = array(); 00101 foreach ($data as $row) { 00102 $storesArray[] = $row['store_id']; 00103 } 00104 $object->setData('store_id', $storesArray); 00105 } 00106 00107 return parent::_afterLoad($object); 00108 }
_afterSave | ( | Mage_Core_Model_Abstract $ | object | ) | [protected] |
Mage_Core_Model_Abstract | $object |
Reimplemented from Mage_Core_Model_Mysql4_Abstract.
Definition at line 65 of file Block.php.
00066 { 00067 $condition = $this->_getWriteAdapter()->quoteInto('block_id = ?', $object->getId()); 00068 $this->_getWriteAdapter()->delete($this->getTable('cms/block_store'), $condition); 00069 00070 foreach ((array)$object->getData('stores') as $store) { 00071 $storeArray = array(); 00072 $storeArray['block_id'] = $object->getId(); 00073 $storeArray['store_id'] = $store; 00074 $this->_getWriteAdapter()->insert($this->getTable('cms/block_store'), $storeArray); 00075 } 00076 00077 return parent::_afterSave($object); 00078 }
_beforeSave | ( | Mage_Core_Model_Abstract $ | object | ) | [protected] |
Mage_Core_Model_Abstract | $object |
Reimplemented from Mage_Core_Model_Mysql4_Abstract.
Definition at line 48 of file Block.php.
00049 { 00050 if (!$this->getIsUniqueBlockToStores($object)) { 00051 Mage::throwException(Mage::helper('cms')->__('Such a block identifier in selected store already exist.')); 00052 } 00053 00054 if (! $object->getId()) { 00055 $object->setCreationTime(Mage::getSingleton('core/date')->gmtDate()); 00056 } 00057 $object->setUpdateTime(Mage::getSingleton('core/date')->gmtDate()); 00058 return $this; 00059 }
_construct | ( | ) | [protected] |
Resource initialization
Reimplemented from Mage_Core_Model_Resource_Abstract.
Definition at line 38 of file Block.php.
00039 { 00040 $this->_init('cms/block', 'block_id'); 00041 }
_getLoadSelect | ( | $ | field, | |
$ | value, | |||
$ | object | |||
) | [protected] |
Retrieve select object for load object data
string | $field | |
mixed | $value |
Reimplemented from Mage_Core_Model_Mysql4_Abstract.
Definition at line 117 of file Block.php.
00118 { 00119 00120 $select = parent::_getLoadSelect($field, $value, $object); 00121 00122 if ($object->getStoreId()) { 00123 $select->join(array('cbs' => $this->getTable('cms/block_store')), $this->getMainTable().'.block_id = cbs.block_id') 00124 ->where('is_active=1 AND cbs.store_id in (0, ?) ', $object->getStoreId()) 00125 ->order('store_id DESC') 00126 ->limit(1); 00127 } 00128 return $select; 00129 }
getIsUniqueBlockToStores | ( | Mage_Core_Model_Abstract $ | object | ) |
Check for unique of identifier of block to selected store(s).
Mage_Core_Model_Abstract | $object |
Definition at line 137 of file Block.php.
00138 { 00139 $select = $this->_getWriteAdapter()->select() 00140 ->from($this->getMainTable()) 00141 ->join(array('cbs' => $this->getTable('cms/block_store')), $this->getMainTable().'.block_id = `cbs`.block_id') 00142 ->where($this->getMainTable().'.identifier = ?', $object->getData('identifier')); 00143 if ($object->getId()) { 00144 $select->where($this->getMainTable().'.block_id <> ?',$object->getId()); 00145 } 00146 $select->where('`cbs`.store_id IN (?)', (array)$object->getData('stores')); 00147 00148 if ($this->_getWriteAdapter()->fetchRow($select)) { 00149 return false; 00150 } 00151 00152 return true; 00153 }
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 from Mage_Core_Model_Mysql4_Abstract.
Definition at line 80 of file Block.php.
00081 { 00082 00083 if (!intval($value) && is_string($value)) { 00084 $field = 'identifier'; 00085 } 00086 return parent::load($object, $value, $field); 00087 }
lookupStoreIds | ( | $ | id | ) |
Get store ids to which specified item is assigned
int | $id |
Definition at line 161 of file Block.php.
00162 { 00163 return $this->_getReadAdapter()->fetchCol($this->_getReadAdapter()->select() 00164 ->from($this->getTable('cms/block_store'), 'store_id') 00165 ->where("{$this->getIdFieldName()} = ?", $id) 00166 ); 00167 }