Mage_Cms_Model_Mysql4_Page Class Reference

Inheritance diagram for Mage_Cms_Model_Mysql4_Page:

Mage_Core_Model_Mysql4_Abstract Mage_Core_Model_Resource_Abstract

List of all members.

Public Member Functions

 load (Mage_Core_Model_Abstract $object, $value, $field=null)
 getIsUniquePageToStores (Mage_Core_Model_Abstract $object)
 checkIdentifier ($identifier, $storeId)
 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)
 isNumericPageIdentifier (Mage_Core_Model_Abstract $object)


Detailed Description

Definition at line 35 of file Page.php.


Member Function Documentation

_afterLoad ( Mage_Core_Model_Abstract object  )  [protected]

Parameters:
Mage_Core_Model_Abstract $object

Reimplemented from Mage_Core_Model_Mysql4_Abstract.

Definition at line 112 of file Page.php.

00113     {
00114         $select = $this->_getReadAdapter()->select()
00115             ->from($this->getTable('cms/page_store'))
00116             ->where('page_id = ?', $object->getId());
00117 
00118         if ($data = $this->_getReadAdapter()->fetchAll($select)) {
00119             $storesArray = array();
00120             foreach ($data as $row) {
00121                 $storesArray[] = $row['store_id'];
00122             }
00123             $object->setData('store_id', $storesArray);
00124         }
00125 
00126         return parent::_afterLoad($object);
00127     }

_afterSave ( Mage_Core_Model_Abstract object  )  [protected]

Assign page to store views

Parameters:
Mage_Core_Model_Abstract $object

Reimplemented from Mage_Core_Model_Mysql4_Abstract.

Definition at line 85 of file Page.php.

00086     {
00087         $condition = $this->_getWriteAdapter()->quoteInto('page_id = ?', $object->getId());
00088         $this->_getWriteAdapter()->delete($this->getTable('cms/page_store'), $condition);
00089 
00090         foreach ((array)$object->getData('stores') as $store) {
00091             $storeArray = array();
00092             $storeArray['page_id'] = $object->getId();
00093             $storeArray['store_id'] = $store;
00094             $this->_getWriteAdapter()->insert($this->getTable('cms/page_store'), $storeArray);
00095         }
00096 
00097         return parent::_afterSave($object);
00098     }

_beforeSave ( Mage_Core_Model_Abstract object  )  [protected]

Process page data before saving

Parameters:
Mage_Core_Model_Abstract $object

Reimplemented from Mage_Core_Model_Mysql4_Abstract.

Definition at line 50 of file Page.php.

00051     {
00052         $format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
00053         foreach (array('custom_theme_from', 'custom_theme_to') as $dataKey) {
00054             if ($date = $object->getData($dataKey)) {
00055                 $object->setData($dataKey, Mage::app()->getLocale()->date($date, $format, null, false)
00056                     ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT)
00057                 );
00058             }
00059             else {
00060                 $object->setData($dataKey, new Zend_Db_Expr('NULL'));
00061             }
00062         }
00063 
00064         if (!$this->getIsUniquePageToStores($object)) {
00065             Mage::throwException(Mage::helper('cms')->__('Page Identifier for specified store already exist.'));
00066         }
00067 
00068         if ($this->isNumericPageIdentifier($object)) {
00069             Mage::throwException(Mage::helper('cms')->__('Page Identifier cannot consist only of numbers.'));
00070         }
00071 
00072         if (! $object->getId()) {
00073             $object->setCreationTime(Mage::getSingleton('core/date')->gmtDate());
00074         }
00075 
00076         $object->setUpdateTime(Mage::getSingleton('core/date')->gmtDate());
00077         return $this;
00078     }

_construct (  )  [protected]

Initialize resource model

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 40 of file Page.php.

00041     {
00042         $this->_init('cms/page', 'page_id');
00043     }

_getLoadSelect ( field,
value,
object 
) [protected]

Retrieve select object for load object data

Parameters:
string $field
mixed $value
Returns:
Zend_Db_Select

Reimplemented from Mage_Core_Model_Mysql4_Abstract.

Definition at line 136 of file Page.php.

00137     {
00138         $select = parent::_getLoadSelect($field, $value, $object);
00139 
00140         if ($object->getStoreId()) {
00141             $select->join(
00142                         array('cps' => $this->getTable('cms/page_store')),
00143                         $this->getMainTable().'.page_id = `cps`.page_id'
00144                     )
00145                     ->where('is_active=1 AND `cps`.store_id in (0, ?) ', $object->getStoreId())
00146                     ->order('store_id DESC')
00147                     ->limit(1);
00148         }
00149         return $select;
00150     }

checkIdentifier ( identifier,
storeId 
)

Check if page identifier exist for specific store return page id if page exists

Parameters:
string $identifier
int $storeId
Returns:
int

Definition at line 196 of file Page.php.

00197     {
00198         $select = $this->_getReadAdapter()->select()->from(array('main_table'=>$this->getMainTable()), 'page_id')
00199             ->join(
00200                 array('cps' => $this->getTable('cms/page_store')),
00201                 'main_table.page_id = `cps`.page_id'
00202             )
00203             ->where('main_table.identifier=?', $identifier)
00204             ->where('main_table.is_active=1 AND `cps`.store_id in (0, ?) ', $storeId)
00205             ->order('store_id DESC');
00206 
00207         return $this->_getReadAdapter()->fetchOne($select);
00208     }

getIsUniquePageToStores ( Mage_Core_Model_Abstract object  ) 

Check for unique of identifier of page to selected store(s).

Parameters:
Mage_Core_Model_Abstract $object
Returns:
bool

Definition at line 158 of file Page.php.

00159     {
00160         $select = $this->_getWriteAdapter()->select()
00161                 ->from($this->getMainTable())
00162                 ->join(array('cps' => $this->getTable('cms/page_store')), $this->getMainTable().'.page_id = `cps`.page_id')
00163                 ->where($this->getMainTable().'.identifier = ?', $object->getData('identifier'));
00164         if ($object->getId()) {
00165             $select->where($this->getMainTable().'.page_id <> ?',$object->getId());
00166         }
00167         $select->where('`cps`.store_id IN (?)', (array)$object->getData('stores'));
00168 
00169         if ($this->_getWriteAdapter()->fetchRow($select)) {
00170             return false;
00171         }
00172 
00173         return true;
00174     }

isNumericPageIdentifier ( Mage_Core_Model_Abstract object  )  [protected]

Check whether page identifier is numeric

Parameters:
Mage_Core_Model_Abstract $object
Returns:
bool
Date:
Wed Mar 26 18:12:28 EET 2008

Definition at line 183 of file Page.php.

00184     {
00185         return preg_match('/^[0-9]+$/', $object->getData('identifier'));
00186     }

load ( Mage_Core_Model_Abstract object,
value,
field = null 
)

Load an object

Parameters:
Mage_Core_Model_Abstract $object
mixed $value
string $field field to load by (defaults to model id)
Returns:
Mage_Core_Model_Mysql4_Abstract

Reimplemented from Mage_Core_Model_Mysql4_Abstract.

Definition at line 100 of file Page.php.

00101     {
00102         if (strcmp($value, (int)$value) !== 0) {
00103             $field = 'identifier';
00104         }
00105         return parent::load($object, $value, $field);
00106     }

lookupStoreIds ( id  ) 

Get store ids to which specified item is assigned

Parameters:
int $id
Returns:
array

Definition at line 216 of file Page.php.

00217     {
00218         return $this->_getReadAdapter()->fetchCol($this->_getReadAdapter()->select()
00219             ->from($this->getTable('cms/page_store'), 'store_id')
00220             ->where("{$this->getIdFieldName()} = ?", $id)
00221         );
00222     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:52 2009 for Magento by  doxygen 1.5.8