OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
module_config.php
Go to the documentation of this file.
1 <?php
2 
10 {
11  protected $_sModule = 'shop_config.tpl';
12 
19  public function render()
20  {
21  $myConfig = $this->getConfig();
22 
23  $sModuleId = $this->_sModuleId = $this->getEditObjectId();
24  $sShopId = $myConfig->getShopId();
25 
26  $oModule = oxNew( 'oxModule' );
27 
28  if ( $sModuleId && $oModule->load( $sModuleId ) ) {
29  try {
30  $aDbVariables = $this->_loadMetadataConfVars($oModule->getInfo("settings"));
31 
32  $this->_aViewData["var_constraints"] = $aDbVariables['constraints'];
33  $this->_aViewData["var_grouping"] = $aDbVariables['grouping'];
34  $iCount = 0;
35  foreach ($this->_aConfParams as $sType => $sParam) {
36  $this->_aViewData[$sParam] = $aDbVariables['vars'][$sType];
37  $iCount += count($aDbVariables['vars'][$sType]);
38  }
39  } catch (oxException $oEx) {
40  oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx );
41  $oEx->debugOut();
42  }
43  } else {
44  oxRegistry::get("oxUtilsView")->addErrorToDisplay( new oxException('EXCEPTION_MODULE_NOT_LOADED') );
45  }
46 
47  $this->_aViewData["oModule"] = $oModule;
48 
49  return 'module_config.tpl';
50  }
51 
57  protected function _getModuleForConfigVars()
58  {
59  return oxConfig::OXMODULE_MODULE_PREFIX . $this->_sModuleId;
60  }
61 
73  public function _loadMetadataConfVars($aModuleSettings)
74  {
75  $oConfig = $this->getConfig();
76 
77  $aConfVars = array(
78  "bool" => array(),
79  "str" => array(),
80  "arr" => array(),
81  "aarr" => array(),
82  "select" => array(),
83  );
84  $aVarConstraints = array();
85  $aGrouping = array();
86 
87  $aDbVariables = $this->loadConfVars($oConfig->getShopId(), $this->_getModuleForConfigVars());
88 
89  if ( is_array($aModuleSettings) ) {
90 
91  foreach ( $aModuleSettings as $aValue ) {
92  $sName = $aValue["name"];
93  $sType = $aValue["type"];
94  $sValue = null;
95  if (is_null($oConfig->getConfigParam($sName)) ) {
96  switch ($aValue["type"]) {
97  case "arr":
98  $sValue = $this->_arrayToMultiline( $aValue["value"] );
99  break;
100  case "aarr":
101  $sValue = $this->_aarrayToMultiline( $aValue["value"] );
102  break;
103  case "bool":
104  $sValue = filter_var($aValue["value"], FILTER_VALIDATE_BOOLEAN);
105  break;
106  default:
107  $sValue = $aValue["value"];
108  break;
109  }
110  $sValue = getStr()->htmlentities( $sValue );
111  } else {
112  $sValue = $aDbVariables['vars'][$sType][$sName];
113  }
114 
115  $sGroup = $aValue["group"];
116 
117  $sConstraints = "";
118  if ( $aValue["constraints"] ) {
119  $sConstraints = $aValue["constraints"];
120  } elseif ( $aValue["constrains"] ) {
121  $sConstraints = $aValue["constrains"];
122  }
123 
124  $aConfVars[$sType][$sName] = $sValue;
125  $aVarConstraints[$sName] = $this->_parseConstraint( $sType, $sConstraints );
126  if ($sGroup) {
127  if (!isset($aGrouping[$sGroup])) {
128  $aGrouping[$sGroup] = array($sName=>$sType);
129  } else {
130  $aGrouping[$sGroup][$sName] = $sType;
131  }
132  }
133  }
134  }
135 
136  return array(
137  'vars' => $aConfVars,
138  'constraints' => $aVarConstraints,
139  'grouping' => $aGrouping,
140  );
141  }
142 
143 
149  public function saveConfVars()
150  {
151  $myConfig = $this->getConfig();
152 
153 
154  $sModuleId = $this->_sModuleId = $this->getEditObjectId();
155  $sShopId = $myConfig->getShopId();
156 
157  $sModuleId = $this->_getModuleForConfigVars();
158 
159  foreach ($this->_aConfParams as $sType => $sParam) {
160  $aConfVars = oxConfig::getParameter($sParam);
161  if (is_array($aConfVars)) {
162  foreach ( $aConfVars as $sName => $sValue ) {
163  $myConfig->saveShopConfVar(
164  $sType,
165  $sName,
166  $this->_serializeConfVar($sType, $sName, $sValue),
167  $sShopId,
168  $sModuleId
169  );
170  }
171  }
172  }
173  }
174 
175 }