OXID eShop CE  4.9.5
 All Classes Files Functions Variables Pages
module_config.php
Go to the documentation of this file.
1 <?php
2 
10 {
11 
12  protected $_sModule = 'shop_config.tpl';
13 
17  public function __construct()
18  {
20  $this->_aConfParams['password'] = 'confpassword';
21  }
22 
29  public function render()
30  {
31  $myConfig = $this->getConfig();
32 
33  $sModuleId = $this->_sModuleId = $this->getEditObjectId();
34  $sShopId = $myConfig->getShopId();
35 
36  $oModule = oxNew('oxModule');
37 
38  if ($sModuleId && $oModule->load($sModuleId)) {
39  try {
40  $aDbVariables = $this->_loadMetadataConfVars($oModule->getInfo("settings"));
41 
42  $this->_aViewData["var_constraints"] = $aDbVariables['constraints'];
43  $this->_aViewData["var_grouping"] = $aDbVariables['grouping'];
44  $iCount = 0;
45  foreach ($this->_aConfParams as $sType => $sParam) {
46  $this->_aViewData[$sParam] = $aDbVariables['vars'][$sType];
47  $iCount += count($aDbVariables['vars'][$sType]);
48  }
49  } catch (oxException $oEx) {
50  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx);
51  $oEx->debugOut();
52  }
53  } else {
54  oxRegistry::get("oxUtilsView")->addErrorToDisplay(new oxException('EXCEPTION_MODULE_NOT_LOADED'));
55  }
56 
57  $this->_aViewData["oModule"] = $oModule;
58 
59  return 'module_config.tpl';
60  }
61 
67  protected function _getModuleForConfigVars()
68  {
69  return oxConfig::OXMODULE_MODULE_PREFIX . $this->_sModuleId;
70  }
71 
83  public function _loadMetadataConfVars($aModuleSettings)
84  {
85  $oConfig = $this->getConfig();
86 
87  $aConfVars = array(
88  "bool" => array(),
89  "str" => array(),
90  "arr" => array(),
91  "aarr" => array(),
92  "select" => array(),
93  "password" => array(),
94  );
95  $aVarConstraints = array();
96  $aGrouping = array();
97 
98  $aDbVariables = $this->loadConfVars($oConfig->getShopId(), $this->_getModuleForConfigVars());
99 
100  if (is_array($aModuleSettings)) {
101 
102  foreach ($aModuleSettings as $aValue) {
103  $sName = $aValue["name"];
104  $sType = $aValue["type"];
105  $sValue = null;
106  if (is_null($oConfig->getConfigParam($sName))) {
107  switch ($aValue["type"]) {
108  case "arr":
109  $sValue = $this->_arrayToMultiline($aValue["value"]);
110  break;
111  case "aarr":
112  $sValue = $this->_aarrayToMultiline($aValue["value"]);
113  break;
114  case "bool":
115  $sValue = filter_var($aValue["value"], FILTER_VALIDATE_BOOLEAN);
116  break;
117  default:
118  $sValue = $aValue["value"];
119  break;
120  }
121  $sValue = getStr()->htmlentities($sValue);
122  } else {
123  $sDbType = $this->_getDbConfigTypeName($sType);
124  $sValue = $aDbVariables['vars'][$sDbType][$sName];
125  }
126 
127  $sGroup = $aValue["group"];
128 
129  $sConstraints = "";
130  if ($aValue["constraints"]) {
131  $sConstraints = $aValue["constraints"];
132  } elseif ($aValue["constrains"]) {
133  $sConstraints = $aValue["constrains"];
134  }
135 
136  $aConfVars[$sType][$sName] = $sValue;
137  $aVarConstraints[$sName] = $this->_parseConstraint($sType, $sConstraints);
138  if ($sGroup) {
139  if (!isset($aGrouping[$sGroup])) {
140  $aGrouping[$sGroup] = array($sName => $sType);
141  } else {
142  $aGrouping[$sGroup][$sName] = $sType;
143  }
144  }
145  }
146  }
147 
148  return array(
149  'vars' => $aConfVars,
150  'constraints' => $aVarConstraints,
151  'grouping' => $aGrouping,
152  );
153  }
154 
155 
159  public function saveConfVars()
160  {
161  $oConfig = $this->getConfig();
162 
163  $this->resetContentCache();
164 
165  $sModuleId = $this->_sModuleId = $this->getEditObjectId();
166  $sShopId = $oConfig->getShopId();
167 
168  $sModuleId = $this->_getModuleForConfigVars();
169 
170  foreach ($this->_aConfParams as $sType => $sParam) {
171  $aConfVars = $oConfig->getRequestParameter($sParam);
172  if (is_array($aConfVars)) {
173  foreach ($aConfVars as $sName => $sValue) {
174  $sDbType = $this->_getDbConfigTypeName($sType);
175  $oConfig->saveShopConfVar(
176  $sDbType,
177  $sName,
178  $this->_serializeConfVar($sDbType, $sName, $sValue),
179  $sShopId,
180  $sModuleId
181  );
182  }
183  }
184  }
185  }
186 
194  private function _getDbConfigTypeName($sType)
195  {
196  $sDbType = $sType;
197  if ($sType === 'password') {
198  $sDbType = 'str';
199  }
200 
201  return $sDbType;
202  }
203 
204 }