|
Apache/2.4.41 (Ubuntu) Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) server ip : 62.171.164.128 | your ip : 127.0.0.1 safemode OFF > / home / a / home / dev2.destoffenstraat.com / app / code / Infortis / Infortis / Model / Config / |
Filename | /home/a/home/dev2.destoffenstraat.com/app/code/Infortis/Infortis/Model/Config/Scope.php |
Size | 4.05 kb |
Permission | rwxrwxrwx |
Owner | root : root |
Create time | 21-Aug-2025 12:26 |
Last modified | 06-Apr-2021 18:06 |
Last accessed | 23-Aug-2025 05:38 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to the Regular License.
* You may not use any part of the code in whole or part in any other software
* or product or website.
*
* @author Infortis
* @copyright Copyright (c) 2014 Infortis
* @license Regular License http://themeforest.net/licenses/regular
*/
namespace Infortis\Infortis\Model\Config;
use Magento\Store\Model\System\Store;
class Scope
{
/**
* @var Store
*/
protected $_systemStore;
public function __construct(Store $systemStore)
{
$this->_systemStore = $systemStore;
}
const SCOPE_DEFAULT = 'default';
const SCOPE_WEBSITES = 'websites';
const SCOPE_STORES = 'stores';
const SCOPE_DELIMITER = '@';
protected $_options;
/**
* Retrieve scope values for form, compatible with form dropdown options
*
* @param bool
* @param bool
* @return array
*/
public function getScopeSelectOptions($empty = false, $all = false)
{
if (!$this->_options)
{
$options = [];
if ($empty)
{
$options[] = [
'label' => __('-- Please Select --'),
'value' => '',
];
}
if ($all)
{
$options[] = [
'label' => __('Default Config'),
'value' => self::SCOPE_DEFAULT . self::SCOPE_DELIMITER . '0', 'style' => 'color:#1EB5F0;',
];
}
$nonEscapableNbspChar = html_entity_decode(' ', ENT_NOQUOTES, 'UTF-8');
$storeModel = $this->_systemStore;
/* @var $storeModel Store */
foreach ($storeModel->getWebsiteCollection() as $website)
{
$websiteShow = false;
foreach ($storeModel->getGroupCollection() as $group)
{
if ($group->getWebsiteId() != $website->getId())
{
continue;
}
$groupShow = false;
foreach ($storeModel->getStoreCollection() as $store)
{
if ($store->getGroupId() != $group->getId())
{
continue;
}
if (!$websiteShow)
{
$options[] = [
'label' => $website->getName(),
'value' => self::SCOPE_WEBSITES . self::SCOPE_DELIMITER . $website->getId(),
];
$websiteShow = true;
}
if (!$groupShow)
{
$groupShow = true;
$values = [];
}
$values[] = [
'label' => str_repeat($nonEscapableNbspChar, 4) . $store->getName(),
'value' => self::SCOPE_STORES . self::SCOPE_DELIMITER . $store->getId(),
];
} //end: foreach store
if ($groupShow)
{
$options[] = [
'label' => str_repeat($nonEscapableNbspChar, 4) . $group->getName(),
'value' => $values,
];
}
} //end: foreach group
} //end: foreach website
$this->_options = $options;
}
return $this->_options;
}
/**
* Decode scope code: retrieve scope and scope id from the scope code and return values as an array
*
* @param string
* @return array
*/
public function decodeScope($str)
{
//Check if correct format of input (should contain proper delimiter)
if (FALSE === strstr($str, self::SCOPE_DELIMITER))
{
throw new \Exception('Incorrect format of scope/scopeId value.');
//If single store mode supported:
//Single id without delimiter is a store id
/*if (!$str)
{
$output['scope'] = self::SCOPE_DEFAULT;
$output['scopeId'] = '0';
}
else
{
$output['scope'] = self::SCOPE_STORES;
$output['scopeId'] = $str;
}*/
}
//Split input value to get scope and scope id
$values = explode(self::SCOPE_DELIMITER, $str);
$output = [];
$output['scope'] = $values[0];
$output['scopeId'] = $values[1];
return $output;
}
/**
* Encode scope code: create scope code based on store id
*
* @param string|int
* @return string
*/
public function encodeScopeUsingStoreId($storeId)
{
$storeId = intval($storeId);
if ($storeId === 0)
{
$scope = self::SCOPE_DEFAULT . self::SCOPE_DELIMITER . '0';
}
else
{
$scope = self::SCOPE_STORES . self::SCOPE_DELIMITER . $storeId;
}
return $scope;
}
}
/**
* NOTICE OF LICENSE
*
* This source file is subject to the Regular License.
* You may not use any part of the code in whole or part in any other software
* or product or website.
*
* @author Infortis
* @copyright Copyright (c) 2014 Infortis
* @license Regular License http://themeforest.net/licenses/regular
*/
namespace Infortis\Infortis\Model\Config;
use Magento\Store\Model\System\Store;
class Scope
{
/**
* @var Store
*/
protected $_systemStore;
public function __construct(Store $systemStore)
{
$this->_systemStore = $systemStore;
}
const SCOPE_DEFAULT = 'default';
const SCOPE_WEBSITES = 'websites';
const SCOPE_STORES = 'stores';
const SCOPE_DELIMITER = '@';
protected $_options;
/**
* Retrieve scope values for form, compatible with form dropdown options
*
* @param bool
* @param bool
* @return array
*/
public function getScopeSelectOptions($empty = false, $all = false)
{
if (!$this->_options)
{
$options = [];
if ($empty)
{
$options[] = [
'label' => __('-- Please Select --'),
'value' => '',
];
}
if ($all)
{
$options[] = [
'label' => __('Default Config'),
'value' => self::SCOPE_DEFAULT . self::SCOPE_DELIMITER . '0', 'style' => 'color:#1EB5F0;',
];
}
$nonEscapableNbspChar = html_entity_decode(' ', ENT_NOQUOTES, 'UTF-8');
$storeModel = $this->_systemStore;
/* @var $storeModel Store */
foreach ($storeModel->getWebsiteCollection() as $website)
{
$websiteShow = false;
foreach ($storeModel->getGroupCollection() as $group)
{
if ($group->getWebsiteId() != $website->getId())
{
continue;
}
$groupShow = false;
foreach ($storeModel->getStoreCollection() as $store)
{
if ($store->getGroupId() != $group->getId())
{
continue;
}
if (!$websiteShow)
{
$options[] = [
'label' => $website->getName(),
'value' => self::SCOPE_WEBSITES . self::SCOPE_DELIMITER . $website->getId(),
];
$websiteShow = true;
}
if (!$groupShow)
{
$groupShow = true;
$values = [];
}
$values[] = [
'label' => str_repeat($nonEscapableNbspChar, 4) . $store->getName(),
'value' => self::SCOPE_STORES . self::SCOPE_DELIMITER . $store->getId(),
];
} //end: foreach store
if ($groupShow)
{
$options[] = [
'label' => str_repeat($nonEscapableNbspChar, 4) . $group->getName(),
'value' => $values,
];
}
} //end: foreach group
} //end: foreach website
$this->_options = $options;
}
return $this->_options;
}
/**
* Decode scope code: retrieve scope and scope id from the scope code and return values as an array
*
* @param string
* @return array
*/
public function decodeScope($str)
{
//Check if correct format of input (should contain proper delimiter)
if (FALSE === strstr($str, self::SCOPE_DELIMITER))
{
throw new \Exception('Incorrect format of scope/scopeId value.');
//If single store mode supported:
//Single id without delimiter is a store id
/*if (!$str)
{
$output['scope'] = self::SCOPE_DEFAULT;
$output['scopeId'] = '0';
}
else
{
$output['scope'] = self::SCOPE_STORES;
$output['scopeId'] = $str;
}*/
}
//Split input value to get scope and scope id
$values = explode(self::SCOPE_DELIMITER, $str);
$output = [];
$output['scope'] = $values[0];
$output['scopeId'] = $values[1];
return $output;
}
/**
* Encode scope code: create scope code based on store id
*
* @param string|int
* @return string
*/
public function encodeScopeUsingStoreId($storeId)
{
$storeId = intval($storeId);
if ($storeId === 0)
{
$scope = self::SCOPE_DEFAULT . self::SCOPE_DELIMITER . '0';
}
else
{
$scope = self::SCOPE_STORES . self::SCOPE_DELIMITER . $storeId;
}
return $scope;
}
}