Commit dfb9cd0d12c91e311c4799bfae4c11c0d04a54bc
Exists in
master
and in
44 other branches
Merge master into develop
Showing
8 changed files
with
918 additions
and
790 deletions
Show diff stats
src/InputOutput/IHMImpl/Params/DownloadImpl/IHMInputOutputParamsDownloadClass.php
@@ -15,7 +15,7 @@ class IHMInputOutputParamsDownloadClass extends IHMInputOutputParamsAbstractClas | @@ -15,7 +15,7 @@ class IHMInputOutputParamsDownloadClass extends IHMInputOutputParamsAbstractClas | ||
15 | */ | 15 | */ |
16 | protected function unmarshallRequest($input) | 16 | protected function unmarshallRequest($input) |
17 | { | 17 | { |
18 | - //{"nodeType":"download","type":"Download","downloadSrc":"0","structure":"2","sampling":600,"separateInfoFile":false,"output":"", | 18 | + //{"nodeType":"download","type":"Download","downloadSrc":"0","filestructure":"2","sampling":600,"separateInfoFile":false,"output":"", |
19 | // "header":"0","timesrc":"TimeTable","timeTables":[{"timeTableName":"rzerzer","id":"tt_1"},{"timeTableName":"sqsdq","id":"tt_0"}], | 19 | // "header":"0","timesrc":"TimeTable","timeTables":[{"timeTableName":"rzerzer","id":"tt_1"},{"timeTableName":"sqsdq","id":"tt_0"}], |
20 | //"list":["dst"],"milli":false,"fileformat":"ASCII","timeformat":"YYYY-MM-DDThh:mm:ss","compression":"tar+gzip","leaf":true} | 20 | //"list":["dst"],"milli":false,"fileformat":"ASCII","timeformat":"YYYY-MM-DDThh:mm:ss","compression":"tar+gzip","leaf":true} |
21 | 21 | ||
@@ -106,7 +106,7 @@ class IHMInputOutputParamsDownloadClass extends IHMInputOutputParamsAbstractClas | @@ -106,7 +106,7 @@ class IHMInputOutputParamsDownloadClass extends IHMInputOutputParamsAbstractClas | ||
106 | } | 106 | } |
107 | 107 | ||
108 | //filestructureData : [['0','All In One File'], ['1','One File Per Time Interval'], ['2','One File Per Param/Interval']], | 108 | //filestructureData : [['0','All In One File'], ['1','One File Per Time Interval'], ['2','One File Per Param/Interval']], |
109 | - switch ($input->structure) | 109 | + switch ($input->filestructure) |
110 | { | 110 | { |
111 | case "0" : | 111 | case "0" : |
112 | if (!$input->refparamSampling) | 112 | if (!$input->refparamSampling) |
src/InputOutput/IHMImpl/Params/IHMInputOutputParamsAbstractClass.php
@@ -257,7 +257,11 @@ abstract class IHMInputOutputParamsAbstractClass implements InputOutputInterface | @@ -257,7 +257,11 @@ abstract class IHMInputOutputParamsAbstractClass implements InputOutputInterface | ||
257 | $xp = new DOMXpath($xml); | 257 | $xp = new DOMXpath($xml); |
258 | 258 | ||
259 | foreach ($this->paramsData->getParamsToCopy() as $key => $value) { | 259 | foreach ($this->paramsData->getParamsToCopy() as $key => $value) { |
260 | - $paramNodes = $xp->query("//parameter[@xml:id='".$key."']"); | 260 | + $paramId = $key; |
261 | + if ($info = $this->paramManager->getTemplateParamsManager()->parseTemplatedParam($key)) { | ||
262 | + $paramId = $info['paramid']; | ||
263 | + } | ||
264 | + $paramNodes = $xp->query("//parameter[@xml:id='".$paramId."']"); | ||
261 | if ($paramNodes->length == 0) { | 265 | if ($paramNodes->length == 0) { |
262 | continue; | 266 | continue; |
263 | } | 267 | } |
src/InputOutput/IHMImpl/Tools/IHMParamManagerClass.php
@@ -5,507 +5,534 @@ | @@ -5,507 +5,534 @@ | ||
5 | * @brief Parameter manager | 5 | * @brief Parameter manager |
6 | * @details | 6 | * @details |
7 | */ | 7 | */ |
8 | -class IHMParamManagerClass { | ||
9 | - | ||
10 | - protected $userParameterMgr = null; | ||
11 | - protected $templateParamsManager = null; | ||
12 | - protected $paramImpexMgr = null; | ||
13 | - protected $ttCatMgr = null; | ||
14 | - protected $cacheExpressionParser = null; | ||
15 | - | ||
16 | - /* | ||
17 | - * @brief Constructor | ||
18 | - */ | ||
19 | - | ||
20 | - function __construct() { | ||
21 | - $this->templateParamsManager = new IHMParamTemplateClass(); | ||
22 | - $this->cacheExpressionParser = array(); | ||
23 | - } | ||
24 | - | ||
25 | - public function addGeneratedParam($paramId, $expression, $sampling_mode, $sampling_step, $ref_param, $paramsData) { | ||
26 | - $expressionInfo = $this->parseExpression($expression, $paramsData->getWorkingPath()); | ||
27 | - if (!$expressionInfo['success']) { | ||
28 | - throw new Exception($expressionInfo['message']); | ||
29 | - } | ||
30 | - | ||
31 | - //create a process param for the derived parameter | ||
32 | - $this->addProcessParam($paramId, $expressionInfo["expression"], $expression, $expressionInfo['params'], $sampling_mode, $sampling_step, $ref_param, 0, time(), "", "", $paramsData); | ||
33 | - } | ||
34 | - | ||
35 | - /* | ||
36 | - * @brief Add an existing parameter | ||
37 | - */ | ||
38 | - | ||
39 | - public function addExistingParam($param, $paramsData, $templateArgs = NULL, $tableLink = NULL) { | ||
40 | - if ($this->isDerivedParam($param)) | ||
41 | - return $this->addDerivedParam($param, $paramsData); | ||
42 | - else if ($this->isUploadedParam($param)) | ||
43 | - return $this->addUploadedParam($param, $paramsData); | ||
44 | - else if ($this->isImpexParam($param)) | ||
45 | - return $this->addImpexParam($param, $paramsData, $templateArgs); | ||
46 | - else | ||
47 | - return $this->addLocalParam($param, $paramsData, $templateArgs, $tableLink); | ||
48 | - return ""; | ||
49 | - } | ||
50 | - | ||
51 | - /* | ||
52 | - * @brief Add a process parameter | ||
53 | - */ | ||
54 | - | ||
55 | - public function addProcessParam($paramId, $expression, $expression_info, $params, $sampling_mode, $sampling_step, $ref_param, $gap, $dateModif, $units, $ytitle, $paramsData) { | ||
56 | - $paramsData->addProcessParamToCreate($paramId, $expression, $expression_info, $params, $sampling_mode, $sampling_step, $ref_param, $gap, $dateModif, $units, $ytitle); | ||
57 | - | ||
58 | - foreach ($params as $param) { | ||
59 | - $template_args = NULL; | ||
60 | - | ||
61 | - if (array_key_exists("template_args", $param)) | ||
62 | - $template_args = $param["template_args"]; | ||
63 | - | ||
64 | - $this->addExistingParam($param["paramid"], $paramsData, $template_args); | ||
65 | - } | ||
66 | - if (!empty($ref_param)) { | ||
67 | - $this->addExistingParam($ref_param, $paramsData, $template_args); | ||
68 | - } | ||
69 | - | ||
70 | - return true; | ||
71 | - } | ||
72 | - | ||
73 | - /* | ||
74 | - * @brief Add a TT or catalog parameter | ||
75 | - */ | ||
76 | - | ||
77 | - public function addTTCatParam($paramId, $paramsData) { | ||
78 | - if (!isset($this->ttCatMgr)) { | ||
79 | - $this->ttCatMgr = new IHMTTCatLoaderClass(); | ||
80 | - } | ||
81 | - $info = $this->ttCatMgr->getTTCatInfoFromId($paramId); | ||
82 | - | ||
83 | - if (!$info["success"]) { | ||
84 | - throw new Exception($info["message"]); | ||
85 | - } | ||
86 | - | ||
87 | - $status = array(); | ||
88 | - $units = ""; | ||
89 | - $ytitle = ""; | ||
90 | - $flag = ""; | ||
91 | - | ||
92 | - if ($info["info"]["isCatalog"]) { | ||
93 | - $parameters = $this->ttCatMgr->getCatalogParameters($paramId); | ||
94 | - if (!$parameters["success"] || empty($parameters["parameters"])) { | ||
95 | - throw new Exception("Error to extract first parameter of " . $paramId); | ||
96 | - } | ||
97 | - //For the moment, use the first parameter | ||
98 | - $parameter = $parameters["parameters"][0]; | ||
99 | - $units = $parameter["units"]; | ||
100 | - $ytitle = !empty($parameter["name"]) ? $parameter["name"] : $parameter["id"]; | ||
101 | - $flag = $parameter["id"]; | ||
102 | - $description = $parameter["description"]; | ||
103 | - $desc_parts = array(); | ||
104 | - foreach (explode("-", $description) as $def) { | ||
105 | - $def = trim($def); | ||
106 | - $p = strpos($def, ":"); | ||
107 | - if ($p === FALSE) { | ||
108 | - continue; | ||
109 | - } | ||
110 | - $val = substr($def, 0, $p); | ||
111 | - $val = trim($val); | ||
112 | - $name = substr($def, $p + 1); | ||
113 | - $name = trim($name); | ||
114 | - $color = ""; | ||
115 | - $p = strpos($name, "["); | ||
116 | - if ($p !== FALSE) { | ||
117 | - $color = substr($name, $p); | ||
118 | - $color = trim($color); | ||
119 | - $name = substr($name, 0, $p); | ||
120 | - $name = trim($name); | ||
121 | - } | ||
122 | - $status[] = array( | ||
123 | - "min" => floatval($val), | ||
124 | - "max" => floatval($val), | ||
125 | - "name" => $name, | ||
126 | - "color" => $color, | ||
127 | - ); | ||
128 | - } | ||
129 | - } else { | ||
130 | - $status = array( | ||
131 | - array( | ||
132 | - "min" => 1, | ||
133 | - "max" => 1, | ||
134 | - "name" => "Inside", | ||
135 | - "color" => "[255,0,0]", | ||
136 | - ) | ||
137 | - ); | ||
138 | - $ytitle = $info["info"]["name"]; | ||
139 | - } | ||
140 | - | ||
141 | - $paramsData->addTTCatParamToCreate($paramId, $info["info"]["path"], $info["info"]["isShared"], filemtime($info["info"]["path"]), $units, $ytitle, $status, $flag); | ||
142 | - return array("id" => $paramId, "indexes" => array(), "calib_infos" => array()); | ||
143 | - } | ||
144 | - | ||
145 | - /* | ||
146 | - * @brief Detect if it's a derived parameter | ||
147 | - */ | ||
148 | - | ||
149 | - private function isDerivedParam($param) { | ||
150 | - return preg_match("#^ws_#", $param); | ||
151 | - } | ||
152 | - | ||
153 | - /* | ||
154 | - * @brief Detect if it's a uploaded parameter | ||
155 | - */ | ||
156 | - | ||
157 | - public function isUploadedParam($param) { | ||
158 | - return preg_match("#^wsd_#", $param); | ||
159 | - } | ||
160 | - | ||
161 | - /* | ||
162 | - * @brief Detect if it's IMPEX parameter | ||
163 | - */ | ||
164 | - | ||
165 | - private function isImpexParam($param) { | ||
166 | - return preg_match("#^" . IHMImpexParamClass::$paramPrefix . "#", $param); | ||
167 | - } | ||
168 | - | ||
169 | - /* | ||
170 | - * @brief Add a local parameter | ||
171 | - */ | ||
172 | - | ||
173 | - private function addLocalParam($param, $paramsData, $templateArgs, $tableLink) { | ||
174 | - //local parameter | ||
175 | - $indexes = array(); | ||
176 | - $calib_infos = array(); | ||
177 | - //check for components | ||
178 | - $pattern = "/(?P<param>.*)\((?P<components>.*)\)/"; | ||
179 | - preg_match_all($pattern, $param, $matches); | ||
180 | - if ((count($matches["param"]) > 0) && (count($matches["components"]) > 0)) { | ||
181 | - $paramId = $matches["param"][0]; | ||
182 | - $indexes = explode(",", $matches["components"][0]); | ||
183 | - } else | ||
184 | - $paramId = $param; | ||
185 | - | ||
186 | - //check templated parameter | ||
187 | - $real_param_id = $paramId; | ||
188 | - $paramPath = ""; | ||
189 | - if ($this->templateParamsManager->isTemplatedParam($paramId)) { | ||
190 | - $paramPath = $this->templateParamsManager->generateTemplatedParamFile($paramId, $templateArgs, $tableLink); | ||
191 | - $real_param_id = $this->templateParamsManager->getTemplatedParamId($paramId, $templateArgs); | ||
192 | - if (empty($paramPath) || !file_exists($paramPath)) | ||
193 | - throw new Exception('Cannot generate parameter template file ' . $paramId); | ||
194 | - } | ||
195 | - else { | ||
196 | - $paramPath = IHMConfigClass::getLocalParamDBPath() . $paramId . ".xml"; | ||
197 | - if (!file_exists($paramPath)) | ||
198 | - throw new Exception('Cannot find parameter local file ' . $paramId); | ||
199 | - } | ||
200 | - | ||
201 | - $paramsData->addParamToCopy($real_param_id, $paramPath); | ||
202 | - | ||
203 | - $this->addLinkedLocalParams($paramId, $paramsData, $templateArgs); | ||
204 | - | ||
205 | - return array("id" => $real_param_id, "indexes" => $indexes, "calib_infos" => $calib_infos, "path" => $paramPath); | ||
206 | - } | ||
207 | - | ||
208 | - /* | ||
209 | - * @brief Add linked parameter | ||
210 | - */ | ||
211 | - | ||
212 | - private function addLinkedLocalParams($paramId, $paramsData, $templateArgs = NULL) { | ||
213 | - $doc = new DOMDocument("1.0", "UTF-8"); | ||
214 | - $doc->preserveWhiteSpace = false; | ||
215 | - $doc->formatOutput = true; | ||
216 | - | ||
217 | - $real_param_id = $paramId; | ||
218 | - if ($this->templateParamsManager->isTemplatedParam($paramId)) { | ||
219 | - $paramPath = $this->templateParamsManager->getTemplatePath($paramId); | ||
220 | - if (empty($paramPath) || !@$doc->load($paramPath)) | ||
221 | - throw new Exception('Cannot find parameter template file ' . $paramId); | ||
222 | - } | ||
223 | - else { | ||
224 | - $paramPath = IHMConfigClass::getLocalParamDBPath() . $paramId . ".xml"; | ||
225 | - if (empty($paramPath) || !@$doc->load($paramPath)) | ||
226 | - throw new Exception('Cannot find parameter local file ' . $paramId); | ||
227 | - } | ||
228 | - | ||
229 | - //<get> | ||
230 | - $getNodes = $doc->getElementsByTagName('get'); | ||
231 | - | ||
232 | - if ($getNodes->length <= 0) | ||
233 | - throw new Exception('Parameter local file ' . $paramId . ' dont have a getter node'); | ||
234 | - | ||
235 | - $getNode = $getNodes->item(0); | ||
236 | - | ||
237 | - //<amdaParam name="imf"/> | ||
238 | - $amdaParamNodes = $doc->getElementsByTagName('amdaParam'); | ||
239 | - | ||
240 | - foreach ($amdaParamNodes as $amdaParamNode) { | ||
241 | - $linkedParamId = $amdaParamNode->getAttribute('name'); | ||
242 | - if (empty($linkedParamId)) | ||
243 | - continue; | ||
244 | - $template_id = $this->templateParamsManager->getTemplateId($linkedParamId); | ||
245 | - $tempArgs = isset($templateArgs) ? $templateArgs : array(); | ||
246 | - if ($template_id !== FALSE) { | ||
247 | - $linkedParamId = $template_id; | ||
248 | - } else { | ||
249 | - $linkedParamId = $this->templateParamsManager->replaceArgs($linkedParamId, $templateArgs); | ||
250 | - $parsedParam = $this->templateParamsManager->parseTemplatedParam($linkedParamId); | ||
251 | - if ($parsedParam !== FALSE) { | ||
252 | - $linkedParamId = $parsedParam['paramid']; | ||
253 | - foreach ($parsedParam['template_args'] as $key => $val) { | ||
254 | - $tempArgs[$key] = $val; | ||
255 | - } | ||
256 | - } | ||
257 | - } | ||
258 | - | ||
259 | - if ($this->templateParamsManager->isTemplatedParam($linkedParamId)) { | ||
260 | - $linkedParamPath = $this->templateParamsManager->generateTemplatedParamFile($linkedParamId, $tempArgs); | ||
261 | - $real_linked_param_id = $this->templateParamsManager->getTemplatedParamId($linkedParamId, $tempArgs); | ||
262 | - } else { | ||
263 | - $real_linked_param_id = $linkedParamId; | ||
264 | - $linkedParamPath = IHMConfigClass::getLocalParamDBPath() . $real_linked_param_id . ".xml"; | ||
265 | - } | ||
266 | - $paramsData->addParamToCopy($real_linked_param_id, $linkedParamPath); | ||
267 | - $this->addLinkedLocalParams($linkedParamId, $paramsData); | ||
268 | - } | ||
269 | - } | ||
270 | - | ||
271 | - /* | ||
272 | - * @brief Add derived parameter | ||
273 | - */ | ||
274 | - | ||
275 | - private function addDerivedParam($param, $paramsData) { | ||
276 | - $time = time(); | ||
277 | - if (!isset($this->userParameterMgr)) | ||
278 | - $this->userParameterMgr = new IHMUserParamManagerClass(); | ||
279 | - | ||
280 | - //get derived parameter info | ||
281 | - $res = $this->userParameterMgr->getDerivedParameterFromName($param); | ||
282 | - | ||
283 | - if (!$res["success"]) | ||
284 | - throw new Exception('Error to load derived parameter file : ' . $res["message"]); | ||
285 | - | ||
286 | - if (isset($res["param"]["info"]["parsedExpression"])) { | ||
287 | - //Re use existing parsed expression info | ||
288 | - $expressionInfo = $res["param"]["info"]["parsedExpression"]; | ||
289 | - } else { | ||
290 | - //parse expression | ||
291 | - $expressionInfo = $this->parseExpression($res["param"]["expression"], $paramsData->getWorkingPath()); | ||
292 | - | ||
293 | - if (!$expressionInfo['success']) { | ||
294 | - throw new Exception($expressionInfo['message']); | ||
295 | - } | ||
296 | - | ||
297 | - $paramsList = array(); | ||
298 | - foreach ($expressionInfo['params'] as $p) { | ||
299 | - $paramsList[] = $p["paramid"]; | ||
300 | - } | ||
301 | - $this->userParameterMgr->saveDerivedParameterParsedExpression($res["param"]["id"], $expressionInfo["expression"], md5($res["param"]["expression"]), $paramsList); | ||
302 | - } | ||
303 | - | ||
304 | - $paramId = $param; | ||
305 | - | ||
306 | - //create a process param for the derived parameter | ||
307 | - $this->addProcessParam($paramId, $expressionInfo["expression"], $res["param"]["expression"], $expressionInfo['params'], $res["param"]["info"]["sampling_mode"], $res["param"]["info"]["timestep"], $res["param"]["info"]["reference_param"], 0, $res["param"]["dateModif"], !empty($res["param"]["info"]["units"]) ? $res["param"]["info"]["units"] : "", !empty($res["param"]["info"]["yTitle"]) ? $res["param"]["info"]["yTitle"] : "", $paramsData); | ||
308 | - | ||
309 | - return array("id" => $paramId, "indexes" => array(), "calib_infos" => array()); | ||
310 | - } | ||
311 | - | ||
312 | - /* | ||
313 | - * @brief Add IMPEX parameter : create dynamically xml parameter descriptor in user WS | ||
314 | - */ | ||
315 | - | ||
316 | - private function addImpexParam($param, $paramsData, $templateArgs = NULL) { | ||
317 | - if (!isset($this->paramImpexMgr)) | ||
318 | - $this->paramImpexMgr = new ImpexParamManager(); | ||
319 | - | ||
320 | - $parameterID = $this->paramImpexMgr->getImpexFullParamId($param, $templateArgs); | ||
321 | - | ||
322 | - $requestNodes = $paramsData->getRequestNodes(); | ||
323 | - | ||
324 | - // it is PARAMSGEN | ||
325 | - if (!$requestNodes) { | ||
326 | - return array("id" => $parameterID); | ||
327 | - } | ||
328 | - | ||
329 | - $timesNode = $requestNodes[0]->getTimesNode(); | ||
330 | - $intervals = $timesNode->getIntervals(); | ||
331 | - $originFile = IHMConfigClass::getUserWSPath() . $parameterID . ".xml"; | ||
332 | - | ||
333 | - if (!file_exists($originFile)) { | ||
334 | - // create IMPEX parameter info and data | ||
335 | - $res = $this->paramImpexMgr->createImpexParameter($param, $intervals, $templateArgs); | ||
336 | - | ||
337 | - if (!$res["success"]) | ||
338 | - throw new Exception('Error to create IMPEX parameter : ' . $res["message"]); | ||
339 | - | ||
340 | - $newParamNode = $paramsData->addLocalParamToCreate($res["param"]["id"], $res["param"]["info"]["viId"], $res["param"]["info"]["realVar"], $res["param"]["info"]["minSampling"], $res["param"]["info"]["maxSampling"], $res["param"]["info"]["type"], $res["param"]["info"]["size"], NULL, $res["param"]["dateModif"], true); | ||
341 | - | ||
342 | - $newParamNode->getInfo()->setName($res["param"]["info"]['name']); | ||
343 | - $newParamNode->getInfo()->setShortName($res["param"]["info"]['name']); | ||
344 | - $newParamNode->getInfo()->setUnits($res["param"]["info"]['units']); | ||
345 | - | ||
346 | - $tableDef = $res["param"]["info"]["tableDef"]; | ||
347 | - if (isset($tableDef) && array_key_exists('tableDefType', $tableDef) && ($tableDef['tableDefType'] != 'NONE')) { | ||
348 | - switch ($tableDef['channelsDefType']) { | ||
349 | - case 'BOUND' : | ||
350 | - $boundTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::BOUNDS, $res["param"]["info"]["yTitle"]); | ||
351 | - $boundTable->setUnits($res["param"]["info"]["yUnits"]); | ||
352 | - switch ($tableDef['tableDefType']) { | ||
353 | - case 'SELECT' : | ||
354 | - $boundTable->setBoundsName($tableDef['data']['bound']); | ||
355 | - $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['bound']); | ||
356 | - break; | ||
357 | - default : | ||
358 | - throw new Exception("Unknown tableDefType " . $tableDef['tableDefType']); | ||
359 | - } | ||
360 | - break; | ||
361 | - case 'CENTER' : | ||
362 | - $centerTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTER, $res["param"]["info"]["yTitle"]); | ||
363 | - $centerTable->setUnits($res["param"]["info"]["yUnits"]); | ||
364 | - $centerTable->setSize($tableDef['data']['width']); | ||
365 | - switch ($tableDef['tableDefType']) { | ||
366 | - case 'SELECT' : | ||
367 | - $centerTable->setCenterName($tableDef['data']['center']); | ||
368 | - $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']); | ||
369 | - break; | ||
370 | - default : | ||
371 | - throw new Exception("Unknown tableDefType " . $tableDef['tableDefType']); | ||
372 | - } | ||
373 | - break; | ||
374 | - default : | ||
375 | - throw new Exception("Unknown tableDefType " . $tableDef['channelsDefType']); | ||
376 | - } | ||
377 | - } | ||
378 | - | ||
379 | - return array("id" => $res["param"]["id"], "plotType" => $res["param"]["info"]["plotType"]); | ||
380 | - } else { | ||
381 | - // add IMPEX parameter data | ||
382 | - $this->paramImpexMgr->addImpexData($param, $intervals, $templateArgs); | ||
383 | - $paramsData->addParamToCopy($parameterID, $originFile); | ||
384 | - | ||
385 | - return array("id" => $parameterID); | ||
386 | - } | ||
387 | - } | ||
388 | - | ||
389 | - /* | ||
390 | - * @brief Add uploaded parameter | ||
391 | - */ | ||
392 | - | ||
393 | - private function addUploadedParam($param, $paramsData) { | ||
394 | - if (!isset($this->userParameterMgr)) | ||
395 | - $this->userParameterMgr = new IHMUserParamManagerClass(); | ||
396 | - | ||
397 | - //get uploaded parameter info | ||
398 | - $res = $this->userParameterMgr->getUploadedParameterFromName($param); | ||
399 | - | ||
400 | - if (!$res["success"]) | ||
401 | - throw new Exception('Error to load uploaded parameter file : ' . $res["message"]); | ||
402 | - | ||
403 | - $paramId = $param; | ||
404 | - | ||
405 | - $newParamNode = $paramsData->addLocalParamToCreate($paramId, $res["param"]["info"]["viId"], $res["param"]["info"]["realVar"], $res["param"]["info"]["minSampling"], $res["param"]["info"]["maxSampling"], $res["param"]["info"]["type"], $res["param"]["info"]["size"], $res["param"]["info"]["fillValue"], $res["param"]["dateModif"]); | ||
406 | - | ||
407 | - if (!empty($res["param"]["info"]["yTitle"])) { | ||
408 | - $newParamNode->getInfo()->setName($res["param"]["info"]['yTitle']); | ||
409 | - $newParamNode->getInfo()->setShortName($res["param"]["info"]['yTitle']); | ||
410 | - } | ||
411 | - if (!empty($res["param"]["info"]['units'])) { | ||
412 | - $newParamNode->getInfo()->setUnits($res["param"]["info"]['units']); | ||
413 | - } | ||
414 | - | ||
415 | - | ||
416 | - $tableDef = $res["param"]["info"]["tableDef"]; | ||
417 | - if (isset($tableDef) && array_key_exists('tableDefType', $tableDef) && ($tableDef['tableDefType'] != 'NONE')) { | ||
418 | - $tableName = empty($tableDef['tableName']) ? 'Table' : $tableDef['tableName']; | ||
419 | - $tableUnits = empty($tableDef['tableUnits']) ? '' : $tableDef['tableUnits']; | ||
420 | - switch ($tableDef['channelsDefType']) { | ||
421 | - case 'MINMAX' : | ||
422 | - $minMaxTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::MINMAX, $tableName); | ||
423 | - $minMaxTable->setUnits($tableUnits); | ||
424 | - switch ($tableDef['tableDefType']) { | ||
425 | - case 'SELECT' : | ||
426 | - $minMaxTable->setMinName($tableDef['data']['min']); | ||
427 | - $minMaxTable->setMaxName($tableDef['data']['max']); | ||
428 | - $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['min']); | ||
429 | - $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['max']); | ||
430 | - break; | ||
431 | - case 'MANUAL' : | ||
432 | - $minMaxTable->setMinName('min'); | ||
433 | - $minMaxTable->setMaxName('max'); | ||
434 | - $clbMinNode = $newParamNode->addClbManual('min'); | ||
435 | - $clbMinValues = explode(',', $tableDef['data']['min']); | ||
436 | - foreach ($clbMinValues as $value) | ||
437 | - $clbMinNode->addClbValue($value); | ||
438 | - $clbMaxNode = $newParamNode->addClbManual('max'); | ||
439 | - $clbMaxValues = explode(',', $tableDef['data']['max']); | ||
440 | - foreach ($clbMaxValues as $value) | ||
441 | - $clbMaxNode->addClbValue($value); | ||
442 | - break; | ||
443 | - } | ||
444 | - break; | ||
445 | - case 'BOUND' : | ||
446 | - $boundTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::BOUNDS, $tableName); | ||
447 | - $boundTable->setUnits($tableUnits); | ||
448 | - switch ($tableDef['tableDefType']) { | ||
449 | - case 'SELECT' : | ||
450 | - $boundTable->setBoundsName($tableDef['data']['bound']); | ||
451 | - $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['bound']); | ||
452 | - break; | ||
453 | - case 'MANUAL' : | ||
454 | - $boundTable->setBoundsName('bound'); | ||
455 | - $clbBoundNode = $newParamNode->addClbManual('bound'); | ||
456 | - $clbBoundValues = explode(',', $tableDef['data']['bound']); | ||
457 | - foreach ($clbBoundValues as $value) | ||
458 | - $clbBoundNode->addClbValue($value); | ||
459 | - break; | ||
460 | - } | ||
461 | - break; | ||
462 | - case 'CENTER' : | ||
463 | - $centerTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTER, $tableName); | ||
464 | - $centerTable->setUnits($tableUnits); | ||
465 | - $centerTable->setSize($tableDef['data']['width']); | ||
466 | - switch ($tableDef['tableDefType']) { | ||
467 | - case 'SELECT' : | ||
468 | - $centerTable->setCenterName($tableDef['data']['center']); | ||
469 | - $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']); | ||
470 | - break; | ||
471 | - case 'MANUAL' : | ||
472 | - $centerTable->setCenterName('center'); | ||
473 | - $clbCenterNode = $newParamNode->addClbManual('center'); | ||
474 | - $clbCenterValues = explode(',', $tableDef['data']['center']); | ||
475 | - foreach ($clbCenterValues as $value) | ||
476 | - $clbCenterNode->addClbValue($value); | ||
477 | - break; | ||
478 | - } | ||
479 | - break; | ||
480 | - case 'CENTERWIDTH' : | ||
481 | - $centerWidthTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTERWIDTH, $tableName); | ||
482 | - $centerWidthTable->setUnits($tableUnits); | ||
483 | - switch ($tableDef['tableDefType']) { | ||
484 | - case 'SELECT' : | ||
485 | - $centerWidthTable->setCenterName($tableDef['data']['center']); | ||
486 | - $centerWidthTable->setWidthName($tableDef['data']['width']); | ||
487 | - $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']); | ||
488 | - $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['width']); | ||
489 | - break; | ||
490 | - case 'MANUAL' : | ||
491 | - $centerWidthTable->setCenterName('center'); | ||
492 | - $centerWidthTable->setWidthName('width'); | ||
493 | - $clbCenterNode = $newParamNode->addClbManual('center'); | ||
494 | - $clbWidthNode = $newParamNode->addClbManual('width'); | ||
495 | - $clbCenterValues = explode(',', $tableDef['data']['center']); | ||
496 | - foreach ($clbCenterValues as $value) | ||
497 | - $clbCenterNode->addClbValue($value); | ||
498 | - $clbWidthValues = explode(',', $tableDef['data']['width']); | ||
499 | - foreach ($clbWidthValues as $value) | ||
500 | - $clbWidthNode->addClbValue($value); | ||
501 | - break; | ||
502 | - } | ||
503 | - break; | ||
504 | - } | ||
505 | - } | ||
506 | - | ||
507 | - return array("id" => $paramId, "plotType" => $res["param"]["info"]["plotType"]); | ||
508 | - } | 8 | +class IHMParamManagerClass |
9 | +{ | ||
10 | + protected $userParameterMgr = null; | ||
11 | + protected $templateParamsManager = null; | ||
12 | + protected $paramImpexMgr = null; | ||
13 | + protected $ttCatMgr = null; | ||
14 | + protected $cacheExpressionParser = null; | ||
15 | + | ||
16 | + /* | ||
17 | + * @brief Constructor | ||
18 | + */ | ||
19 | + function __construct() | ||
20 | + { | ||
21 | + $this->templateParamsManager = new IHMParamTemplateClass(); | ||
22 | + $this->cacheExpressionParser = array(); | ||
23 | + } | ||
24 | + | ||
25 | + public function addGeneratedParam($paramId, $expression, $sampling_mode, $sampling_step, $ref_param, $paramsData) | ||
26 | + { | ||
27 | + $expressionInfo = $this->parseExpression($expression, $paramsData->getWorkingPath()); | ||
28 | + if (!$expressionInfo['success']) { | ||
29 | + throw new Exception($expressionInfo['message']); | ||
30 | + } | ||
31 | + | ||
32 | + //create a process param for the derived parameter | ||
33 | + $this->addProcessParam($paramId, $expressionInfo["expression"], $expression, | ||
34 | + $expressionInfo['params'], $sampling_mode, $sampling_step, $ref_param, | ||
35 | + 0, time(), "", "", $paramsData); | ||
36 | + } | ||
37 | + | ||
38 | + /* | ||
39 | + * @brief Add an existing parameter | ||
40 | + */ | ||
41 | + public function addExistingParam($param, $paramsData, $templateArgs = NULL, $tableLink = NULL) | ||
42 | + { | ||
43 | + if ($this->isDerivedParam($param)) | ||
44 | + return $this->addDerivedParam($param,$paramsData); | ||
45 | + else if ($this->isUploadedParam($param)) | ||
46 | + return $this->addUploadedParam($param,$paramsData); | ||
47 | + else if ($this->isImpexParam($param)) | ||
48 | + return $this->addImpexParam($param,$paramsData,$templateArgs); | ||
49 | + else | ||
50 | + return $this->addLocalParam($param,$paramsData,$templateArgs, $tableLink); | ||
51 | + return ""; | ||
52 | + } | ||
53 | + | ||
54 | + /* | ||
55 | + * @brief Add a process parameter | ||
56 | + */ | ||
57 | + public function addProcessParam($paramId,$expression,$expression_info,$params, $sampling_mode, $sampling_step, $ref_param, $gap,$dateModif,$units,$ytitle,$paramsData) | ||
58 | + { | ||
59 | + $paramsData->addProcessParamToCreate($paramId, $expression, $expression_info, $params, $sampling_mode, $sampling_step, $ref_param, $gap,$dateModif, $units, $ytitle); | ||
60 | + | ||
61 | + foreach ($params as $param) { | ||
62 | + $template_args = NULL; | ||
63 | + | ||
64 | + if (array_key_exists("template_args", $param)) | ||
65 | + $template_args = $param["template_args"]; | ||
66 | + | ||
67 | + $this->addExistingParam($param["paramid"],$paramsData,$template_args); | ||
68 | + } | ||
69 | + if (!empty($ref_param)) { | ||
70 | + $this->addExistingParam($ref_param, $paramsData,$template_args); | ||
71 | + } | ||
72 | + | ||
73 | + return true; | ||
74 | + } | ||
75 | + | ||
76 | + /* | ||
77 | + * @brief Add a TT or catalog parameter | ||
78 | + */ | ||
79 | + public function addTTCatParam($paramId, $paramsData) | ||
80 | + { | ||
81 | + if (!isset($this->ttCatMgr)) { | ||
82 | + $this->ttCatMgr = new IHMTTCatLoaderClass(); | ||
83 | + } | ||
84 | + $info = $this->ttCatMgr->getTTCatInfoFromId($paramId); | ||
85 | + | ||
86 | + if (!$info["success"]) { | ||
87 | + throw new Exception($info["message"]); | ||
88 | + } | ||
89 | + | ||
90 | + $status = array(); | ||
91 | + $units = ""; | ||
92 | + $ytitle = ""; | ||
93 | + $flag = ""; | ||
94 | + | ||
95 | + if ($info["info"]["isCatalog"]) { | ||
96 | + $parameters = $this->ttCatMgr->getCatalogParameters($paramId); | ||
97 | + if (!$parameters["success"] || empty($parameters["parameters"])) { | ||
98 | + throw new Exception("Error to extract first parameter of ".$paramId); | ||
99 | + } | ||
100 | + //For the moment, use the first parameter | ||
101 | + $parameter = $parameters["parameters"][0]; | ||
102 | + $units = $parameter["units"]; | ||
103 | + $ytitle = !empty($parameter["name"]) ? $parameter["name"] : $parameter["id"]; | ||
104 | + $flag = $parameter["id"]; | ||
105 | + $description = $parameter["description"]; | ||
106 | + $desc_parts = array(); | ||
107 | + foreach (explode("-",$description) as $def) { | ||
108 | + $def = trim($def); | ||
109 | + $p = strpos($def, ":"); | ||
110 | + if ($p === FALSE) { | ||
111 | + continue; | ||
112 | + } | ||
113 | + $val = substr($def, 0, $p); | ||
114 | + $val = trim($val); | ||
115 | + $name = substr($def, $p+1); | ||
116 | + $name = trim($name); | ||
117 | + $color = ""; | ||
118 | + $p = strpos($name, "["); | ||
119 | + if ($p !== FALSE) { | ||
120 | + $color = substr($name, $p); | ||
121 | + $color = trim($color); | ||
122 | + $name = substr($name, 0, $p); | ||
123 | + $name = trim($name); | ||
124 | + } | ||
125 | + $status[] = array( | ||
126 | + "min" => floatval($val), | ||
127 | + "max" => floatval($val), | ||
128 | + "name" => $name, | ||
129 | + "color" => $color, | ||
130 | + ); | ||
131 | + } | ||
132 | + } | ||
133 | + else { | ||
134 | + $status = array( | ||
135 | + array( | ||
136 | + "min" => 1, | ||
137 | + "max" => 1, | ||
138 | + "name" => "Inside", | ||
139 | + "color" => "[255,0,0]", | ||
140 | + ) | ||
141 | + ); | ||
142 | + $ytitle = $info["info"]["name"]; | ||
143 | + } | ||
144 | + | ||
145 | + $paramsData->addTTCatParamToCreate($paramId, $info["info"]["path"], $info["info"]["isShared"], filemtime($info["info"]["path"]), $units, $ytitle, $status, $flag); | ||
146 | + return array("id" => $paramId, "indexes" => array(), "calib_infos" => array()); | ||
147 | + } | ||
148 | + | ||
149 | + /* | ||
150 | + * @brief Detect if it's a derived parameter | ||
151 | + */ | ||
152 | + private function isDerivedParam($param) | ||
153 | + { | ||
154 | + return preg_match("#^ws_#",$param); | ||
155 | + } | ||
156 | + | ||
157 | + /* | ||
158 | + * @brief Detect if it's a uploaded parameter | ||
159 | + */ | ||
160 | + public function isUploadedParam($param) | ||
161 | + { | ||
162 | + return preg_match("#^wsd_#",$param); | ||
163 | + } | ||
164 | + | ||
165 | + /* | ||
166 | + * @brief Detect if it's IMPEX parameter | ||
167 | + */ | ||
168 | + private function isImpexParam($param) | ||
169 | + { | ||
170 | + return preg_match("#^".IHMImpexParamClass::$paramPrefix."#",$param); | ||
171 | + } | ||
172 | + | ||
173 | + /* | ||
174 | + * @brief Add a local parameter | ||
175 | + */ | ||
176 | + private function addLocalParam($param, $paramsData, $templateArgs, $tableLink) | ||
177 | + { | ||
178 | + //local parameter | ||
179 | + $indexes = array(); | ||
180 | + $calib_infos = array(); | ||
181 | + //check for components | ||
182 | + $pattern = "/(?P<param>.*)\((?P<components>.*)\)/"; | ||
183 | + preg_match_all($pattern, $param, $matches); | ||
184 | + if ((count($matches["param"]) > 0) && (count($matches["components"]) > 0)) | ||
185 | + { | ||
186 | + $paramId = $matches["param"][0]; | ||
187 | + $indexes = explode(",",$matches["components"][0]); | ||
188 | + } | ||
189 | + else | ||
190 | + $paramId = $param; | ||
191 | + | ||
192 | + //check templated parameter | ||
193 | + $real_param_id = $paramId; | ||
194 | + $paramPath = ""; | ||
195 | + if ($this->templateParamsManager->isTemplatedParam($paramId)) { | ||
196 | + $paramPath = $this->templateParamsManager->generateTemplatedParamFile($paramId, $templateArgs, $tableLink); | ||
197 | + $real_param_id = $this->templateParamsManager->getTemplatedParamId($paramId, $templateArgs); | ||
198 | + if (empty($paramPath) || !file_exists($paramPath)) | ||
199 | + throw new Exception('Cannot generate parameter template file '.$paramId); | ||
200 | + } | ||
201 | + else { | ||
202 | + $paramPath = IHMConfigClass::getLocalParamDBPath().$paramId.".xml"; | ||
203 | + if (!file_exists($paramPath)) | ||
204 | + throw new Exception('Cannot find parameter local file '.$paramId); | ||
205 | + } | ||
206 | + | ||
207 | + $paramsData->addParamToCopy($real_param_id,$paramPath); | ||
208 | + | ||
209 | + $this->addLinkedLocalParams($paramId, $paramsData, $templateArgs); | ||
210 | + | ||
211 | + return array("id" => $real_param_id, "indexes" => $indexes, "calib_infos" => $calib_infos, "path" => $paramPath); | ||
212 | + } | ||
213 | + | ||
214 | + /* | ||
215 | + * @brief Add linked parameter | ||
216 | + */ | ||
217 | + private function addLinkedLocalParams($paramId,$paramsData,$templateArgs = NULL) | ||
218 | + { | ||
219 | + $doc = new DOMDocument("1.0", "UTF-8"); | ||
220 | + $doc->preserveWhiteSpace = false; | ||
221 | + $doc->formatOutput = true; | ||
222 | + | ||
223 | + $real_param_id = $paramId; | ||
224 | + if ($this->templateParamsManager->isTemplatedParam($paramId)) { | ||
225 | + $paramPath = $this->templateParamsManager->getTemplatePath($paramId); | ||
226 | + if (empty($paramPath) || !@$doc->load($paramPath)) | ||
227 | + throw new Exception('Cannot find parameter template file '.$paramId); | ||
228 | + } | ||
229 | + else { | ||
230 | + $paramPath = IHMConfigClass::getLocalParamDBPath().$paramId.".xml"; | ||
231 | + if (empty($paramPath) || !@$doc->load($paramPath)) | ||
232 | + throw new Exception('Cannot find parameter local file '.$paramId); | ||
233 | + } | ||
234 | + | ||
235 | + //<get> | ||
236 | + $getNodes = $doc->getElementsByTagName('get'); | ||
237 | + | ||
238 | + if ($getNodes->length <= 0) | ||
239 | + throw new Exception('Parameter local file '.$paramId.' dont have a getter node'); | ||
240 | + | ||
241 | + $getNode = $getNodes->item(0); | ||
242 | + | ||
243 | + //<amdaParam name="imf"/> | ||
244 | + $amdaParamNodes = $doc->getElementsByTagName('amdaParam'); | ||
245 | + | ||
246 | + foreach($amdaParamNodes as $amdaParamNode) | ||
247 | + { | ||
248 | + $linkedParamId = $amdaParamNode->getAttribute('name'); | ||
249 | + if (empty($linkedParamId)) | ||
250 | + continue; | ||
251 | + $template_id = $this->templateParamsManager->getTemplateId($linkedParamId); | ||
252 | + $tempArgs = isset($templateArgs) ? $templateArgs : array(); | ||
253 | + if ($template_id !== FALSE) { | ||
254 | + $linkedParamId = $template_id; | ||
255 | + } | ||
256 | + else { | ||
257 | + $linkedParamId = $this->templateParamsManager->replaceArgs($linkedParamId, $templateArgs); | ||
258 | + $parsedParam = $this->templateParamsManager->parseTemplatedParam($linkedParamId); | ||
259 | + if ($parsedParam !== FALSE) { | ||
260 | + $linkedParamId = $parsedParam['paramid']; | ||
261 | + foreach ($parsedParam['template_args'] as $key => $val) { | ||
262 | + $tempArgs[$key] = $val; | ||
263 | + } | ||
264 | + } | ||
265 | + } | ||
266 | + | ||
267 | + if ($this->templateParamsManager->isTemplatedParam($linkedParamId)) { | ||
268 | + $linkedParamPath = $this->templateParamsManager->generateTemplatedParamFile($linkedParamId, $tempArgs); | ||
269 | + $real_linked_param_id = $this->templateParamsManager->getTemplatedParamId($linkedParamId, $tempArgs); | ||
270 | + } | ||
271 | + else { | ||
272 | + $real_linked_param_id = $linkedParamId; | ||
273 | + $linkedParamPath = IHMConfigClass::getLocalParamDBPath().$real_linked_param_id.".xml"; | ||
274 | + } | ||
275 | + $paramsData->addParamToCopy($real_linked_param_id,$linkedParamPath); | ||
276 | + $this->addLinkedLocalParams($linkedParamId, $paramsData); | ||
277 | + } | ||
278 | + } | ||
279 | + | ||
280 | + /* | ||
281 | + * @brief Add derived parameter | ||
282 | + */ | ||
283 | + private function addDerivedParam($param,$paramsData) | ||
284 | + { | ||
285 | + $time = time(); | ||
286 | + if (!isset($this->userParameterMgr)) | ||
287 | + $this->userParameterMgr = new IHMUserParamManagerClass(); | ||
288 | + | ||
289 | + //get derived parameter info | ||
290 | + $res = $this->userParameterMgr->getDerivedParameterFromName($param); | ||
291 | + | ||
292 | + if (!$res["success"]) | ||
293 | + throw new Exception('Error to load derived parameter file : '.$res["message"]); | ||
294 | + | ||
295 | + if (isset($res["param"]["info"]["parsedExpression"])) { | ||
296 | + //Re use existing parsed expression info | ||
297 | + $expressionInfo = $res["param"]["info"]["parsedExpression"]; | ||
298 | + } | ||
299 | + else { | ||
300 | + //parse expression | ||
301 | + $expressionInfo = $this->parseExpression($res["param"]["expression"], $paramsData->getWorkingPath()); | ||
302 | + | ||
303 | + if (!$expressionInfo['success']) { | ||
304 | + throw new Exception($expressionInfo['message']); | ||
305 | + } | ||
306 | + $this->userParameterMgr->saveDerivedParameterParsedExpression($res["param"]["id"], $expressionInfo["expression"], md5($res["param"]["expression"]), $expressionInfo['params']); | ||
307 | + } | ||
308 | + | ||
309 | + $paramId = $param; | ||
310 | + | ||
311 | + //create a process param for the derived parameter | ||
312 | + $this->addProcessParam($paramId, $expressionInfo["expression"], $res["param"]["expression"], | ||
313 | + $expressionInfo['params'], $res["param"]["info"]["sampling_mode"], $res["param"]["info"]["timestep"], $res["param"]["info"]["reference_param"], | ||
314 | + 0,$res["param"]["dateModif"],!empty($res["param"]["info"]["units"]) ? $res["param"]["info"]["units"] : "", | ||
315 | + !empty($res["param"]["info"]["yTitle"]) ? $res["param"]["info"]["yTitle"] : "", $paramsData); | ||
316 | + | ||
317 | + return array("id" => $paramId, "indexes" => array(), "calib_infos" => array()); | ||
318 | + } | ||
319 | + | ||
320 | + /* | ||
321 | + * @brief Add IMPEX parameter : create dynamically xml parameter descriptor in user WS | ||
322 | + */ | ||
323 | + private function addImpexParam($param,$paramsData,$templateArgs = NULL) | ||
324 | + { | ||
325 | + if (!isset($this->paramImpexMgr)) | ||
326 | + $this->paramImpexMgr = new ImpexParamManager(); | ||
327 | + | ||
328 | + $parameterID = $this->paramImpexMgr->getImpexFullParamId($param, $templateArgs); | ||
329 | + | ||
330 | + $requestNodes = $paramsData->getRequestNodes(); | ||
331 | + | ||
332 | + // it is PARAMSGEN | ||
333 | + if (!$requestNodes) { | ||
334 | + return array("id" => $parameterID); | ||
335 | + } | ||
336 | + | ||
337 | + $timesNode = $requestNodes[0]->getTimesNode(); | ||
338 | + $intervals = $timesNode->getIntervals(); | ||
339 | + $originFile = IHMConfigClass::getUserWSPath().$parameterID.".xml"; | ||
340 | + | ||
341 | + if (!file_exists($originFile)) { | ||
342 | + // create IMPEX parameter info and data | ||
343 | + $res = $this->paramImpexMgr->createImpexParameter($param, $intervals, $templateArgs); | ||
344 | + | ||
345 | + if (!$res["success"]) | ||
346 | + throw new Exception('Error to create IMPEX parameter : '.$res["message"]); | ||
347 | + | ||
348 | + $newParamNode = $paramsData->addLocalParamToCreate($res["param"]["id"], | ||
349 | + $res["param"]["info"]["viId"], $res["param"]["info"]["realVar"], | ||
350 | + $res["param"]["info"]["minSampling"], $res["param"]["info"]["maxSampling"], | ||
351 | + $res["param"]["info"]["type"],$res["param"]["info"]["size"], | ||
352 | + NULL,$res["param"]["dateModif"],true); | ||
353 | + | ||
354 | + $newParamNode->getInfo()->setName($res["param"]["info"]['name']); | ||
355 | + $newParamNode->getInfo()->setShortName($res["param"]["info"]['name']); | ||
356 | + $newParamNode->getInfo()->setUnits($res["param"]["info"]['units']); | ||
357 | + | ||
358 | + $tableDef = $res["param"]["info"]["tableDef"]; | ||
359 | + if (isset($tableDef) && array_key_exists('tableDefType', $tableDef) && ($tableDef['tableDefType'] != 'NONE')) | ||
360 | + { | ||
361 | + switch ($tableDef['channelsDefType']) | ||
362 | + { | ||
363 | + case 'BOUND' : | ||
364 | + $boundTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::BOUNDS, $res["param"]["info"]["yTitle"]); | ||
365 | + $boundTable->setUnits($res["param"]["info"]["yUnits"]); | ||
366 | + switch ($tableDef['tableDefType']) | ||
367 | + { | ||
368 | + case 'SELECT' : | ||
369 | + $boundTable->setBoundsName($tableDef['data']['bound']); | ||
370 | + $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['bound']); | ||
371 | + break; | ||
372 | + default : | ||
373 | + throw new Exception("Unknown tableDefType ".$tableDef['tableDefType']); | ||
374 | + } | ||
375 | + break; | ||
376 | + case 'CENTER' : | ||
377 | + $centerTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTER, $res["param"]["info"]["yTitle"]); | ||
378 | + $centerTable->setUnits($res["param"]["info"]["yUnits"]); | ||
379 | + $centerTable->setSize($tableDef['data']['width']); | ||
380 | + switch ($tableDef['tableDefType']) | ||
381 | + { | ||
382 | + case 'SELECT' : | ||
383 | + $centerTable->setCenterName($tableDef['data']['center']); | ||
384 | + $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']); | ||
385 | + break; | ||
386 | + default : | ||
387 | + throw new Exception("Unknown tableDefType ".$tableDef['tableDefType']); | ||
388 | + } | ||
389 | + break; | ||
390 | + default : | ||
391 | + throw new Exception("Unknown tableDefType ".$tableDef['channelsDefType']); | ||
392 | + } | ||
393 | + } | ||
394 | + | ||
395 | + return array("id" => $res["param"]["id"], "plotType" => $res["param"]["info"]["plotType"]); | ||
396 | + } | ||
397 | + else { | ||
398 | + // add IMPEX parameter data | ||
399 | + $this->paramImpexMgr->addImpexData($param, $intervals, $templateArgs); | ||
400 | + $paramsData->addParamToCopy($parameterID, $originFile); | ||
401 | + | ||
402 | + return array("id" => $parameterID); | ||
403 | + } | ||
404 | + } | ||
405 | + | ||
406 | + /* | ||
407 | + * @brief Add uploaded parameter | ||
408 | + */ | ||
409 | + private function addUploadedParam($param,$paramsData) | ||
410 | + { | ||
411 | + if (!isset($this->userParameterMgr)) | ||
412 | + $this->userParameterMgr = new IHMUserParamManagerClass(); | ||
413 | + | ||
414 | + //get uploaded parameter info | ||
415 | + $res = $this->userParameterMgr->getUploadedParameterFromName($param); | ||
416 | + | ||
417 | + if (!$res["success"]) | ||
418 | + throw new Exception('Error to load uploaded parameter file : '.$res["message"]); | ||
419 | + | ||
420 | + $paramId = $param; | ||
421 | + | ||
422 | + $newParamNode = $paramsData->addLocalParamToCreate($paramId, | ||
423 | + $res["param"]["info"]["viId"], $res["param"]["info"]["realVar"], | ||
424 | + $res["param"]["info"]["minSampling"], $res["param"]["info"]["maxSampling"], | ||
425 | + $res["param"]["info"]["type"],$res["param"]["info"]["size"], | ||
426 | + $res["param"]["info"]["fillValue"],$res["param"]["dateModif"]); | ||
427 | + | ||
428 | + if (!empty($res["param"]["info"]["yTitle"])) { | ||
429 | + $newParamNode->getInfo()->setName($res["param"]["info"]['yTitle']); | ||
430 | + $newParamNode->getInfo()->setShortName($res["param"]["info"]['yTitle']); | ||
431 | + } | ||
432 | + if (!empty($res["param"]["info"]['units'])) { | ||
433 | + $newParamNode->getInfo()->setUnits($res["param"]["info"]['units']); | ||
434 | + } | ||
435 | + | ||
436 | + | ||
437 | + $tableDef = $res["param"]["info"]["tableDef"]; | ||
438 | + if (isset($tableDef) && array_key_exists('tableDefType', $tableDef) && ($tableDef['tableDefType'] != 'NONE')) | ||
439 | + { | ||
440 | + $tableName = empty($tableDef['tableName']) ? 'Table' : $tableDef['tableName']; | ||
441 | + $tableUnits = empty($tableDef['tableUnits']) ? '' : $tableDef['tableUnits']; | ||
442 | + switch ($tableDef['channelsDefType']) | ||
443 | + { | ||
444 | + case 'MINMAX' : | ||
445 | + $minMaxTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::MINMAX, $tableName); | ||
446 | + $minMaxTable->setUnits($tableUnits); | ||
447 | + switch ($tableDef['tableDefType']) | ||
448 | + { | ||
449 | + case 'SELECT' : | ||
450 | + $minMaxTable->setMinName($tableDef['data']['min']); | ||
451 | + $minMaxTable->setMaxName($tableDef['data']['max']); | ||
452 | + $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['min']); | ||
453 | + $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['max']); | ||
454 | + break; | ||
455 | + case 'MANUAL' : | ||
456 | + $minMaxTable->setMinName('min'); | ||
457 | + $minMaxTable->setMaxName('max'); | ||
458 | + $clbMinNode = $newParamNode->addClbManual('min'); | ||
459 | + $clbMinValues = explode(',', $tableDef['data']['min']); | ||
460 | + foreach ($clbMinValues as $value) | ||
461 | + $clbMinNode->addClbValue($value); | ||
462 | + $clbMaxNode = $newParamNode->addClbManual('max'); | ||
463 | + $clbMaxValues = explode(',', $tableDef['data']['max']); | ||
464 | + foreach ($clbMaxValues as $value) | ||
465 | + $clbMaxNode->addClbValue($value); | ||
466 | + break; | ||
467 | + } | ||
468 | + break; | ||
469 | + case 'BOUND' : | ||
470 | + $boundTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::BOUNDS, $tableName); | ||
471 | + $boundTable->setUnits($tableUnits); | ||
472 | + switch ($tableDef['tableDefType']) | ||
473 | + { | ||
474 | + case 'SELECT' : | ||
475 | + $boundTable->setBoundsName($tableDef['data']['bound']); | ||
476 | + $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['bound']); | ||
477 | + break; | ||
478 | + case 'MANUAL' : | ||
479 | + $boundTable->setBoundsName('bound'); | ||
480 | + $clbBoundNode = $newParamNode->addClbManual('bound'); | ||
481 | + $clbBoundValues = explode(',', $tableDef['data']['bound']); | ||
482 | + foreach ($clbBoundValues as $value) | ||
483 | + $clbBoundNode->addClbValue($value); | ||
484 | + break; | ||
485 | + } | ||
486 | + break; | ||
487 | + case 'CENTER' : | ||
488 | + $centerTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTER, $tableName); | ||
489 | + $centerTable->setUnits($tableUnits); | ||
490 | + $centerTable->setSize($tableDef['data']['width']); | ||
491 | + switch ($tableDef['tableDefType']) | ||
492 | + { | ||
493 | + case 'SELECT' : | ||
494 | + $centerTable->setCenterName($tableDef['data']['center']); | ||
495 | + $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']); | ||
496 | + break; | ||
497 | + case 'MANUAL' : | ||
498 | + $centerTable->setCenterName('center'); | ||
499 | + $clbCenterNode = $newParamNode->addClbManual('center'); | ||
500 | + $clbCenterValues = explode(',', $tableDef['data']['center']); | ||
501 | + foreach ($clbCenterValues as $value) | ||
502 | + $clbCenterNode->addClbValue($value); | ||
503 | + break; | ||
504 | + } | ||
505 | + break; | ||
506 | + case 'CENTERWIDTH' : | ||
507 | + $centerWidthTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTERWIDTH, $tableName); | ||
508 | + $centerWidthTable->setUnits($tableUnits); | ||
509 | + switch ($tableDef['tableDefType']) | ||
510 | + { | ||
511 | + case 'SELECT' : | ||
512 | + $centerWidthTable->setCenterName($tableDef['data']['center']); | ||
513 | + $centerWidthTable->setWidthName($tableDef['data']['width']); | ||
514 | + $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']); | ||
515 | + $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['width']); | ||
516 | + break; | ||
517 | + case 'MANUAL' : | ||
518 | + $centerWidthTable->setCenterName('center'); | ||
519 | + $centerWidthTable->setWidthName('width'); | ||
520 | + $clbCenterNode = $newParamNode->addClbManual('center'); | ||
521 | + $clbWidthNode = $newParamNode->addClbManual('width'); | ||
522 | + $clbCenterValues = explode(',', $tableDef['data']['center']); | ||
523 | + foreach ($clbCenterValues as $value) | ||
524 | + $clbCenterNode->addClbValue($value); | ||
525 | + $clbWidthValues = explode(',', $tableDef['data']['width']); | ||
526 | + foreach ($clbWidthValues as $value) | ||
527 | + $clbWidthNode->addClbValue($value); | ||
528 | + break; | ||
529 | + } | ||
530 | + break; | ||
531 | + } | ||
532 | + } | ||
533 | + | ||
534 | + return array("id" => $paramId, "plotType" => $res["param"]["info"]["plotType"]); | ||
535 | + } | ||
509 | 536 | ||
510 | public function applyFilter($paramsData, $paramData, &$paramInfo) { | 537 | public function applyFilter($paramsData, $paramData, &$paramInfo) { |
511 | $filter = (isset($paramData->{'param-drawing-object'}->{'filtering-activated'}) && ($paramData->{'param-drawing-object'}->{'filtering-activated'})) ? true : false; | 538 | $filter = (isset($paramData->{'param-drawing-object'}->{'filtering-activated'}) && ($paramData->{'param-drawing-object'}->{'filtering-activated'})) ? true : false; |
@@ -570,266 +597,271 @@ class IHMParamManagerClass { | @@ -570,266 +597,271 @@ class IHMParamManagerClass { | ||
570 | } | 597 | } |
571 | } | 598 | } |
572 | 599 | ||
573 | - public function applyRangesAndIndexes($paramsData, $paramData, $force_total_2d, &$paramInfo) { | ||
574 | - $dim1_min = 0; | ||
575 | - $dim1_max = 0; | ||
576 | - $dim2_min = 0; | ||
577 | - $dim2_max = 0; | ||
578 | - | ||
579 | - $dim1_is_range = (isset($paramData->{'dim1-sum-type'}) && ($paramData->{'dim1-sum-type'} > 0)); | ||
580 | - $dim1_index = ($dim1_is_range || !isset($paramData->{'dim1-index'}) || ($paramData->{'dim1-index'} == '')) ? '*' : $paramData->{'dim1-index'}; | ||
581 | - if ($dim1_is_range) { | ||
582 | - switch ($paramData->{'dim1-sum-type'}) { | ||
583 | - case 1: | ||
584 | - //Sum between a range of value | ||
585 | - $dim1_min = !empty($paramData->{'dim1-min-value'}) ? $paramData->{'dim1-min-value'} : 0; | ||
586 | - $dim1_max = !empty($paramData->{'dim1-max-value'}) ? $paramData->{'dim1-max-value'} : 0; | ||
587 | - break; | ||
588 | - case 2: | ||
589 | - //Sum between indexes | ||
590 | - $dim1_min = !empty($paramData->{'dim1-min-index'}) ? $paramData->{'dim1-min-index'} : 0; | ||
591 | - $dim1_max = !empty($paramData->{'dim1-max-index'}) ? $paramData->{'dim1-max-index'} : 0; | ||
592 | - break; | ||
593 | - } | ||
594 | - } | ||
595 | - | ||
596 | - $dim2_is_range = (isset($paramData->{'dim2-sum-type'}) && ($paramData->{'dim2-sum-type'} > 0)); | ||
597 | - $dim2_index = ($dim2_is_range || !isset($paramData->{'dim2-index'}) || ($paramData->{'dim2-index'} == '')) ? '*' : $paramData->{'dim2-index'}; | ||
598 | - if ($dim2_is_range) { | ||
599 | - switch ($paramData->{'dim2-sum-type'}) { | ||
600 | - case 1: | ||
601 | - //Sum between a range of value | ||
602 | - $dim2_min = !empty($paramData->{'dim2-min-value'}) ? $paramData->{'dim2-min-value'} : 0; | ||
603 | - $dim2_max = !empty($paramData->{'dim2-max-value'}) ? $paramData->{'dim2-max-value'} : 0; | ||
604 | - break; | ||
605 | - case 2: | ||
606 | - //Sum between indexes | ||
607 | - $dim2_min = !empty($paramData->{'dim2-min-index'}) ? $paramData->{'dim2-min-index'} : 0; | ||
608 | - $dim2_max = !empty($paramData->{'dim2-max-index'}) ? $paramData->{'dim2-max-index'} : 0; | ||
609 | - break; | ||
610 | - } | ||
611 | - } | ||
612 | - | ||
613 | - switch ($paramData->{'type'}) { | ||
614 | - case 0: | ||
615 | - //scalar - nothing to do | ||
616 | - break; | ||
617 | - case 1: | ||
618 | - //Tab1D | ||
619 | - if ($dim1_is_range) { | ||
620 | - $template_args = array( | ||
621 | - 'paramid' => $paramInfo['id'], | ||
622 | - 'min' => $dim1_min, | ||
623 | - 'max' => $dim1_max, | ||
624 | - 'relateddim' => 0, | ||
625 | - ); | ||
626 | - if ($paramData->{'dim1-sum-type'} == 2) | ||
627 | - $paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args); | ||
628 | - else | ||
629 | - $paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args); | ||
630 | - } | ||
631 | - else if ($dim2_is_range) { | ||
632 | - $template_args = array( | ||
633 | - 'paramid' => $paramInfo['id'], | ||
634 | - 'min' => $dim2_min, | ||
635 | - 'max' => $dim2_max, | ||
636 | - 'relateddim' => 1, | ||
637 | - ); | ||
638 | - if ($paramData->{'dim2-sum-type'} == 2) | ||
639 | - $paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args); | ||
640 | - else | ||
641 | - $paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args); | ||
642 | - } | ||
643 | - else if ($dim1_index != '*') { | ||
644 | - $paramInfo['indexes'][] = $dim1_index; | ||
645 | - } else if ($dim2_index != '*') { | ||
646 | - $paramInfo['indexes'][] = $dim2_index; | ||
647 | - } | ||
648 | - break; | ||
649 | - case 2: | ||
650 | - //Tab2D | ||
651 | - if ($dim1_is_range && $dim2_is_range) { | ||
652 | - if ($paramData->{'dim1-sum-type'} != $paramData->{'dim2-sum-type'}) { | ||
653 | - throw new Exception("Not supported - Dimensions ranges for " . $paramInfo['id'] . " must have the same type for each dimensions"); | ||
654 | - } | ||
655 | - $template_args = array( | ||
656 | - 'paramid' => $paramInfo['id'], | ||
657 | - 'min1' => $dim1_min, | ||
658 | - 'max1' => $dim1_max, | ||
659 | - 'relateddim1' => 0, | ||
660 | - 'min2' => $dim2_min, | ||
661 | - 'max2' => $dim2_max, | ||
662 | - ); | ||
663 | - if ($paramData->{'dim1-sum-type'} == 2) | ||
664 | - $paramInfo = $this->addExistingParam('sum_into_table_indexes_2d', $paramsData, $template_args); | ||
665 | - else | ||
666 | - $paramInfo = $this->addExistingParam('sum_into_table_range_2d', $paramsData, $template_args); | ||
667 | - } | ||
668 | - else if ($dim1_is_range) { | ||
669 | - $template_args = array( | ||
670 | - 'paramid' => $paramInfo['id'], | ||
671 | - 'min' => $dim1_min, | ||
672 | - 'max' => $dim1_max, | ||
673 | - 'relateddim' => 0, | ||
674 | - ); | ||
675 | - $tableLink = array( | ||
676 | - 'paramid' => $paramInfo['id'], | ||
677 | - 'relateddim' => 1, | ||
678 | - ); | ||
679 | - if ($paramData->{'dim1-sum-type'} == 2) | ||
680 | - $paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args, $tableLink); | ||
681 | - else | ||
682 | - $paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args, $tableLink); | ||
683 | - if ($dim2_index != '*') { | ||
684 | - $paramInfo['indexes'][] = $dim2_index; | ||
685 | - } | ||
686 | - } else if ($dim2_is_range) { | ||
687 | - $template_args = array( | ||
688 | - 'paramid' => $paramInfo['id'], | ||
689 | - 'min' => $dim2_min, | ||
690 | - 'max' => $dim2_max, | ||
691 | - 'relateddim' => 1, | ||
692 | - ); | ||
693 | - $tableLink = array( | ||
694 | - 'paramid' => $paramInfo['id'], | ||
695 | - 'relateddim' => 0, | ||
696 | - ); | ||
697 | - if ($paramData->{'dim2-sum-type'} == 2) | ||
698 | - $paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args, $tableLink); | ||
699 | - else | ||
700 | - $paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args, $tableLink); | ||
701 | - if ($dim1_index != '*') { | ||
702 | - $paramInfo['indexes'][] = $dim1_index; | ||
703 | - } | ||
704 | - } else if (($dim1_index != '*') && ($dim2_index != '*')) { | ||
705 | - $paramInfo['indexes'][] = "[" . $dim1_index . "," . $dim2_index . "]"; | ||
706 | - } else if ($dim1_index != '*') { | ||
707 | - $paramInfo['indexes'][] = "[" . $dim1_index . ",*]"; | ||
708 | - } else if ($dim2_index != '*') { | ||
709 | - $paramInfo['indexes'][] = "[*," . $dim2_index . "]"; | ||
710 | - } else if ($force_total_2d) { | ||
711 | - //total over 2 dims | ||
712 | - $template_args = array( | ||
713 | - 'paramid' => $paramInfo['id'], | ||
714 | - ); | ||
715 | - $paramInfo = $this->addExistingParam('total_2D', $paramsData, $template_args); | ||
716 | - } | ||
717 | - break; | ||
718 | - } | ||
719 | - } | ||
720 | - | ||
721 | - public function parseExpression($expression, $workingDir) { | ||
722 | - $outputFileName = "parser_" . md5($expression) . ".xml"; | ||
723 | - if (array_key_exists($outputFileName, $this->cacheExpressionParser)) { | ||
724 | - return $this->cacheExpressionParser[$outputFileName]; | ||
725 | - } | ||
726 | - $parserData = new ParserRequestDataClass(); | ||
727 | - $parserData->setManagerFilePath(IHMConfigClass::getProcessManagerFilePath()); | ||
728 | - $parserData->addExpression($expression); | ||
729 | - $parserData->setWorkingPath($workingDir); | ||
730 | - $parserData->setLocalParamsPath(IHMConfigClass::getLocalParamDBPath()); | ||
731 | - $parserData->setConstantsFilePath(IHMConfigClass::getConstantsFilePath()); | ||
732 | - $parserData->setFunctionsFilePath(IHMConfigClass::getFunctionsFilePath()); | ||
733 | - $parserData->setParamTemplatesFilePath(IHMConfigClass::getParamTemplateListFilePath()); | ||
734 | - $parserData->setFunctionsArgsListFilePath(IHMConfigClass::getFunctionsArgsListFilePath()); | ||
735 | - $parserData->setOutputFileName($outputFileName); | ||
736 | - $resultFilePath = $workingDir . "/" . $outputFileName; | ||
737 | - | ||
738 | - $parserRequest = new ParserRequestClass(); | ||
739 | - $parserRequest->setData($parserData); | ||
740 | - | ||
741 | - if (!$parserRequest->init() || !$parserRequest->run()) { | ||
742 | - if (file_exists($resultFilePath)) { | ||
743 | - unlink($resultFilePath); | ||
744 | - } | ||
745 | - return array('success' => FALSE, 'message' => 'Error to init or run expression parser'); | ||
746 | - } | ||
747 | - | ||
748 | - //Load result file | ||
749 | - $doc = new DOMDocument(); | ||
750 | - $doc->load($resultFilePath); | ||
751 | - if (!$doc->load($resultFilePath)) { | ||
752 | - if (file_exists($resultFilePath)) { | ||
753 | - unlink($resultFilePath); | ||
754 | - } | ||
755 | - return array('success' => FALSE, 'message' => 'Error to load parser result file'); | ||
756 | - } | ||
757 | - | ||
758 | - $expressionNodes = $doc->getElementsByTagName('expression'); | ||
759 | - if ($expressionNodes->length == 0) { | ||
760 | - unlink($resultFilePath); | ||
761 | - return array('success' => FALSE, 'message' => 'Cannot get expression nodes in parser result file'); | ||
762 | - } | ||
763 | - | ||
764 | - $crtExpressionNode = NULL; | ||
765 | - foreach ($expressionNodes as $expressionNode) { | ||
766 | - $ihmExpressionNodes = $expressionNode->getElementsByTagName('ihm'); | ||
767 | - if ($ihmExpressionNodes->length == 0) { | ||
768 | - continue; | ||
769 | - } | ||
770 | - if ($ihmExpressionNodes->item(0)->nodeValue == $expression) { | ||
771 | - $crtExpressionNode = $expressionNode; | ||
772 | - break; | ||
773 | - } | ||
774 | - } | ||
775 | - | ||
776 | - if (!isset($crtExpressionNode)) { | ||
777 | - unlink($resultFilePath); | ||
778 | - return array('success' => FALSE, 'message' => 'Cannot retrieve expression in parser result file'); | ||
779 | - } | ||
780 | - | ||
781 | - if ($crtExpressionNode->getAttribute('success') != "true") { | ||
782 | - unlink($resultFilePath); | ||
783 | - return array('success' => FALSE, 'message' => 'Synthax error in expression ' . $expression); | ||
784 | - } | ||
785 | - | ||
786 | - $kernelExpressionNodes = $crtExpressionNode->getElementsByTagName('kernel'); | ||
787 | - if ($kernelExpressionNodes->length == 0) { | ||
788 | - unlink($resultFilePath); | ||
789 | - return array('success' => FALSE, 'message' => 'Cannot retrieve kernel expression in parser result file'); | ||
790 | - } | ||
791 | - | ||
792 | - $kernelExpression = $kernelExpressionNodes->item(0)->nodeValue; | ||
793 | - | ||
794 | - if (empty($kernelExpression)) { | ||
795 | - unlink($resultFilePath); | ||
796 | - return array('success' => FALSE, 'message' => 'Parser return an empty expression'); | ||
797 | - } | ||
798 | - | ||
799 | - $params = array(); | ||
800 | - $paramsNodes = $crtExpressionNode->getElementsByTagName('params'); | ||
801 | - if ($paramsNodes->length != 0) { | ||
802 | - $paramNodes = $paramsNodes->item(0)->getElementsByTagName('param'); | ||
803 | - if ($paramNodes->length != 0) { | ||
804 | - foreach ($paramNodes as $paramNode) { | ||
805 | - if (!empty($paramNode->nodeValue)) { | ||
806 | - $params[] = array( | ||
807 | - 'paramid' => $paramNode->nodeValue | ||
808 | - ); | ||
809 | - } | ||
810 | - } | ||
811 | - } | ||
812 | - } | ||
813 | - | ||
814 | - unlink($resultFilePath); | ||
815 | - | ||
816 | - if (empty($params)) { | ||
817 | - return array('success' => FALSE, 'message' => 'Expression should contain at least one parameter'); | ||
818 | - } | ||
819 | - | ||
820 | - foreach ($params as &$param) { | ||
821 | - $templated_param = $this->templateParamsManager->parseTemplatedParam($param['paramid']); | ||
822 | - if ($templated_param !== FALSE) { | ||
823 | - $param = $templated_param; | ||
824 | - } | ||
825 | - } | ||
826 | - | ||
827 | - $this->cacheExpressionParser[$outputFileName] = array('success' => TRUE, 'expression' => $kernelExpression, 'params' => $params); | ||
828 | - return $this->cacheExpressionParser[$outputFileName]; | ||
829 | - } | ||
830 | - | ||
831 | - public function getTemplateParamsManager() { | ||
832 | - return $this->templateParamsManager; | ||
833 | - } | ||
834 | - | 600 | + public function applyRangesAndIndexes($paramsData, $paramData, $force_total_2d, &$paramInfo) { |
601 | + $dim1_min = 0; | ||
602 | + $dim1_max = 0; | ||
603 | + $dim2_min = 0; | ||
604 | + $dim2_max = 0; | ||
605 | + | ||
606 | + $dim1_is_range = (isset($paramData->{'dim1-sum-type'}) && ($paramData->{'dim1-sum-type'} > 0)); | ||
607 | + $dim1_index = ($dim1_is_range || !isset($paramData->{'dim1-index'}) || ($paramData->{'dim1-index'} == '')) ? '*' : $paramData->{'dim1-index'}; | ||
608 | + if ($dim1_is_range) { | ||
609 | + switch ($paramData->{'dim1-sum-type'}) { | ||
610 | + case 1: | ||
611 | + //Sum between a range of value | ||
612 | + $dim1_min = !empty($paramData->{'dim1-min-value'}) ? $paramData->{'dim1-min-value'} : 0; | ||
613 | + $dim1_max = !empty($paramData->{'dim1-max-value'}) ? $paramData->{'dim1-max-value'} : 0; | ||
614 | + break; | ||
615 | + case 2: | ||
616 | + //Sum between indexes | ||
617 | + $dim1_min = !empty($paramData->{'dim1-min-index'}) ? $paramData->{'dim1-min-index'} : 0; | ||
618 | + $dim1_max = !empty($paramData->{'dim1-max-index'}) ? $paramData->{'dim1-max-index'} : 0; | ||
619 | + break; | ||
620 | + } | ||
621 | + } | ||
622 | + | ||
623 | + $dim2_is_range = (isset($paramData->{'dim2-sum-type'}) && ($paramData->{'dim2-sum-type'} > 0)); | ||
624 | + $dim2_index = ($dim2_is_range || !isset($paramData->{'dim2-index'}) || ($paramData->{'dim2-index'} == '')) ? '*' : $paramData->{'dim2-index'}; | ||
625 | + if ($dim2_is_range) { | ||
626 | + switch ($paramData->{'dim2-sum-type'}) { | ||
627 | + case 1: | ||
628 | + //Sum between a range of value | ||
629 | + $dim2_min = !empty($paramData->{'dim2-min-value'}) ? $paramData->{'dim2-min-value'} : 0; | ||
630 | + $dim2_max = !empty($paramData->{'dim2-max-value'}) ? $paramData->{'dim2-max-value'} : 0; | ||
631 | + break; | ||
632 | + case 2: | ||
633 | + //Sum between indexes | ||
634 | + $dim2_min = !empty($paramData->{'dim2-min-index'}) ? $paramData->{'dim2-min-index'} : 0; | ||
635 | + $dim2_max = !empty($paramData->{'dim2-max-index'}) ? $paramData->{'dim2-max-index'} : 0; | ||
636 | + break; | ||
637 | + } | ||
638 | + } | ||
639 | + | ||
640 | + switch ($paramData->{'type'}) { | ||
641 | + case 0: | ||
642 | + //scalar - nothing to do | ||
643 | + break; | ||
644 | + case 1: | ||
645 | + //Tab1D | ||
646 | + if ($dim1_is_range) { | ||
647 | + $template_args = array( | ||
648 | + 'paramid' => $paramInfo['id'], | ||
649 | + 'min' => $dim1_min, | ||
650 | + 'max' => $dim1_max, | ||
651 | + 'relateddim' => 0, | ||
652 | + ); | ||
653 | + if ($paramData->{'dim1-sum-type'} == 2) | ||
654 | + $paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args); | ||
655 | + else | ||
656 | + $paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args); | ||
657 | + } | ||
658 | + else if ($dim2_is_range) { | ||
659 | + $template_args = array( | ||
660 | + 'paramid' => $paramInfo['id'], | ||
661 | + 'min' => $dim2_min, | ||
662 | + 'max' => $dim2_max, | ||
663 | + 'relateddim' => 1, | ||
664 | + ); | ||
665 | + if ($paramData->{'dim2-sum-type'} == 2) | ||
666 | + $paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args); | ||
667 | + else | ||
668 | + $paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args); | ||
669 | + } | ||
670 | + else if ($dim1_index != '*') { | ||
671 | + $paramInfo['indexes'][] = $dim1_index; | ||
672 | + } | ||
673 | + else if ($dim2_index != '*') { | ||
674 | + $paramInfo['indexes'][] = $dim2_index; | ||
675 | + } | ||
676 | + break; | ||
677 | + case 2: | ||
678 | + //Tab2D | ||
679 | + if ($dim1_is_range && $dim2_is_range) { | ||
680 | + if ($paramData->{'dim1-sum-type'} != $paramData->{'dim2-sum-type'}) { | ||
681 | + throw new Exception("Not supported - Dimensions ranges for ".$paramInfo['id']." must have the same type for each dimensions"); | ||
682 | + } | ||
683 | + $template_args = array( | ||
684 | + 'paramid' => $paramInfo['id'], | ||
685 | + 'min1' => $dim1_min, | ||
686 | + 'max1' => $dim1_max, | ||
687 | + 'relateddim1' => 0, | ||
688 | + 'min2' => $dim2_min, | ||
689 | + 'max2' => $dim2_max, | ||
690 | + ); | ||
691 | + if ($paramData->{'dim1-sum-type'} == 2) | ||
692 | + $paramInfo = $this->addExistingParam('sum_into_table_indexes_2d', $paramsData, $template_args); | ||
693 | + else | ||
694 | + $paramInfo = $this->addExistingParam('sum_into_table_range_2d', $paramsData, $template_args); | ||
695 | + } | ||
696 | + else if ($dim1_is_range) { | ||
697 | + $template_args = array( | ||
698 | + 'paramid' => $paramInfo['id'], | ||
699 | + 'min' => $dim1_min, | ||
700 | + 'max' => $dim1_max, | ||
701 | + 'relateddim' => 0, | ||
702 | + ); | ||
703 | + $tableLink = array( | ||
704 | + 'paramid' => $paramInfo['id'], | ||
705 | + 'relateddim' => 1, | ||
706 | + ); | ||
707 | + if ($paramData->{'dim1-sum-type'} == 2) | ||
708 | + $paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args, $tableLink); | ||
709 | + else | ||
710 | + $paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args, $tableLink); | ||
711 | + if ($dim2_index != '*') { | ||
712 | + $paramInfo['indexes'][] = $dim2_index; | ||
713 | + } | ||
714 | + } | ||
715 | + else if ($dim2_is_range) { | ||
716 | + $template_args = array( | ||
717 | + 'paramid' => $paramInfo['id'], | ||
718 | + 'min' => $dim2_min, | ||
719 | + 'max' => $dim2_max, | ||
720 | + 'relateddim' => 1, | ||
721 | + ); | ||
722 | + $tableLink = array( | ||
723 | + 'paramid' => $paramInfo['id'], | ||
724 | + 'relateddim' => 0, | ||
725 | + ); | ||
726 | + if ($paramData->{'dim2-sum-type'} == 2) | ||
727 | + $paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args, $tableLink); | ||
728 | + else | ||
729 | + $paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args, $tableLink); | ||
730 | + if ($dim1_index != '*') { | ||
731 | + $paramInfo['indexes'][] = $dim1_index; | ||
732 | + } | ||
733 | + } | ||
734 | + else if (($dim1_index != '*') && ($dim2_index != '*')) { | ||
735 | + $paramInfo['indexes'][] = "[".$dim1_index.",".$dim2_index."]"; | ||
736 | + } | ||
737 | + else if ($dim1_index != '*') { | ||
738 | + $paramInfo['indexes'][] = "[".$dim1_index.",*]"; | ||
739 | + } | ||
740 | + else if ($dim2_index != '*') { | ||
741 | + $paramInfo['indexes'][] = "[*,".$dim2_index."]"; | ||
742 | + } | ||
743 | + else if ($force_total_2d) { | ||
744 | + //total over 2 dims | ||
745 | + $template_args = array( | ||
746 | + 'paramid' => $paramInfo['id'], | ||
747 | + ); | ||
748 | + $paramInfo = $this->addExistingParam('total_2D', $paramsData, $template_args); | ||
749 | + } | ||
750 | + break; | ||
751 | + } | ||
752 | + } | ||
753 | + | ||
754 | + public function parseExpression($expression, $workingDir) { | ||
755 | + $outputFileName = "parser_".md5($expression).".xml"; | ||
756 | + if (array_key_exists($outputFileName, $this->cacheExpressionParser)) { | ||
757 | + return $this->cacheExpressionParser[$outputFileName]; | ||
758 | + } | ||
759 | + $parserData = new ParserRequestDataClass(); | ||
760 | + $parserData->setManagerFilePath(IHMConfigClass::getProcessManagerFilePath()); | ||
761 | + $parserData->addExpression($expression); | ||
762 | + $parserData->setWorkingPath($workingDir); | ||
763 | + $parserData->setLocalParamsPath(IHMConfigClass::getLocalParamDBPath()); | ||
764 | + $parserData->setConstantsFilePath(IHMConfigClass::getConstantsFilePath()); | ||
765 | + $parserData->setFunctionsFilePath(IHMConfigClass::getFunctionsFilePath()); | ||
766 | + $parserData->setParamTemplatesFilePath(IHMConfigClass::getParamTemplateListFilePath()); | ||
767 | + $parserData->setFunctionsArgsListFilePath(IHMConfigClass::getFunctionsArgsListFilePath()); | ||
768 | + $parserData->setOutputFileName($outputFileName); | ||
769 | + $resultFilePath = $workingDir."/".$outputFileName; | ||
770 | + | ||
771 | + $parserRequest = new ParserRequestClass(); | ||
772 | + $parserRequest->setData($parserData); | ||
773 | + | ||
774 | + if (!$parserRequest->init() || !$parserRequest->run()) { | ||
775 | + if (file_exists($resultFilePath)) { | ||
776 | + unlink($resultFilePath); | ||
777 | + } | ||
778 | + return array('success' => FALSE, 'message' => 'Error to init or run expression parser'); | ||
779 | + } | ||
780 | + | ||
781 | + //Load result file | ||
782 | + $doc = new DOMDocument(); | ||
783 | + $doc->load($resultFilePath); | ||
784 | + if (!$doc->load($resultFilePath)) { | ||
785 | + if (file_exists($resultFilePath)) { | ||
786 | + unlink($resultFilePath); | ||
787 | + } | ||
788 | + return array('success' => FALSE, 'message' => 'Error to load parser result file'); | ||
789 | + } | ||
790 | + | ||
791 | + $expressionNodes = $doc->getElementsByTagName('expression'); | ||
792 | + if ($expressionNodes->length == 0) { | ||
793 | + unlink($resultFilePath); | ||
794 | + return array('success' => FALSE, 'message' => 'Cannot get expression nodes in parser result file'); | ||
795 | + } | ||
796 | + | ||
797 | + $crtExpressionNode = NULL; | ||
798 | + foreach ($expressionNodes as $expressionNode) { | ||
799 | + $ihmExpressionNodes = $expressionNode->getElementsByTagName('ihm'); | ||
800 | + if ($ihmExpressionNodes->length == 0) { | ||
801 | + continue; | ||
802 | + } | ||
803 | + if ($ihmExpressionNodes->item(0)->nodeValue == $expression) { | ||
804 | + $crtExpressionNode = $expressionNode; | ||
805 | + break; | ||
806 | + } | ||
807 | + } | ||
808 | + | ||
809 | + if (!isset($crtExpressionNode)) { | ||
810 | + unlink($resultFilePath); | ||
811 | + return array('success' => FALSE, 'message' => 'Cannot retrieve expression in parser result file'); | ||
812 | + } | ||
813 | + | ||
814 | + if ($crtExpressionNode->getAttribute('success') != "true") { | ||
815 | + unlink($resultFilePath); | ||
816 | + return array('success' => FALSE, 'message' => 'Synthax error in expression '.$expression); | ||
817 | + } | ||
818 | + | ||
819 | + $kernelExpressionNodes = $crtExpressionNode->getElementsByTagName('kernel'); | ||
820 | + if ($kernelExpressionNodes->length == 0) { | ||
821 | + unlink($resultFilePath); | ||
822 | + return array('success' => FALSE, 'message' => 'Cannot retrieve kernel expression in parser result file'); | ||
823 | + } | ||
824 | + | ||
825 | + $kernelExpression = $kernelExpressionNodes->item(0)->nodeValue; | ||
826 | + | ||
827 | + if (empty($kernelExpression)) { | ||
828 | + unlink($resultFilePath); | ||
829 | + return array('success' => FALSE, 'message' => 'Parser return an empty expression'); | ||
830 | + } | ||
831 | + | ||
832 | + $params = array(); | ||
833 | + $paramsNodes = $crtExpressionNode->getElementsByTagName('params'); | ||
834 | + if ($paramsNodes->length != 0) { | ||
835 | + $paramNodes = $paramsNodes->item(0)->getElementsByTagName('param'); | ||
836 | + if ($paramNodes->length != 0) { | ||
837 | + foreach ($paramNodes as $paramNode) { | ||
838 | + if (!empty($paramNode->nodeValue)) { | ||
839 | + $params[] = array( | ||
840 | + 'paramid' => $paramNode->nodeValue | ||
841 | + ); | ||
842 | + } | ||
843 | + } | ||
844 | + } | ||
845 | + } | ||
846 | + | ||
847 | + unlink($resultFilePath); | ||
848 | + | ||
849 | + if (empty($params)) { | ||
850 | + return array('success' => FALSE, 'message' => 'Expression should contain at least one parameter'); | ||
851 | + } | ||
852 | + | ||
853 | + foreach ($params as &$param) { | ||
854 | + $templated_param = $this->templateParamsManager->parseTemplatedParam($param['paramid']); | ||
855 | + if ($templated_param !== FALSE) { | ||
856 | + $param = $templated_param; | ||
857 | + } | ||
858 | + } | ||
859 | + | ||
860 | + $this->cacheExpressionParser[$outputFileName] = array('success' => TRUE, 'expression' => $kernelExpression, 'params' => $params); | ||
861 | + return $this->cacheExpressionParser[$outputFileName]; | ||
862 | + } | ||
863 | + | ||
864 | + public function getTemplateParamsManager() { | ||
865 | + return $this->templateParamsManager; | ||
866 | + } | ||
835 | } | 867 | } |
src/InputOutput/IHMImpl/Tools/IHMParamTemplateClass.php
@@ -65,9 +65,8 @@ class IHMParamTemplateClass | @@ -65,9 +65,8 @@ class IHMParamTemplateClass | ||
65 | if ($tmp_paramid != "") | 65 | if ($tmp_paramid != "") |
66 | $tmp_paramid .= "_"; | 66 | $tmp_paramid .= "_"; |
67 | $tmp_paramid .= $expression_part; | 67 | $tmp_paramid .= $expression_part; |
68 | - if ($this->isTemplatedParam($tmp_paramid)) { | 68 | + if ($this->isTemplatedParam($tmp_paramid) && strlen($tmp_paramid) > strlen($real_param_id)) { |
69 | $real_param_id = $tmp_paramid; | 69 | $real_param_id = $tmp_paramid; |
70 | - break; | ||
71 | } | 70 | } |
72 | } | 71 | } |
73 | 72 | ||
@@ -292,8 +291,14 @@ class IHMParamTemplateClass | @@ -292,8 +291,14 @@ class IHMParamTemplateClass | ||
292 | if (empty($arguments)) | 291 | if (empty($arguments)) |
293 | return; | 292 | return; |
294 | foreach ($arguments as $arg_key => $arg_def) { | 293 | foreach ($arguments as $arg_key => $arg_def) { |
295 | - if (!array_key_exists($arg_key, $template_args)) | ||
296 | - $template_args->{$arg_key} = $arg_def['default']; | 294 | + if (!array_key_exists($arg_key, $template_args)) { |
295 | + if (is_array($template_args)) { | ||
296 | + $template_args[$arg_key] = $arg_def['default']; | ||
297 | + } | ||
298 | + else { | ||
299 | + $template_args->{$arg_key} = $arg_def['default']; | ||
300 | + } | ||
301 | + } | ||
297 | } | 302 | } |
298 | } | 303 | } |
299 | 304 |
src/InputOutput/IHMImpl/Tools/IHMUserParamManagerClass.php
@@ -23,7 +23,10 @@ class IHMUserParamManagerClass | @@ -23,7 +23,10 @@ class IHMUserParamManagerClass | ||
23 | private static $infoDerivedParsedExpNode = 'parsedExp'; | 23 | private static $infoDerivedParsedExpNode = 'parsedExp'; |
24 | private static $infoDerivedParsedExpValAtt = 'exp'; | 24 | private static $infoDerivedParsedExpValAtt = 'exp'; |
25 | private static $infoDerivedParsedExpHashAtt = 'hash'; | 25 | private static $infoDerivedParsedExpHashAtt = 'hash'; |
26 | - private static $infoDerivedParsedExpParamsAtt = 'params'; | 26 | + private static $infoDerivedParsedExpParamNode = 'param'; |
27 | + private static $infoDerivedParsedExpParamIdAtt = "paramid"; | ||
28 | + private static $infoDerivedParsedExpParamArgNode = 'arg'; | ||
29 | + private static $infoDerivedParsedExpParamArgNameAtt = 'name'; | ||
27 | private static $infoDerivedSamplingModeNode = 'sampling_mode'; | 30 | private static $infoDerivedSamplingModeNode = 'sampling_mode'; |
28 | private static $infoDerivedTimeStepNode = 'timestep'; | 31 | private static $infoDerivedTimeStepNode = 'timestep'; |
29 | private static $infoDerivedRefParamNode = 'reference_param'; | 32 | private static $infoDerivedRefParamNode = 'reference_param'; |
@@ -330,18 +333,42 @@ class IHMUserParamManagerClass | @@ -330,18 +333,42 @@ class IHMUserParamManagerClass | ||
330 | $parsedExpNode = $parsedExpNodes->item(0); | 333 | $parsedExpNode = $parsedExpNodes->item(0); |
331 | $parsedExpVal = $parsedExpNode->getAttribute(self::$infoDerivedParsedExpValAtt); | 334 | $parsedExpVal = $parsedExpNode->getAttribute(self::$infoDerivedParsedExpValAtt); |
332 | $parsedExpHash = $parsedExpNode->getAttribute(self::$infoDerivedParsedExpHashAtt); | 335 | $parsedExpHash = $parsedExpNode->getAttribute(self::$infoDerivedParsedExpHashAtt); |
333 | - $parsedExpParams = $parsedExpNode->getAttribute(self::$infoDerivedParsedExpParamsAtt); | ||
334 | - if (!empty($parsedExpVal) && !empty($parsedExpParams) && (md5($paramExpression) == $parsedExpHash)) { | 336 | + $parsedExpParamNodes = $parsedExpNode->getElementsByTagName(self::$infoDerivedParsedExpParamNode); |
337 | + if (!empty($parsedExpVal) && !empty($parsedExpParams) && !empty($parsedExpParamNodes) && (md5($paramExpression) == $parsedExpHash)) { | ||
338 | + $error = FALSE; | ||
335 | $params = array(); | 339 | $params = array(); |
336 | - foreach (explode(',',$parsedExpParams) as $param) { | ||
337 | - $params[] = array( | ||
338 | - 'paramid' => $param, | 340 | + foreach ($parsedExpParamNodes as $parsedExpParamNode) { |
341 | + $parsedParamId = $parsedExpParamNode->getAttribute(self::$infoDerivedParsedExpParamIdAtt); | ||
342 | + if (empty($parsedParamId)) { | ||
343 | + $error = TRUE; | ||
344 | + break; | ||
345 | + } | ||
346 | + $param_to_add = array( | ||
347 | + 'paramid' => $parsedParamId, | ||
348 | + ); | ||
349 | + $parsedExpParamArgNodes = $parsedExpParamNode->getElementsByTagName(self::$infoDerivedParsedExpParamArgNode); | ||
350 | + if (!empty($parsedExpParamArgNodes)) { | ||
351 | + $param_to_add['template_args'] = array(); | ||
352 | + foreach ($parsedExpParamArgNodes as $parsedExpParamArgNode) { | ||
353 | + $attName = $parsedExpParamArgNode->getAttribute(self::$infoDerivedParsedExpParamArgNameAtt); | ||
354 | + if (empty($attName)) { | ||
355 | + $error = TRUE; | ||
356 | + break; | ||
357 | + } | ||
358 | + $param_to_add['template_args'][$attName] = $parsedExpParamArgNode->nodeValue; | ||
359 | + } | ||
360 | + if ($error) { | ||
361 | + break; | ||
362 | + } | ||
363 | + } | ||
364 | + $params[] = $param_to_add; | ||
365 | + } | ||
366 | + if (!$error) { | ||
367 | + $result['parsedExpression'] = array( | ||
368 | + "expression" => $parsedExpVal, | ||
369 | + "params" => $params, | ||
339 | ); | 370 | ); |
340 | } | 371 | } |
341 | - $result['parsedExpression'] = array( | ||
342 | - "expression" => $parsedExpVal, | ||
343 | - "params" => $params, | ||
344 | - ); | ||
345 | } | 372 | } |
346 | } | 373 | } |
347 | 374 | ||
@@ -462,11 +489,28 @@ class IHMUserParamManagerClass | @@ -462,11 +489,28 @@ class IHMUserParamManagerClass | ||
462 | } | 489 | } |
463 | else { | 490 | else { |
464 | $parsedExpNode = $parsedExpNodes->item(0); | 491 | $parsedExpNode = $parsedExpNodes->item(0); |
492 | + while ($parsedExpNode->hasChildNodes()) { | ||
493 | + $parsedExpNode->removeChild($parsedExpNode->firstChild); | ||
494 | + } | ||
465 | } | 495 | } |
466 | 496 | ||
497 | + | ||
467 | $parsedExpNode->setAttribute(self::$infoDerivedParsedExpValAtt, $expression); | 498 | $parsedExpNode->setAttribute(self::$infoDerivedParsedExpValAtt, $expression); |
468 | $parsedExpNode->setAttribute(self::$infoDerivedParsedExpHashAtt, $hash); | 499 | $parsedExpNode->setAttribute(self::$infoDerivedParsedExpHashAtt, $hash); |
469 | - $parsedExpNode->setAttribute(self::$infoDerivedParsedExpParamsAtt, implode(',',$params)); | 500 | + |
501 | + foreach ($params as $param) { | ||
502 | + $paramNode = $dom->createElement(self::$infoDerivedParsedExpParamNode); | ||
503 | + $paramNode->setAttribute(self::$infoDerivedParsedExpParamIdAtt, $param['paramid']); | ||
504 | + $parsedExpNode->appendChild($paramNode); | ||
505 | + if (!empty($param['template_args'])) { | ||
506 | + foreach ($param['template_args'] as $arg_name => $arg_value) { | ||
507 | + $argNode = $dom->createElement(self::$infoDerivedParsedExpParamArgNode); | ||
508 | + $argNode->setAttribute(self::$infoDerivedParsedExpParamArgNameAtt, $arg_name); | ||
509 | + $argNode->nodeValue = $arg_value; | ||
510 | + $paramNode->appendChild($argNode); | ||
511 | + } | ||
512 | + } | ||
513 | + } | ||
470 | 514 | ||
471 | $dom->save($path); | 515 | $dom->save($path); |
472 | 516 |
src/InputOutput/IHMImpl/Tools/IHMUserWSManagerClass.php
@@ -7,7 +7,7 @@ | @@ -7,7 +7,7 @@ | ||
7 | */ | 7 | */ |
8 | class IHMUserWSManagerClass | 8 | class IHMUserWSManagerClass |
9 | { | 9 | { |
10 | - private static $WS_VERSION = 1; | 10 | + private static $WS_VERSION = 2; |
11 | 11 | ||
12 | protected $wsInfo = null; | 12 | protected $wsInfo = null; |
13 | 13 | ||
@@ -84,6 +84,35 @@ class IHMUserWSManagerClass | @@ -84,6 +84,35 @@ class IHMUserWSManagerClass | ||
84 | return file_put_contents(IHMConfigClass::getUserWSInfoFilePath(),$json_data); | 84 | return file_put_contents(IHMConfigClass::getUserWSInfoFilePath(),$json_data); |
85 | } | 85 | } |
86 | 86 | ||
87 | + private function updateFromVersion1() { | ||
88 | + // Update WS for save download requests | ||
89 | + | ||
90 | + // Load user requests file | ||
91 | + $req_mgr_file_path = IHMConfigClass::getUserRequestManagerFilePath(); | ||
92 | + if (!file_exists($req_mgr_file_path)) { | ||
93 | + return TRUE; | ||
94 | + } | ||
95 | + | ||
96 | + $dom = new DOMDocument(); | ||
97 | + if (!$dom->load($req_mgr_file_path)) { | ||
98 | + return FALSE; | ||
99 | + } | ||
100 | + | ||
101 | + $downloadNodeTag = 'downloadList'; | ||
102 | + $downloadNodes = $dom->documentElement->getElementsByTagName($downloadNodeTag); | ||
103 | + // Id download root node already exists, nothing to do | ||
104 | + if ($downloadNodes->length > 0) { | ||
105 | + return TRUE; | ||
106 | + } | ||
107 | + | ||
108 | + // Create download root node | ||
109 | + $downloadNode = $dom->createElement($downloadNodeTag); | ||
110 | + $downloadNode->setAttribute('xml:id', 'download-treeRootNode'); | ||
111 | + $dom->documentElement->appendChild($downloadNode); | ||
112 | + | ||
113 | + return $dom->save($req_mgr_file_path); | ||
114 | + } | ||
115 | + | ||
87 | private function updateFromVersion0() { | 116 | private function updateFromVersion0() { |
88 | // This update split plot requests | 117 | // This update split plot requests |
89 | 118 |
src/InputOutput/WSImpl/Params/PlotImpl/WSInputOutputParamsPlotClass.php
@@ -130,14 +130,28 @@ class WSInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass | @@ -130,14 +130,28 @@ class WSInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass | ||
130 | 130 | ||
131 | $requestParamsNode->addParam($paramInfo['id']); | 131 | $requestParamsNode->addParam($paramInfo['id']); |
132 | $paramNode = $plotNode->getParams()->getParamById($paramInfo['id']); | 132 | $paramNode = $plotNode->getParams()->getParamById($paramInfo['id']); |
133 | + | ||
134 | + $activateLegends = FALSE; | ||
135 | + if (empty($paramInfo['indexes'])) { | ||
136 | + $paramInfo['indexes'] = array(-1); | ||
137 | + if ($this->isVector($paramInfo['id'])) { | ||
138 | + $activateLegends = TRUE; | ||
139 | + } | ||
140 | + } | ||
141 | + else if (count($paramInfo['indexes']) > 1) { | ||
142 | + $activateLegends = TRUE; | ||
143 | + } | ||
144 | + | ||
145 | + $serieId = 1; | ||
146 | + foreach ($paramInfo['indexes'] as $index) { | ||
147 | + $serieNode = $paramNode->addYSerie('y-left', $index); | ||
148 | + $serieNode->setId($serieId); | ||
149 | + $lineNode = $serieNode->getLine(); | ||
150 | + $lineNode->setType(RequestOutputPlotLineTypeEnum::LINE); | ||
151 | + ++$serieId; | ||
152 | + } | ||
133 | 153 | ||
134 | - $serieNode = $paramNode->addYSerie('y-left', -1); | ||
135 | - $serieNode->setId('1'); | ||
136 | - | ||
137 | - $lineNode = $serieNode->getLine(); | ||
138 | - $lineNode->setType(RequestOutputPlotLineTypeEnum::LINE); | ||
139 | - | ||
140 | - if ($this->isVector($paramInfo['id'])) { // vector - activate legend | 154 | + if ($activateLegends) { // vector - activate legend |
141 | $paramLegendNode = $plotNode->getLegends()->getParamsLegend(); | 155 | $paramLegendNode = $plotNode->getLegends()->getParamsLegend(); |
142 | $paramLegendNode->setType(RequestOutputPlotParamsLegendTypeEnum::TEXTONLY); | 156 | $paramLegendNode->setType(RequestOutputPlotParamsLegendTypeEnum::TEXTONLY); |
143 | $paramLegendNode->setShowParamInfo("true"); | 157 | $paramLegendNode->setShowParamInfo("true"); |
src/Request/ParamsRequestImpl/Nodes/Params/ParamNodeClass.php
@@ -157,7 +157,7 @@ class ParamNodeClass extends NodeClass | @@ -157,7 +157,7 @@ class ParamNodeClass extends NodeClass | ||
157 | 157 | ||
158 | $refParamNode = $this->getXmlNodeChildByTagName($xmlNode, PARAM_REF_PARAM); | 158 | $refParamNode = $this->getXmlNodeChildByTagName($xmlNode, PARAM_REF_PARAM); |
159 | if (isset($refParamNode)) | 159 | if (isset($refParamNode)) |
160 | - $this->setReferenceParameter($this->getXmlNodeValue($$refParamNode)); | 160 | + $this->setReferenceParameter($this->getXmlNodeValue($refParamNode)); |
161 | 161 | ||
162 | $infoXmlNode = $this->getXmlNodeChildByTagName($xmlNode, INFOPARAM_TAGNAME); | 162 | $infoXmlNode = $this->getXmlNodeChildByTagName($xmlNode, INFOPARAM_TAGNAME); |
163 | if (isset($infoXmlNode)) | 163 | if (isset($infoXmlNode)) |