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 
00093                 $sName       = $aValue["name"];
00094                 $sType       = $aValue["type"];
00095                 $sValue = null;
00096                 //$sValue      = is_null($oConfig->getConfigParam($sName))?$aValue["value"]:$oConfig->getConfigParam($sName);
00097                 if (is_null($oConfig->getConfigParam($sName)) ) {
00098                     switch ($aValue["type"]){
00099                         case "arr":
00100                             $sValue = $this->_arrayToMultiline( unserialize( $aValue["value"] ) );
00101                             break;
00102                         case "aarr":
00103                             $sValue = $this->_aarrayToMultiline( unserialize( $aValue["value"] ) );
00104                             break;
00105                     }
00106                     $sValue = getStr()->htmlentities( $sValue );
00107                 } else {
00108                     $sValue = $aDbVariables['vars'][$sType][$sName];
00109                 }
00110                 
00111                 $sGroup      = $aValue["group"];
00112 
00113                 $sConstraints = "";
00114                 if ( $aValue["constraints"] ) {
00115                     $sConstraints = $aValue["constraints"];
00116                 } elseif ( $aValue["constrains"] ) {
00117                     $sConstraints = $aValue["constrains"];
00118                 }
00119 
00120                 $aConfVars[$sType][$sName] = $sValue;
00121                 $aVarConstraints[$sName]   = $this->_parseConstraint( $sType, $sConstraints );
00122                 if ($sGroup) {
00123                     if (!isset($aGrouping[$sGroup])) {
00124                         $aGrouping[$sGroup] = array($sName=>$sType);
00125                     } else {
00126                         $aGrouping[$sGroup][$sName] = $sType;
00127                     }
00128                 }
00129             }
00130         }
00131 
00132         return array(
00133             'vars'        => $aConfVars,
00134             'constraints' => $aVarConstraints,
00135             'grouping'    => $aGrouping,
00136         );
00137     }
00138 
00139 
00145     public function saveConfVars()
00146     {
00147         $myConfig = $this->getConfig();
00148 
00149 
00150         $sModuleId  = $this->_sModuleId = $this->getEditObjectId();
00151         $sShopId = $myConfig->getShopId();
00152 
00153         $sModuleId = $this->_getModuleForConfigVars();
00154 
00155         foreach ($this->_aConfParams as $sType => $sParam) {
00156             $aConfVars = oxConfig::getParameter($sParam);
00157             if (is_array($aConfVars)) {
00158                 foreach ( $aConfVars as $sName => $sValue ) {
00159                     $myConfig->saveShopConfVar(
00160                             $sType,
00161                             $sName,
00162                             $this->_serializeConfVar($sType, $sName, $sValue),
00163                             $sShopId,
00164                             $sModuleId
00165                     );
00166                 }
00167             }
00168         }
00169     }
00170 
00171 }