00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Cms_Model_Mysql4_Page_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
00036 {
00037 protected $_previewFlag;
00038
00039 protected function _construct()
00040 {
00041 $this->_init('cms/page');
00042 }
00043
00044 public function toOptionArray()
00045 {
00046 return $this->_toOptionArray('identifier', 'title');
00047 }
00048
00049 public function setFirstStoreFlag($flag = false)
00050 {
00051 $this->_previewFlag = $flag;
00052 return $this;
00053 }
00054
00055 protected function _afterLoad()
00056 {
00057 if ($this->_previewFlag) {
00058 $items = $this->getColumnValues('page_id');
00059 if (count($items)) {
00060 $select = $this->getConnection()->select()
00061 ->from($this->getTable('cms/page_store'))
00062 ->where($this->getTable('cms/page_store').'.page_id IN (?)', $items);
00063 if ($result = $this->getConnection()->fetchPairs($select)) {
00064 foreach ($this as $item) {
00065 if (!isset($result[$item->getData('page_id')])) {
00066 continue;
00067 }
00068 if ($result[$item->getData('page_id')] == 0) {
00069 $stores = Mage::app()->getStores(false, true);
00070 $storeId = current($stores)->getId();
00071 $storeCode = key($stores);
00072 } else {
00073 $storeId = $result[$item->getData('page_id')];
00074 $storeCode = Mage::app()->getStore($storeId)->getCode();
00075 }
00076 $item->setData('_first_store_id', $storeId);
00077 $item->setData('store_code', $storeCode);
00078 }
00079 }
00080 }
00081 }
00082
00083 parent::_afterLoad();
00084 }
00085
00086
00087
00088
00089
00090
00091
00092 public function addStoreFilter($store, $withAdmin = true)
00093 {
00094 if ($store instanceof Mage_Core_Model_Store) {
00095 $store = array($store->getId());
00096 }
00097
00098 $this->getSelect()->join(
00099 array('store_table' => $this->getTable('cms/page_store')),
00100 'main_table.page_id = store_table.page_id',
00101 array()
00102 )
00103 ->where('store_table.store_id in (?)', ($withAdmin ? array(0, $store) : $store))
00104 ->group('main_table.page_id');
00105
00106 return $this;
00107 }
00108 }