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 class Mage_Adminhtml_Block_Store_Switcher extends Mage_Adminhtml_Block_Template
00035 {
00036
00037
00038
00039 protected $_storeIds;
00040
00041
00042
00043
00044 protected $_hasDefaultOption = true;
00045
00046 public function __construct()
00047 {
00048 parent::__construct();
00049 $this->setTemplate('store/switcher.phtml');
00050 $this->setUseConfirm(true);
00051 $this->setUseAjax(true);
00052 $this->setDefaultStoreName($this->__('All Store Views'));
00053 }
00054
00055
00056
00057
00058 public function getWebsiteCollection()
00059 {
00060 $collection = Mage::getModel('core/website')->getResourceCollection();
00061
00062 $websiteIds = $this->getWebsiteIds();
00063 if (!is_null($websiteIds)) {
00064 $collection->addIdFilter($this->getWebsiteIds());
00065 }
00066
00067 return $collection->load();
00068 }
00069
00070
00071
00072
00073
00074
00075 public function getWebsites()
00076 {
00077 $websites = Mage::app()->getWebsites();
00078 if ($websiteIds = $this->getWebsiteIds()) {
00079 foreach ($websites as $websiteId => $website) {
00080 if (!in_array($websiteId, $websiteIds)) {
00081 unset($websites[$websiteId]);
00082 }
00083 }
00084 }
00085 return $websites;
00086 }
00087
00088
00089
00090
00091 public function getGroupCollection($website)
00092 {
00093 if (!$website instanceof Mage_Core_Model_Website) {
00094 $website = Mage::getModel('core/website')->load($website);
00095 }
00096 return $website->getGroupCollection();
00097 }
00098
00099
00100
00101
00102
00103
00104
00105 public function getStoreGroups($website)
00106 {
00107 if (!$website instanceof Mage_Core_Model_Website) {
00108 $website = Mage::app()->getWebsite($website);
00109 }
00110 return $website->getGroups();
00111 }
00112
00113
00114
00115
00116 public function getStoreCollection($group)
00117 {
00118 if (!$group instanceof Mage_Core_Model_Store_Group) {
00119 $group = Mage::getModel('core/store_group')->load($group);
00120 }
00121 $stores = $group->getStoreCollection();
00122 $_storeIds = $this->getStoreIds();
00123 if (!empty($_storeIds)) {
00124 $stores->addIdFilter($_storeIds);
00125 }
00126 return $stores;
00127 }
00128
00129
00130
00131
00132
00133
00134
00135 public function getStores($group)
00136 {
00137 if (!$group instanceof Mage_Core_Model_Store_Group) {
00138 $group = Mage::app()->getGroup($group);
00139 }
00140 $stores = $group->getStores();
00141 if ($storeIds = $this->getStoreIds()) {
00142 foreach ($stores as $storeId => $store) {
00143 if (!in_array($storeId, $storeIds)) {
00144 unset($stores[$storeId]);
00145 }
00146 }
00147 }
00148 return $stores;
00149 }
00150
00151 public function getSwitchUrl()
00152 {
00153 if ($url = $this->getData('switch_url')) {
00154 return $url;
00155 }
00156 return $this->getUrl('*/*/*', array('_current' => true, 'store' => null));
00157 }
00158
00159 public function getStoreId()
00160 {
00161 return $this->getRequest()->getParam('store');
00162 }
00163
00164 public function setStoreIds($storeIds)
00165 {
00166 $this->_storeIds = $storeIds;
00167 return $this;
00168 }
00169
00170 public function getStoreIds()
00171 {
00172 return $this->_storeIds;
00173 }
00174
00175 public function isShow()
00176 {
00177 return !Mage::app()->isSingleStoreMode();
00178 }
00179
00180 protected function _toHtml()
00181 {
00182 if (!Mage::app()->isSingleStoreMode()) {
00183 return parent::_toHtml();
00184 }
00185 return '';
00186 }
00187
00188
00189
00190
00191
00192
00193
00194 public function hasDefaultOption($hasDefaultOption = null)
00195 {
00196 if (null !== $hasDefaultOption) {
00197 $this->_hasDefaultOption = $hasDefaultOption;
00198 }
00199 return $this->_hasDefaultOption;
00200 }
00201 }