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_Adminhtml_Model_System_Store extends Varien_Object
00036 {
00037
00038
00039
00040
00041
00042
00043
00044 protected $_websiteCollection = array();
00045
00046
00047
00048
00049
00050
00051
00052 protected $_groupCollection = array();
00053
00054
00055
00056
00057
00058
00059
00060 protected $_storeCollection;
00061
00062
00063
00064
00065 private $_isAdminScopeAllowed = true;
00066
00067
00068
00069
00070
00071
00072
00073 public function __construct()
00074 {
00075 return $this->reload();
00076 }
00077
00078
00079
00080
00081
00082
00083 protected function _loadWebsiteCollection()
00084 {
00085 $this->_websiteCollection = Mage::app()->getWebsites();
00086 return $this;
00087 }
00088
00089
00090
00091
00092
00093
00094 protected function _loadGroupCollection()
00095 {
00096 $this->_groupCollection = array();
00097 foreach (Mage::app()->getWebsites() as $website) {
00098 foreach ($website->getGroups() as $group) {
00099 $this->_groupCollection[$group->getId()] = $group;
00100 }
00101 }
00102 return $this;
00103 }
00104
00105
00106
00107
00108
00109
00110 protected function _loadStoreCollection()
00111 {
00112 $this->_storeCollection = Mage::app()->getStores();
00113 return $this;
00114 }
00115
00116 public function getStoreValuesForForm($empty = false, $all = false)
00117 {
00118 $options = array();
00119 if ($empty) {
00120 $options[] = array(
00121 'label' => '',
00122 'value' => ''
00123 );
00124 }
00125 if ($all && $this->_isAdminScopeAllowed) {
00126 $options[] = array(
00127 'label' => Mage::helper('adminhtml')->__('All Store Views'),
00128 'value' => 0
00129 );
00130 }
00131
00132 foreach ($this->_websiteCollection as $website) {
00133 $websiteShow = false;
00134 foreach ($this->_groupCollection as $group) {
00135 if ($website->getId() != $group->getWebsiteId()) {
00136 continue;
00137 }
00138 $groupShow = false;
00139 foreach ($this->_storeCollection as $store) {
00140 if ($group->getId() != $store->getGroupId()) {
00141 continue;
00142 }
00143 if (!$websiteShow) {
00144 $options[] = array(
00145 'label' => $website->getName(),
00146 'value' => array()
00147 );
00148 $websiteShow = true;
00149 }
00150 if (!$groupShow) {
00151 $groupShow = true;
00152 $values = array();
00153 }
00154 $values[] = array(
00155 'label' => ' ' . $store->getName(),
00156 'value' => $store->getId()
00157 );
00158 }
00159 if ($groupShow) {
00160 $options[] = array(
00161 'label' => ' ' . $group->getName(),
00162 'value' => $values
00163 );
00164 }
00165 }
00166 }
00167 return $options;
00168 }
00169
00170 public function getWebsiteValuesForForm($empty = false, $all = false)
00171 {
00172 $options = array();
00173 if ($empty) {
00174 $options[] = array(
00175 'label' => '',
00176 'value' => ''
00177 );
00178 }
00179 if ($all && $this->_isAdminScopeAllowed) {
00180 $options[] = array(
00181 'label' => Mage::helper('adminhtml')->__('Admin'),
00182 'value' => 0
00183 );
00184 }
00185
00186 foreach ($this->_websiteCollection as $website) {
00187 $options[] = array(
00188 'label' => $website->getName(),
00189 'value' => $website->getId(),
00190 );
00191 }
00192 return $options;
00193 }
00194
00195
00196
00197
00198
00199
00200
00201
00202 public function getWebsiteOptionHash($withDefault = false, $attribute = 'name')
00203 {
00204 $options = array();
00205 foreach (Mage::app()->getWebsites((bool)$withDefault && $this->_isAdminScopeAllowed) as $website) {
00206 $options[$website->getId()] = $website->getDataUsingMethod($attribute);
00207 }
00208 return $options;
00209 }
00210
00211
00212
00213
00214
00215
00216
00217
00218 public function getStoreOptionHash($withDefault = false, $attribute = 'name')
00219 {
00220 $options = array();
00221 foreach (Mage::app()->getStores((bool)$withDefault && $this->_isAdminScopeAllowed) as $store) {
00222 $options[$store->getId()] = $store->getDataUsingMethod($attribute);
00223 }
00224 return $options;
00225 }
00226
00227
00228
00229
00230
00231
00232
00233 public function getStoreGroupOptionHash($attribute = 'name')
00234 {
00235 foreach ($this->_groupCollection as $group) {
00236 $options[$group->getId()] = $group->getDataUsingMethod($attribute);
00237 }
00238 return $options;
00239 }
00240
00241
00242
00243
00244
00245
00246
00247 public function getWebsiteName($websiteId)
00248 {
00249 foreach ($this->_websiteCollection as $website) {
00250 if ($website->getId() == $websiteId) {
00251 return $website->getName();
00252 }
00253 }
00254 return null;
00255 }
00256
00257
00258
00259
00260
00261
00262
00263 public function getGroupName($groupId)
00264 {
00265 foreach ($this->_groupCollection as $group) {
00266 if ($group->getId() == $groupId) {
00267 return $group->getName();
00268 }
00269 }
00270 return null;
00271 }
00272
00273
00274
00275
00276
00277
00278
00279 public function getStoreName($storeId)
00280 {
00281 if (isset($this->_storeCollection[$storeId])) {
00282 return $this->_storeCollection[$storeId]->getName();
00283 }
00284 return null;
00285 }
00286
00287
00288
00289
00290
00291
00292
00293 public function getStoreData($storeId)
00294 {
00295 if (isset($this->_storeCollection[$storeId])) {
00296 return $this->_storeCollection[$storeId];
00297 }
00298 return null;
00299 }
00300
00301
00302
00303
00304
00305
00306
00307 public function getStoreNameWithWebsite($storeId)
00308 {
00309 $name = '';
00310 if (is_array($storeId)) {
00311 $names = array();
00312 foreach ($storeId as $id) {
00313 $names[]= $this->getStoreNameWithWebsite($id);
00314 }
00315 $name = implode(', ', $names);
00316 }
00317 else {
00318 if (isset($this->_storeCollection[$storeId])) {
00319 $data = $this->_storeCollection[$storeId];
00320 $name .= $this->getWebsiteName($data->getWebsiteId());
00321 $name .= ($name ? '/' : '').$this->getGroupName($data->getGroupId());
00322 $name .= ($name ? '/' : '').$data->getName();
00323 }
00324 }
00325 return $name;
00326 }
00327
00328
00329
00330
00331
00332
00333 public function getWebsiteCollection()
00334 {
00335 return $this->_websiteCollection;
00336 }
00337
00338
00339
00340
00341
00342
00343 public function getGroupCollection()
00344 {
00345 return $this->_groupCollection;
00346 }
00347
00348
00349
00350
00351
00352
00353 public function getStoreCollection()
00354 {
00355 return $this->_storeCollection;
00356 }
00357
00358
00359
00360
00361
00362
00363
00364
00365 public function reload($type = null)
00366 {
00367 if (is_null($type)) {
00368 $this->_loadWebsiteCollection();
00369 $this->_loadGroupCollection();
00370 $this->_loadStoreCollection();
00371 }
00372 else {
00373 switch ($type) {
00374 case 'website':
00375 $this->_loadWebsiteCollection();
00376 break;
00377 case 'group':
00378 $this->_loadGroupCollection();
00379 break;
00380 case 'store':
00381 $this->_loadStoreCollection();
00382 break;
00383 default:
00384 break;
00385 }
00386 }
00387 return $this;
00388 }
00389
00390
00391
00392
00393
00394
00395
00396 public function getStoreNamePath($storeId)
00397 {
00398 $name = '';
00399 if (is_array($storeId)) {
00400 $names = array();
00401 foreach ($storeId as $id) {
00402 $names[]= $this->getStoreNamePath($id);
00403 }
00404 $name = implode(', ', $names);
00405 }
00406 else {
00407 if (isset($this->_storeCollection[$storeId])) {
00408 $data = $this->_storeCollection[$storeId];
00409 $name .= $this->getWebsiteName($data->getWebsiteId());
00410 $name .= ($name ? '/' : '').$this->getGroupName($data->getGroupId());
00411 }
00412 }
00413 return $name;
00414 }
00415
00416
00417
00418
00419
00420
00421
00422 public function setIsAdminScopeAllowed($value)
00423 {
00424 $this->_isAdminScopeAllowed = (bool)$value;
00425 return $this;
00426 }
00427 }