From 8c50d921f1c226d2b7834befa78a6a57053a3675 Mon Sep 17 00:00:00 2001 From: MaxBuhe01 Date: Sun, 29 Jun 2025 01:36:55 +0200 Subject: [PATCH] [Changed] data getter to state-of-the-art and removed unnecessary code/ try-outs --- .../Admin/GA4AdminUserInterface_main.php | 169 +++--------------- Modules/Core/ViewConfig.php | 57 +++++- 2 files changed, 74 insertions(+), 152 deletions(-) diff --git a/Application/Controller/Admin/GA4AdminUserInterface_main.php b/Application/Controller/Admin/GA4AdminUserInterface_main.php index dcf96c0..3735e19 100644 --- a/Application/Controller/Admin/GA4AdminUserInterface_main.php +++ b/Application/Controller/Admin/GA4AdminUserInterface_main.php @@ -13,16 +13,24 @@ use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Str; use OxidEsales\Eshop\Core\ViewConfig; 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\ModuleSettingServiceInterface; class GA4AdminUserInterface_main extends \OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController { protected $_sThisTemplate = '@' . Constants::OXID_MODULE_ID . '/admin/d3ga4uimain'; - - public function render() + protected $GA4ModuleSettingNameArray = []; + + public function init() + { + parent::init(); + + /*if (empty($this->GA4ModuleSettingNameArray) or count($this->GA4ModuleSettingNameArray) === 0){ + $this->GA4ModuleSettingNameArray = $this->d3GetModuleSettingNameArray(); + }*/ + } + + public function 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('d3ManagerTypeArray', oxNew(ManagerTypes::class)->getManagerList()); $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 "





"; - dumpVar($tmpArray); - die; - + 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() { parent::save(); @@ -175,11 +93,11 @@ class GA4AdminUserInterface_main extends \OxidEsales\Eshop\Application\Controlle return $this->d3GetModuleSettings() ->exists(Constants::OXID_MODULE_ID.$sSettingName, Constants::OXID_MODULE_ID); } - - /** - * @param array $aParams - * @return void - */ + + /** + * @param array $aParams + * @return void + */ protected function d3SaveShopConfigVars(array $aParams) { foreach ($aParams as $sConfigType => $aConfigParams) { @@ -216,49 +134,14 @@ class GA4AdminUserInterface_main extends \OxidEsales\Eshop\Application\Controlle } } } - - /** - * @param string $configParamName - * @return mixed - */ - public function d3GetModuleConfigParam(string $configParamName) + + /** + * @param string $configParamName + * @param bool $displayThrowable + * @return mixed + */ + public function d3GetModuleConfigParam(string $configParamName, bool $displayThrowable = false) { - $container = ContainerFactory::getInstance()->getContainer(); - $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; + return Registry::get(ViewConfig::class)->d3GetModuleConfigParam($configParamName, $displayThrowable); } } \ No newline at end of file diff --git a/Modules/Core/ViewConfig.php b/Modules/Core/ViewConfig.php index 71da8a1..c2265a2 100644 --- a/Modules/Core/ViewConfig.php +++ b/Modules/Core/ViewConfig.php @@ -22,7 +22,11 @@ use OxidEsales\Eshop\Core\Config; use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Core\Registry; 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\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 Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; @@ -166,7 +170,7 @@ class ViewConfig extends ViewConfig_parent public function isGA4enabled() { if ($this->blGA4enabled === null) { - $this->blGA4enabled = $this->d3GetModuleConfigParam("_blEnableGA4"); + $this->blGA4enabled = $this->d3GetModuleConfigParam("_blEnableGa4"); } return $this->blGA4enabled; @@ -251,16 +255,51 @@ class ViewConfig extends ViewConfig_parent { return $this->d3GetModuleConfigParam('_sServersidetagging_nojs') ?: ""; } - - /** - * @param string $configParamName - * @return mixed - */ - public function d3GetModuleConfigParam(string $configParamName) + + /** + * @param string $configParamName + * @param bool $displayThrowable + * @return bool|object|string + */ + 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 */