[Changed] data getter to state-of-the-art
and removed unnecessary code/ try-outs
This commit is contained in:
@ -13,16 +13,24 @@ use OxidEsales\Eshop\Core\Registry;
|
|||||||
use OxidEsales\Eshop\Core\Str;
|
use OxidEsales\Eshop\Core\Str;
|
||||||
use OxidEsales\Eshop\Core\ViewConfig;
|
use OxidEsales\Eshop\Core\ViewConfig;
|
||||||
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
||||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleConfigurationDaoBridge;
|
|
||||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleConfigurationDaoBridgeInterface;
|
|
||||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingService;
|
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingService;
|
||||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
|
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
|
||||||
|
|
||||||
class GA4AdminUserInterface_main extends \OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController
|
class GA4AdminUserInterface_main extends \OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController
|
||||||
{
|
{
|
||||||
protected $_sThisTemplate = '@' . Constants::OXID_MODULE_ID . '/admin/d3ga4uimain';
|
protected $_sThisTemplate = '@' . Constants::OXID_MODULE_ID . '/admin/d3ga4uimain';
|
||||||
|
protected $GA4ModuleSettingNameArray = [];
|
||||||
public function render()
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
/*if (empty($this->GA4ModuleSettingNameArray) or count($this->GA4ModuleSettingNameArray) === 0){
|
||||||
|
$this->GA4ModuleSettingNameArray = $this->d3GetModuleSettingNameArray();
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render()
|
||||||
{
|
{
|
||||||
$return = parent::render();
|
$return = parent::render();
|
||||||
|
|
||||||
@ -30,100 +38,10 @@ class GA4AdminUserInterface_main extends \OxidEsales\Eshop\Application\Controlle
|
|||||||
$this->addTplParam('d3ViewConfObject', Registry::get(ViewConfig::class));
|
$this->addTplParam('d3ViewConfObject', Registry::get(ViewConfig::class));
|
||||||
$this->addTplParam('d3ManagerTypeArray', oxNew(ManagerTypes::class)->getManagerList());
|
$this->addTplParam('d3ManagerTypeArray', oxNew(ManagerTypes::class)->getManagerList());
|
||||||
$this->addTplParam('d3CurrentCMP', oxNew(ManagerHandler::class)->getActManager());
|
$this->addTplParam('d3CurrentCMP', oxNew(ManagerHandler::class)->getActManager());
|
||||||
|
|
||||||
$tmpArray = [];
|
|
||||||
|
|
||||||
try {
|
|
||||||
$moduleConfiguration = ContainerFactory::getInstance()
|
|
||||||
->getContainer()
|
|
||||||
->get(ModuleConfigurationDaoBridgeInterface::class)
|
|
||||||
->get(Constants::OXID_MODULE_ID);
|
|
||||||
|
|
||||||
if (!empty($moduleConfiguration->getModuleSettings())) {
|
|
||||||
$formatModuleSettings = $this
|
|
||||||
->d3FormatModuleSettingsForTemplate($moduleConfiguration->getModuleSettings());
|
|
||||||
|
|
||||||
$tmpArray["var_constraints"] = $formatModuleSettings['constraints'];
|
|
||||||
$tmpArray["var_grouping"] = $formatModuleSettings['grouping'];
|
|
||||||
|
|
||||||
foreach ($this->_aConfParams as $sType => $sParam) {
|
|
||||||
$tmpArray[$sParam] = $formatModuleSettings['vars'][$sType] ?? null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (\Throwable $throwable) {
|
|
||||||
Registry::getUtilsView()->addErrorToDisplay($throwable);
|
|
||||||
Registry::getLogger()->error($throwable->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
$module = oxNew(Module::class);
|
|
||||||
$module->load(Constants::OXID_MODULE_ID);
|
|
||||||
|
|
||||||
dumpVar($module->getModuleData()['settings']);
|
|
||||||
echo "<hr><hr><hr><hr><hr><hr>";
|
|
||||||
dumpVar($tmpArray);
|
|
||||||
die;
|
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function d3FormatModuleSettingsForTemplate(array $moduleSettings): array
|
|
||||||
{
|
|
||||||
$confVars = [
|
|
||||||
'bool' => [],
|
|
||||||
'str' => [],
|
|
||||||
'arr' => [],
|
|
||||||
'aarr' => [],
|
|
||||||
'select' => [],
|
|
||||||
'password' => [],
|
|
||||||
];
|
|
||||||
$constraints = [];
|
|
||||||
$grouping = [];
|
|
||||||
|
|
||||||
foreach ($moduleSettings as $setting) {
|
|
||||||
$name = $setting->getName();
|
|
||||||
$valueType = $setting->getType();
|
|
||||||
$value = null;
|
|
||||||
|
|
||||||
if ($setting->getValue() !== null) {
|
|
||||||
switch ($setting->getType()) {
|
|
||||||
case 'arr':
|
|
||||||
$value = $this->arrayToMultiline($setting->getValue());
|
|
||||||
break;
|
|
||||||
case 'aarr':
|
|
||||||
$value = $this->aarrayToMultiline($setting->getValue());
|
|
||||||
break;
|
|
||||||
case 'bool':
|
|
||||||
$value = filter_var($setting->getValue(), FILTER_VALIDATE_BOOLEAN);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$value = $setting->getValue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
$value = Str::getStr()->htmlentities($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
$group = $setting->getGroupName();
|
|
||||||
|
|
||||||
|
|
||||||
$confVars[$valueType][$name] = $value;
|
|
||||||
$constraints[$name] = $setting->getConstraints() ?? '';
|
|
||||||
|
|
||||||
if ($group) {
|
|
||||||
if (!isset($grouping[$group])) {
|
|
||||||
$grouping[$group] = [$name => $valueType];
|
|
||||||
} else {
|
|
||||||
$grouping[$group][$name] = $valueType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
'vars' => $confVars,
|
|
||||||
'constraints' => $constraints,
|
|
||||||
'grouping' => $grouping,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function save()
|
public function save()
|
||||||
{
|
{
|
||||||
parent::save();
|
parent::save();
|
||||||
@ -175,11 +93,11 @@ class GA4AdminUserInterface_main extends \OxidEsales\Eshop\Application\Controlle
|
|||||||
return $this->d3GetModuleSettings()
|
return $this->d3GetModuleSettings()
|
||||||
->exists(Constants::OXID_MODULE_ID.$sSettingName, Constants::OXID_MODULE_ID);
|
->exists(Constants::OXID_MODULE_ID.$sSettingName, Constants::OXID_MODULE_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $aParams
|
* @param array $aParams
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function d3SaveShopConfigVars(array $aParams)
|
protected function d3SaveShopConfigVars(array $aParams)
|
||||||
{
|
{
|
||||||
foreach ($aParams as $sConfigType => $aConfigParams) {
|
foreach ($aParams as $sConfigType => $aConfigParams) {
|
||||||
@ -216,49 +134,14 @@ class GA4AdminUserInterface_main extends \OxidEsales\Eshop\Application\Controlle
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $configParamName
|
* @param string $configParamName
|
||||||
* @return mixed
|
* @param bool $displayThrowable
|
||||||
*/
|
* @return mixed
|
||||||
public function d3GetModuleConfigParam(string $configParamName)
|
*/
|
||||||
|
public function d3GetModuleConfigParam(string $configParamName, bool $displayThrowable = false)
|
||||||
{
|
{
|
||||||
$container = ContainerFactory::getInstance()->getContainer();
|
return Registry::get(ViewConfig::class)->d3GetModuleConfigParam($configParamName, $displayThrowable);
|
||||||
$moduleConfiguration = $container->get(ModuleConfigurationDaoBridgeInterface::class)->get($moduleId);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return Registry::get(ViewConfig::class)->d3GetModuleConfigParam($configParamName);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function d3convertSettingsToArray(\OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration $moduleConfiguration): array
|
|
||||||
{
|
|
||||||
$data = [];
|
|
||||||
|
|
||||||
foreach ($moduleConfiguration->getModuleSettings() as $index => $setting) {
|
|
||||||
if ($setting->getGroupName()) {
|
|
||||||
$data[$index]['group'] = $setting->getGroupName();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($setting->getName()) {
|
|
||||||
$data[$index]['name'] = $setting->getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($setting->getType()) {
|
|
||||||
$data[$index]['type'] = $setting->getType();
|
|
||||||
}
|
|
||||||
|
|
||||||
$data[$index]['value'] = $setting->getValue();
|
|
||||||
|
|
||||||
if (!empty($setting->getConstraints())) {
|
|
||||||
$data[$index]['constraints'] = $setting->getConstraints();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($setting->getPositionInGroup() > 0) {
|
|
||||||
$data[$index]['position'] = $setting->getPositionInGroup();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -22,7 +22,11 @@ use OxidEsales\Eshop\Core\Config;
|
|||||||
use OxidEsales\Eshop\Application\Model\User;
|
use OxidEsales\Eshop\Application\Model\User;
|
||||||
use OxidEsales\Eshop\Core\Registry;
|
use OxidEsales\Eshop\Core\Registry;
|
||||||
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
|
||||||
|
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Bridge\ModuleConfigurationDaoBridgeInterface;
|
||||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Exception\ModuleConfigurationNotFoundException;
|
use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Exception\ModuleConfigurationNotFoundException;
|
||||||
|
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingService;
|
||||||
|
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingServiceInterface;
|
||||||
|
use OxidEsales\EshopCommunity\Internal\Framework\Module\Setting\Setting;
|
||||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Setup\Bridge\ModuleActivationBridgeInterface;
|
use OxidEsales\EshopCommunity\Internal\Framework\Module\Setup\Bridge\ModuleActivationBridgeInterface;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
@ -166,7 +170,7 @@ class ViewConfig extends ViewConfig_parent
|
|||||||
public function isGA4enabled()
|
public function isGA4enabled()
|
||||||
{
|
{
|
||||||
if ($this->blGA4enabled === null) {
|
if ($this->blGA4enabled === null) {
|
||||||
$this->blGA4enabled = $this->d3GetModuleConfigParam("_blEnableGA4");
|
$this->blGA4enabled = $this->d3GetModuleConfigParam("_blEnableGa4");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->blGA4enabled;
|
return $this->blGA4enabled;
|
||||||
@ -251,16 +255,51 @@ class ViewConfig extends ViewConfig_parent
|
|||||||
{
|
{
|
||||||
return $this->d3GetModuleConfigParam('_sServersidetagging_nojs') ?: "";
|
return $this->d3GetModuleConfigParam('_sServersidetagging_nojs') ?: "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $configParamName
|
* @param string $configParamName
|
||||||
* @return mixed
|
* @param bool $displayThrowable
|
||||||
*/
|
* @return bool|object|string
|
||||||
public function d3GetModuleConfigParam(string $configParamName)
|
*/
|
||||||
|
public function d3GetModuleConfigParam(string $configParamName, bool $displayThrowable = false)
|
||||||
{
|
{
|
||||||
return Registry::getConfig()->getShopConfVar(Constants::OXID_MODULE_ID.$configParamName, null, Constants::OXID_MODULE_ID);
|
try {
|
||||||
|
return $this->d3GetGa4ModuleConfigurationBridge()->getModuleSetting(Constants::OXID_MODULE_ID.$configParamName)->getValue();
|
||||||
|
} catch (\Throwable $throwable) {
|
||||||
|
if ($displayThrowable){
|
||||||
|
Registry::getUtilsView()->addErrorToDisplay($throwable);
|
||||||
|
}
|
||||||
|
Registry::getLogger()->error($throwable->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration
|
||||||
|
* @throws \Psr\Container\ContainerExceptionInterface
|
||||||
|
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||||
|
*/
|
||||||
|
public function d3GetGa4ModuleConfigurationBridge() :\OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration
|
||||||
|
{
|
||||||
|
/** @var \OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\DataObject\ModuleConfiguration $oModuleSettingsBridge */
|
||||||
|
return ContainerFactory::getInstance()
|
||||||
|
->getContainer()
|
||||||
|
->get(ModuleConfigurationDaoBridgeInterface::class)->get(Constants::OXID_MODULE_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function d3GetModuleSettingNameArray() :array
|
||||||
|
{
|
||||||
|
$tmp = [];
|
||||||
|
|
||||||
|
foreach ($this->d3GetGa4ModuleConfigurationBridge()->getModuleSettings() as $arrayEntry){
|
||||||
|
$tmp[] = $arrayEntry->getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tmp;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user