module_config.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Module_Config extends Shop_Config
00010 {
00011 
00012     protected $_sModule = 'shop_config.tpl';
00013 
00017     public function __construct()
00018     {
00019         parent::__construct();
00020         $this->_aConfParams['password'] = 'confpassword';
00021     }
00022 
00029     public function render()
00030     {
00031         $myConfig = $this->getConfig();
00032 
00033         $sModuleId = $this->_sModuleId = $this->getEditObjectId();
00034         $sShopId = $myConfig->getShopId();
00035 
00036         $oModule = oxNew('oxModule');
00037 
00038         if ($sModuleId && $oModule->load($sModuleId)) {
00039             try {
00040                 $aDbVariables = $this->_loadMetadataConfVars($oModule->getInfo("settings"));
00041 
00042                 $this->_aViewData["var_constraints"] = $aDbVariables['constraints'];
00043                 $this->_aViewData["var_grouping"] = $aDbVariables['grouping'];
00044                 $iCount = 0;
00045                 foreach ($this->_aConfParams as $sType => $sParam) {
00046                     $this->_aViewData[$sParam] = $aDbVariables['vars'][$sType];
00047                     $iCount += count($aDbVariables['vars'][$sType]);
00048                 }
00049             } catch (oxException $oEx) {
00050                 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
00051                 $oEx->debugOut();
00052             }
00053         } else {
00054             oxRegistry::get("oxUtilsView")->addErrorToDisplay(new oxException('EXCEPTION_MODULE_NOT_LOADED'));
00055         }
00056 
00057         $this->_aViewData["oModule"] = $oModule;
00058 
00059         return 'module_config.tpl';
00060     }
00061 
00067     protected function _getModuleForConfigVars()
00068     {
00069         return oxConfig::OXMODULE_MODULE_PREFIX . $this->_sModuleId;
00070     }
00071 
00083     public function _loadMetadataConfVars($aModuleSettings)
00084     {
00085         $oConfig = $this->getConfig();
00086 
00087         $aConfVars = array(
00088             "bool"     => array(),
00089             "str"      => array(),
00090             "arr"      => array(),
00091             "aarr"     => array(),
00092             "select"   => array(),
00093             "password" => array(),
00094         );
00095         $aVarConstraints = array();
00096         $aGrouping = array();
00097 
00098         $aDbVariables = $this->loadConfVars($oConfig->getShopId(), $this->_getModuleForConfigVars());
00099 
00100         if (is_array($aModuleSettings)) {
00101 
00102             foreach ($aModuleSettings as $aValue) {
00103                 $sName = $aValue["name"];
00104                 $sType = $aValue["type"];
00105                 $sValue = null;
00106                 if (is_null($oConfig->getConfigParam($sName))) {
00107                     switch ($aValue["type"]) {
00108                         case "arr":
00109                             $sValue = $this->_arrayToMultiline($aValue["value"]);
00110                             break;
00111                         case "aarr":
00112                             $sValue = $this->_aarrayToMultiline($aValue["value"]);
00113                             break;
00114                         case "bool":
00115                             $sValue = filter_var($aValue["value"], FILTER_VALIDATE_BOOLEAN);
00116                             break;
00117                         default:
00118                             $sValue = $aValue["value"];
00119                             break;
00120                     }
00121                     $sValue = getStr()->htmlentities($sValue);
00122                 } else {
00123                     $sDbType = $this->_getDbConfigTypeName($sType);
00124                     $sValue = $aDbVariables['vars'][$sDbType][$sName];
00125                 }
00126 
00127                 $sGroup = $aValue["group"];
00128 
00129                 $sConstraints = "";
00130                 if ($aValue["constraints"]) {
00131                     $sConstraints = $aValue["constraints"];
00132                 } elseif ($aValue["constrains"]) {
00133                     $sConstraints = $aValue["constrains"];
00134                 }
00135 
00136                 $aConfVars[$sType][$sName] = $sValue;
00137                 $aVarConstraints[$sName] = $this->_parseConstraint($sType, $sConstraints);
00138                 if ($sGroup) {
00139                     if (!isset($aGrouping[$sGroup])) {
00140                         $aGrouping[$sGroup] = array($sName => $sType);
00141                     } else {
00142                         $aGrouping[$sGroup][$sName] = $sType;
00143                     }
00144                 }
00145             }
00146         }
00147 
00148         return array(
00149             'vars'        => $aConfVars,
00150             'constraints' => $aVarConstraints,
00151             'grouping'    => $aGrouping,
00152         );
00153     }
00154 
00155 
00159     public function saveConfVars()
00160     {
00161         $oConfig = $this->getConfig();
00162 
00163         $this->resetContentCache();
00164 
00165         $sModuleId = $this->_sModuleId = $this->getEditObjectId();
00166         $sShopId = $oConfig->getShopId();
00167 
00168         $sModuleId = $this->_getModuleForConfigVars();
00169 
00170         foreach ($this->_aConfParams as $sType => $sParam) {
00171             $aConfVars = $oConfig->getRequestParameter($sParam);
00172             if (is_array($aConfVars)) {
00173                 foreach ($aConfVars as $sName => $sValue) {
00174                     $sDbType = $this->_getDbConfigTypeName($sType);
00175                     $oConfig->saveShopConfVar(
00176                         $sDbType,
00177                         $sName,
00178                         $this->_serializeConfVar($sDbType, $sName, $sValue),
00179                         $sShopId,
00180                         $sModuleId
00181                     );
00182                 }
00183             }
00184         }
00185     }
00186 
00194     private function _getDbConfigTypeName($sType)
00195     {
00196         $sDbType = $sType;
00197         if ($sType === 'password') {
00198             $sDbType = 'str';
00199         }
00200 
00201         return $sDbType;
00202     }
00203 
00204 }