Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Adminhtml_Cms_PageController
  • Mage_Adminhtml_Model_System_Config_Source_Cms_Wysiwyg_Enabled
  • Mage_Cms_Block_Block
  • Mage_Cms_Block_Page
  • Mage_Cms_Block_Widget_Block
  • Mage_Cms_Block_Widget_Page_Link
  • Mage_Cms_Controller_Router
  • Mage_Cms_Helper_Data
  • Mage_Cms_Helper_Page
  • Mage_Cms_Helper_Wysiwyg_Images
  • Mage_Cms_IndexController
  • Mage_Cms_Model_Block
  • Mage_Cms_Model_Mysql4_Block
  • Mage_Cms_Model_Mysql4_Block_Collection
  • Mage_Cms_Model_Mysql4_Page
  • Mage_Cms_Model_Mysql4_Page_Collection
  • Mage_Cms_Model_Mysql4_Page_Service
  • Mage_Cms_Model_Observer
  • Mage_Cms_Model_Page
  • Mage_Cms_Model_Resource_Block
  • Mage_Cms_Model_Resource_Block_Collection
  • Mage_Cms_Model_Resource_Page
  • Mage_Cms_Model_Resource_Page_Collection
  • Mage_Cms_Model_Resource_Page_Service
  • Mage_Cms_Model_Template_Filter
  • Mage_Cms_Model_Wysiwyg_Config
  • Mage_Cms_Model_Wysiwyg_Images_Storage
  • Mage_Cms_Model_Wysiwyg_Images_Storage_Collection
  • Mage_Cms_PageController
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Cms
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: /**
 29:  * CMS block model
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_Cms
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Cms_Model_Resource_Block extends Mage_Core_Model_Resource_Db_Abstract
 36: {
 37:     /**
 38:      * Initialize resource model
 39:      *
 40:      */
 41:     protected function _construct()
 42:     {
 43:         $this->_init('cms/block', 'block_id');
 44:     }
 45: 
 46:     /**
 47:      * Process block data before deleting
 48:      *
 49:      * @param Mage_Core_Model_Abstract $object
 50:      * @return Mage_Cms_Model_Resource_Page
 51:      */
 52:     protected function _beforeDelete(Mage_Core_Model_Abstract $object)
 53:     {
 54:         $condition = array(
 55:             'block_id = ?'     => (int) $object->getId(),
 56:         );
 57: 
 58:         $this->_getWriteAdapter()->delete($this->getTable('cms/block_store'), $condition);
 59: 
 60:         return parent::_beforeDelete($object);
 61:     }
 62: 
 63:     /**
 64:      * Perform operations before object save
 65:      *
 66:      * @param Mage_Cms_Model_Block $object
 67:      * @return Mage_Cms_Model_Resource_Block
 68:      */
 69:     protected function _beforeSave(Mage_Core_Model_Abstract $object)
 70:     {
 71:         if (!$this->getIsUniqueBlockToStores($object)) {
 72:             Mage::throwException(Mage::helper('cms')->__('A block identifier with the same properties already exists in the selected store.'));
 73:         }
 74: 
 75:         if (! $object->getId()) {
 76:             $object->setCreationTime(Mage::getSingleton('core/date')->gmtDate());
 77:         }
 78:         $object->setUpdateTime(Mage::getSingleton('core/date')->gmtDate());
 79:         return $this;
 80:     }
 81: 
 82:     /**
 83:      * Perform operations after object save
 84:      *
 85:      * @param Mage_Core_Model_Abstract $object
 86:      * @return Mage_Cms_Model_Resource_Block
 87:      */
 88:     protected function _afterSave(Mage_Core_Model_Abstract $object)
 89:     {
 90:         $oldStores = $this->lookupStoreIds($object->getId());
 91:         $newStores = (array)$object->getStores();
 92: 
 93:         $table  = $this->getTable('cms/block_store');
 94:         $insert = array_diff($newStores, $oldStores);
 95:         $delete = array_diff($oldStores, $newStores);
 96: 
 97:         if ($delete) {
 98:             $where = array(
 99:                 'block_id = ?'     => (int) $object->getId(),
100:                 'store_id IN (?)' => $delete
101:             );
102: 
103:             $this->_getWriteAdapter()->delete($table, $where);
104:         }
105: 
106:         if ($insert) {
107:             $data = array();
108: 
109:             foreach ($insert as $storeId) {
110:                 $data[] = array(
111:                     'block_id'  => (int) $object->getId(),
112:                     'store_id' => (int) $storeId
113:                 );
114:             }
115: 
116:             $this->_getWriteAdapter()->insertMultiple($table, $data);
117:         }
118: 
119:         return parent::_afterSave($object);
120: 
121:     }
122: 
123:     /**
124:      * Load an object using 'identifier' field if there's no field specified and value is not numeric
125:      *
126:      * @param Mage_Core_Model_Abstract $object
127:      * @param mixed $value
128:      * @param string $field
129:      * @return Mage_Cms_Model_Resource_Block
130:      */
131:     public function load(Mage_Core_Model_Abstract $object, $value, $field = null)
132:     {
133:         if (!is_numeric($value) && is_null($field)) {
134:             $field = 'identifier';
135:         }
136: 
137:         return parent::load($object, $value, $field);
138:     }
139: 
140:     /**
141:      * Perform operations after object load
142:      *
143:      * @param Mage_Core_Model_Abstract $object
144:      * @return Mage_Cms_Model_Resource_Block
145:      */
146:     protected function _afterLoad(Mage_Core_Model_Abstract $object)
147:     {
148:         if ($object->getId()) {
149:             $stores = $this->lookupStoreIds($object->getId());
150:             $object->setData('store_id', $stores);
151:             $object->setData('stores', $stores);
152:         }
153: 
154:         return parent::_afterLoad($object);
155:     }
156: 
157:     /**
158:      * Retrieve select object for load object data
159:      *
160:      * @param string $field
161:      * @param mixed $value
162:      * @param Mage_Cms_Model_Block $object
163:      * @return Zend_Db_Select
164:      */
165:     protected function _getLoadSelect($field, $value, $object)
166:     {
167:         $select = parent::_getLoadSelect($field, $value, $object);
168: 
169:         if ($object->getStoreId()) {
170:             $stores = array(
171:                 (int) $object->getStoreId(),
172:                 Mage_Core_Model_App::ADMIN_STORE_ID,
173:             );
174: 
175:             $select->join(
176:                 array('cbs' => $this->getTable('cms/block_store')),
177:                 $this->getMainTable().'.block_id = cbs.block_id',
178:                 array('store_id')
179:             )->where('is_active = ?', 1)
180:             ->where('cbs.store_id in (?) ', $stores)
181:             ->order('store_id DESC')
182:             ->limit(1);
183:         }
184: 
185:         return $select;
186:     }
187: 
188:     /**
189:      * Check for unique of identifier of block to selected store(s).
190:      *
191:      * @param Mage_Core_Model_Abstract $object
192:      * @return bool
193:      */
194:     public function getIsUniqueBlockToStores(Mage_Core_Model_Abstract $object)
195:     {
196:         if (Mage::app()->isSingleStoreMode()) {
197:             $stores = array(Mage_Core_Model_App::ADMIN_STORE_ID);
198:         } else {
199:             $stores = (array)$object->getData('stores');
200:         }
201: 
202:         $select = $this->_getReadAdapter()->select()
203:             ->from(array('cb' => $this->getMainTable()))
204:             ->join(
205:                 array('cbs' => $this->getTable('cms/block_store')),
206:                 'cb.block_id = cbs.block_id',
207:                 array()
208:             )->where('cb.identifier = ?', $object->getData('identifier'))
209:             ->where('cbs.store_id IN (?)', $stores);
210: 
211:         if ($object->getId()) {
212:             $select->where('cb.block_id <> ?', $object->getId());
213:         }
214: 
215:         if ($this->_getReadAdapter()->fetchRow($select)) {
216:             return false;
217:         }
218: 
219:         return true;
220:     }
221: 
222:     /**
223:      * Get store ids to which specified item is assigned
224:      *
225:      * @param int $id
226:      * @return array
227:      */
228:     public function lookupStoreIds($id)
229:     {
230:         $adapter = $this->_getReadAdapter();
231: 
232:         $select  = $adapter->select()
233:             ->from($this->getTable('cms/block_store'), 'store_id')
234:             ->where('block_id = :block_id');
235: 
236:         $binds = array(
237:             ':block_id' => (int) $id
238:         );
239: 
240:         return $adapter->fetchCol($select, $binds);
241:     }
242: }
243: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0