module_config.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Module_Config extends Shop_Config
00010 {
00011     protected $_sModule = 'shop_config.tpl';
00012 
00019     public function render()
00020     {
00021         $myConfig  = $this->getConfig();
00022 
00023         $sModuleId  = $this->_sModuleId = $this->getEditObjectId();
00024         $sShopId = $myConfig->getShopId();
00025 
00026         $oModule = oxNew( 'oxModule' );
00027 
00028         if ( $sModuleId && $oModule->load( $sModuleId ) ) {
00029             try {
00030                 $aDbVariables = $this->_loadMetadataConfVars($oModule->getInfo("settings"));
00031 
00032                 $this->_aViewData["var_constraints"] = $aDbVariables['constraints'];
00033                 $this->_aViewData["var_grouping"]    = $aDbVariables['grouping'];
00034                 $iCount = 0;
00035                 foreach ($this->_aConfParams as $sType => $sParam) {
00036                     $this->_aViewData[$sParam] = $aDbVariables['vars'][$sType];
00037                     $iCount += count($aDbVariables['vars'][$sType]);
00038                 }
00039             } catch (oxException $oEx) {
00040                 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx );
00041                 $oEx->debugOut();
00042             }
00043         } else {
00044             oxRegistry::get("oxUtilsView")->addErrorToDisplay( new oxException('EXCEPTION_MODULE_NOT_LOADED') );
00045         }
00046 
00047         $this->_aViewData["oModule"] =  $oModule;
00048 
00049         return 'module_config.tpl';
00050     }
00051 
00057     protected function _getModuleForConfigVars()
00058     {
00059         return oxConfig::OXMODULE_MODULE_PREFIX . $this->_sModuleId;
00060     }
00061 
00073     public function _loadMetadataConfVars($aModuleSettings)
00074     {
00075         $oConfig  = $this->getConfig();
00076 
00077         $aConfVars = array(
00078             "bool"    => array(),
00079             "str"     => array(),
00080             "arr"     => array(),
00081             "aarr"    => array(),
00082             "select"  => array(),
00083         );
00084         $aVarConstraints = array();
00085         $aGrouping       = array();
00086         
00087         $aDbVariables = $this->loadConfVars($oConfig->getShopId(), $this->_getModuleForConfigVars());
00088 
00089         if ( is_array($aModuleSettings) ) {
00090 
00091             foreach ( $aModuleSettings as $aValue ) {
00092                 $sName       = $aValue["name"];
00093                 $sType       = $aValue["type"];
00094                 $sValue = null;
00095                 if (is_null($oConfig->getConfigParam($sName)) ) {
00096                     switch ($aValue["type"]) {
00097                         case "arr":
00098                             $sValue = $this->_arrayToMultiline( $aValue["value"] );
00099                             break;
00100                         case "aarr":
00101                             $sValue = $this->_aarrayToMultiline( $aValue["value"] );
00102                             break;
00103                         case "bool":
00104                             $sValue = filter_var($aValue["value"], FILTER_VALIDATE_BOOLEAN);
00105                             break;
00106                         default:
00107                             $sValue = $aValue["value"];
00108                             break;
00109                     }
00110                     $sValue = getStr()->htmlentities( $sValue );
00111                 } else {
00112                     $sValue = $aDbVariables['vars'][$sType][$sName];
00113                 }
00114                 
00115                 $sGroup      = $aValue["group"];
00116 
00117                 $sConstraints = "";
00118                 if ( $aValue["constraints"] ) {
00119                     $sConstraints = $aValue["constraints"];
00120                 } elseif ( $aValue["constrains"] ) {
00121                     $sConstraints = $aValue["constrains"];
00122                 }
00123 
00124                 $aConfVars[$sType][$sName] = $sValue;
00125                 $aVarConstraints[$sName]   = $this->_parseConstraint( $sType, $sConstraints );
00126                 if ($sGroup) {
00127                     if (!isset($aGrouping[$sGroup])) {
00128                         $aGrouping[$sGroup] = array($sName=>$sType);
00129                     } else {
00130                         $aGrouping[$sGroup][$sName] = $sType;
00131                     }
00132                 }
00133             }
00134         }
00135 
00136         return array(
00137             'vars'        => $aConfVars,
00138             'constraints' => $aVarConstraints,
00139             'grouping'    => $aGrouping,
00140         );
00141     }
00142 
00143 
00149     public function saveConfVars()
00150     {
00151         $myConfig = $this->getConfig();
00152 
00153 
00154         $sModuleId  = $this->_sModuleId = $this->getEditObjectId();
00155         $sShopId = $myConfig->getShopId();
00156 
00157         $sModuleId = $this->_getModuleForConfigVars();
00158 
00159         foreach ($this->_aConfParams as $sType => $sParam) {
00160             $aConfVars = oxConfig::getParameter($sParam);
00161             if (is_array($aConfVars)) {
00162                 foreach ( $aConfVars as $sName => $sValue ) {
00163                     $myConfig->saveShopConfVar(
00164                             $sType,
00165                             $sName,
00166                             $this->_serializeConfVar($sType, $sName, $sValue),
00167                             $sShopId,
00168                             $sModuleId
00169                     );
00170                 }
00171             }
00172         }
00173     }
00174 
00175 }