Blame view

src/InputOutput/IHMImpl/Tools/IHMParamManagerClass.php 34.6 KB
22521f1c   Benjamin Renard   First commit
1
2
3
4
5
6
7
<?php

/**
 * @class IHMParamManagerClass
 * @brief Parameter manager
 * @details
 */
22521f1c   Benjamin Renard   First commit
8
9
class IHMParamManagerClass
{
96c9cffa   Benjamin Renard   Keep expression p...
10
	protected $userParameterMgr = null;
bf27ba04   Benjamin Renard   Add templated par...
11
	protected $templateParamsManager = null;
ffc5cb81   Elena.Budnik   temporary commit
12
	protected $paramImpexMgr     = null;
52c1e291   Benjamin Renard   Generate TT and c...
13
	protected $ttCatMgr = null;
f03c62e3   Benjamin Renard   Keep in cache res...
14
	protected $cacheExpressionParser = null;
22521f1c   Benjamin Renard   First commit
15
16
17
18
19
20
	
	/*
	 * @brief Constructor
	*/
	function __construct()
	{
bf27ba04   Benjamin Renard   Add templated par...
21
		$this->templateParamsManager = new IHMParamTemplateClass();
f03c62e3   Benjamin Renard   Keep in cache res...
22
		$this->cacheExpressionParser = array();
22521f1c   Benjamin Renard   First commit
23
24
	}

4c975261   Benjamin Renard   Add modif. time f...
25
	public function addGeneratedParam($paramId, $expression, $sampling_mode, $sampling_step, $ref_param, $paramsData)
cd28a380   Benjamin Renard   Generate param in...
26
	{
a928f9d3   Benjamin Renard   New parser integr...
27
28
29
30
		$expressionInfo = $this->parseExpression($expression, $paramsData->getWorkingPath());
		if (!$expressionInfo['success']) {
			throw new Exception($expressionInfo['message']);
		}
cd28a380   Benjamin Renard   Generate param in...
31
32
33

                //create a process param for the derived parameter
                $this->addProcessParam($paramId, $expressionInfo["expression"], $expression,
4c975261   Benjamin Renard   Add modif. time f...
34
                                $expressionInfo['params'], $sampling_mode, $sampling_step, $ref_param,
b1a5ee3c   Erdogan Furkan   Integration part ...
35
                                0, time(), "", "","", $paramsData);
cd28a380   Benjamin Renard   Generate param in...
36
37
	}

22521f1c   Benjamin Renard   First commit
38
39
40
	/*
	 * @brief Add an existing parameter
	*/
52859c27   Benjamin Renard   Give the possibil...
41
	public function addExistingParam($param, $paramsData, $templateArgs = NULL, $tableLink = NULL)
d1a35428   Benjamin Renard   Update template a...
42
	{
22521f1c   Benjamin Renard   First commit
43
44
45
46
		if ($this->isDerivedParam($param))
			return $this->addDerivedParam($param,$paramsData);
		else if ($this->isUploadedParam($param))
			return $this->addUploadedParam($param,$paramsData);
ffc5cb81   Elena.Budnik   temporary commit
47
48
		else if ($this->isImpexParam($param))
			return $this->addImpexParam($param,$paramsData,$templateArgs);	
1bd64e14   Erdogan Furkan   Integration part ...
49
50
		else if($this->isTTCatParam($param))
			return $this->addTTCatParam($param,$paramsData);
22521f1c   Benjamin Renard   First commit
51
		else
52859c27   Benjamin Renard   Give the possibil...
52
			return $this->addLocalParam($param,$paramsData,$templateArgs, $tableLink);
22521f1c   Benjamin Renard   First commit
53
54
55
		return "";
	}

b1a5ee3c   Erdogan Furkan   Integration part ...
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
	public function statusStrToArray($statusStr){
		$defs = explode("-",$statusStr);
		if (!empty($statusStr)) {
			foreach ($defs as $def) {
				$def = trim($def);
				$p = strpos($def, ":");
				if ($p === FALSE) {
					continue;
				}
				
				$vals = trim(substr($def, 0, $p));
				$name = substr($def, $p+1);

				$name = trim($name);
				$color = "";
				$p = strpos($name, "[");
				if ($p !== FALSE) {
					$color = substr($name, $p);
					$color = trim($color);
					$name = substr($name, 0, $p);
					$name = trim($name);
					if(empty($name))
						$name = $vals;
				}

				$p2=strpos($vals, ",");
				$minVal = "";
				$maxVal = "";
				if ($p2 !== FALSE) {
					$minVal= trim(substr($vals, 1, $p2));
					$maxVal =  trim(substr($vals,$p2+1, -1));
				}
				else{
					$minVal= $vals;
					$maxVal = $vals;
				}
				$status[] = array(
					"min" => floatval($minVal),
					"max" => floatval($maxVal),
					"name" => $name,
					"color" => $color,
				);
			}
			return $status;
		}

	}

22521f1c   Benjamin Renard   First commit
104
105
106
	/*
	 * @brief Add a process parameter
	*/
b1a5ee3c   Erdogan Furkan   Integration part ...
107
	public function addProcessParam($paramId,$expression,$expression_info,$params, $sampling_mode, $sampling_step, $ref_param, $gap,$dateModif,$units,$ytitle,$statusStr,$paramsData)
c0535e83   Benjamin Renard   Use units and yTi...
108
	{
b1a5ee3c   Erdogan Furkan   Integration part ...
109
110
111
		$status = $this->statusStrToArray($statusStr);

		$paramsData->addProcessParamToCreate($paramId, $expression, $expression_info, $params, $sampling_mode, $sampling_step, $ref_param, $gap,$dateModif, $units, $ytitle, $status); 
ffc5cb81   Elena.Budnik   temporary commit
112
	 
e4545ed5   Benjamin Renard   Implement templat...
113
		foreach ($params as $param) {
ffc5cb81   Elena.Budnik   temporary commit
114
115
			$template_args = NULL; 
			 
e4545ed5   Benjamin Renard   Implement templat...
116
117
			if (array_key_exists("template_args", $param))
				$template_args = $param["template_args"];
ffc5cb81   Elena.Budnik   temporary commit
118
	 		 
e4545ed5   Benjamin Renard   Implement templat...
119
120
			$this->addExistingParam($param["paramid"],$paramsData,$template_args);
		}
4c975261   Benjamin Renard   Add modif. time f...
121
122
123
		if (!empty($ref_param)) {
			$this->addExistingParam($ref_param, $paramsData,$template_args);
		}
22521f1c   Benjamin Renard   First commit
124
125
126
127
128

		return true;
	}

	/*
52c1e291   Benjamin Renard   Generate TT and c...
129
130
131
132
133
134
135
136
137
138
	 *  @brief Add a TT or catalog parameter
	 */
	public function addTTCatParam($paramId, $paramsData)
	{
		if (!isset($this->ttCatMgr)) {
			$this->ttCatMgr = new IHMTTCatLoaderClass();
		}
		$info = $this->ttCatMgr->getTTCatInfoFromId($paramId);

		if (!$info["success"]) {
1bd64e14   Erdogan Furkan   Integration part ...
139
140
141
142
143
144
145
146
147
148
149
			$paramName = $paramId;
			foreach(array("tt_","cat_","sharedtimeTable_","sharedcartalog_") as $prefix){
				if(strpos($paramName, $prefix) === 0){
					$paramName = substr($paramName, strlen($prefix));
					break;
				}
			}
			$info = $this->ttCatMgr->getTTCatInfoFromName($paramName);
			if (!$info["success"]) {
				throw new Exception($info["message"]);
			}
52c1e291   Benjamin Renard   Generate TT and c...
150
151
152
153
154
155
156
157
		}

		$status = array();
		$units = "";
		$ytitle = "";
		$flag = "";

		if ($info["info"]["isCatalog"]) {
1bd64e14   Erdogan Furkan   Integration part ...
158
			$parameters = $this->ttCatMgr->getCatalogParameters($info["info"]["id"]);
52c1e291   Benjamin Renard   Generate TT and c...
159
			if (!$parameters["success"] || empty($parameters["parameters"])) {
1bd64e14   Erdogan Furkan   Integration part ...
160
				throw new Exception("Error to extract first parameter of ".$info["info"]["id"]);
52c1e291   Benjamin Renard   Generate TT and c...
161
162
163
164
165
166
167
			}
			//For the moment, use the first parameter
			$parameter = $parameters["parameters"][0];
			$units     = $parameter["units"];
			$ytitle    = !empty($parameter["name"]) ? $parameter["name"] : $parameter["id"];
			$flag      = $parameter["id"];
			$description = $parameter["description"];
7cced201   Erdogan Furkan   Done.
168
			$statusParam = $parameter["status"];
52c1e291   Benjamin Renard   Generate TT and c...
169
			$desc_parts = array();
7cced201   Erdogan Furkan   Done.
170
171
			$defs = explode("-",$statusParam);
			if (empty($statusParam)) {
4ea242cb   Benjamin Renard   Fix
172
173
174
175
176
				//No status defined => Read catalog as TT
				$info["info"]["isCatalog"] = FALSE;
				$flag = "";
				$units = "";
				$ytitle = $info["info"]["name"];
71447305   Benjamin Renard   Plot catalog as T...
177
178
179
180
181
				$status = array(
					array(
						"min" => -PHP_FLOAT_MAX,
						"max" => PHP_FLOAT_MAX,
						"name" => "Inside",
a0693995   Benjamin Renard   Fix bug with inte...
182
						//"color" => "[255,0,0]",
71447305   Benjamin Renard   Plot catalog as T...
183
184
185
186
					),
				);
			}
			else {
b1a5ee3c   Erdogan Furkan   Integration part ...
187
				$status = $this->statusStrToArray($statusParam);
52c1e291   Benjamin Renard   Generate TT and c...
188
189
190
191
192
193
194
195
			}
		}
		else {
			$status = array(
				array(
					"min" => 1,
					"max" => 1,
					"name" => "Inside",
a0693995   Benjamin Renard   Fix bug with inte...
196
					//"color" => "[255,0,0]",
52c1e291   Benjamin Renard   Generate TT and c...
197
198
199
200
201
202
203
204
205
206
				)
			);
			$ytitle = $info["info"]["name"];
		}

		$paramsData->addTTCatParamToCreate($paramId, $info["info"]["path"], $info["info"]["isShared"], filemtime($info["info"]["path"]), $units, $ytitle, $status, $flag);
		return array("id" => $paramId, "indexes" => array(), "calib_infos" => array());
	} 

	/*
22521f1c   Benjamin Renard   First commit
207
208
209
210
211
212
213
214
	 * @brief Detect if it's a derived parameter
	*/
	private function isDerivedParam($param)
	{
		return preg_match("#^ws_#",$param);
	}

	/*
1bd64e14   Erdogan Furkan   Integration part ...
215
216
217
218
219
220
221
222
223
	 * @brief Detect if it's a TT/Cat parameter
	*/
	private function isTTCatParam($param)
	{
		return preg_match("#^tt_#",$param) || preg_match("#^cat_#",$param) || 
			   preg_match("#^sharedtimeTable_#",$param) || preg_match("#^sharedcatalog_#",$param);
	}

	/*
22521f1c   Benjamin Renard   First commit
224
225
	 * @brief Detect if it's a uploaded parameter
	*/
dcdacd5c   Benjamin Renard   Fill plot type in...
226
	public function isUploadedParam($param)
22521f1c   Benjamin Renard   First commit
227
228
229
	{
		return preg_match("#^wsd_#",$param);
	}
ffc5cb81   Elena.Budnik   temporary commit
230
231
232
233
234
235
236
237
	
	/*
	 * @brief Detect if it's IMPEX parameter
	*/
	private function isImpexParam($param)
	{
		return preg_match("#^".IHMImpexParamClass::$paramPrefix."#",$param);
	}
22521f1c   Benjamin Renard   First commit
238
239

	/*
9b996a31   Benjamin Renard   Split param compo...
240
241
242
	 * @brief Split param components if defined
	 */
	private function splitParamComponents($param)
22521f1c   Benjamin Renard   First commit
243
	{
22521f1c   Benjamin Renard   First commit
244
		$indexes     = array();
22521f1c   Benjamin Renard   First commit
245
246
247
248
249
250
251
252
253
		$pattern = "/(?P<param>.*)\((?P<components>.*)\)/";
		preg_match_all($pattern, $param, $matches);
		if ((count($matches["param"]) > 0) && (count($matches["components"]) > 0))
		{
			$paramId       = $matches["param"][0];
			$indexes = explode(",",$matches["components"][0]);
		}
		else
			$paramId = $param;
9b996a31   Benjamin Renard   Split param compo...
254
255
256
257
258
259
260
261
262
263
264
265
266
		return array('param' => $paramId, 'indexes' => $indexes);
	}

	/*
	 * @brief Add a local parameter
	*/
	private function addLocalParam($param, $paramsData, $templateArgs, $tableLink)
	{
		//local parameter
		$res = $this->splitParamComponents($param);
		$indexes = $res['indexes'];
		$paramId = $res['param'];
		$calib_infos = array();
ffc5cb81   Elena.Budnik   temporary commit
267
	 
bf27ba04   Benjamin Renard   Add templated par...
268
269
		//check templated parameter
		$real_param_id = $paramId;
0dd42438   Benjamin Renard   WS getDataset wit...
270
		$paramPath = "";
bf27ba04   Benjamin Renard   Add templated par...
271
		if ($this->templateParamsManager->isTemplatedParam($paramId)) {
52859c27   Benjamin Renard   Give the possibil...
272
			$paramPath = $this->templateParamsManager->generateTemplatedParamFile($paramId, $templateArgs, $tableLink);
bf27ba04   Benjamin Renard   Add templated par...
273
			$real_param_id = $this->templateParamsManager->getTemplatedParamId($paramId, $templateArgs);
bf27ba04   Benjamin Renard   Add templated par...
274
275
276
277
278
279
			if (empty($paramPath) || !file_exists($paramPath))
				throw new Exception('Cannot generate parameter template file '.$paramId);
		}
		else {
			$paramPath = IHMConfigClass::getLocalParamDBPath().$paramId.".xml";
			if (!file_exists($paramPath))
ab2ddaca   Benjamin Renard   Remove debug info
280
				throw new Exception('Cannot find parameter local file '.$paramId);
bf27ba04   Benjamin Renard   Add templated par...
281
		}
22521f1c   Benjamin Renard   First commit
282

bf27ba04   Benjamin Renard   Add templated par...
283
		$paramsData->addParamToCopy($real_param_id,$paramPath);
22521f1c   Benjamin Renard   First commit
284

bf27ba04   Benjamin Renard   Add templated par...
285
		$this->addLinkedLocalParams($paramId, $paramsData, $templateArgs);
22521f1c   Benjamin Renard   First commit
286
			
0dd42438   Benjamin Renard   WS getDataset wit...
287
		return array("id" => $real_param_id, "indexes" => $indexes, "calib_infos" => $calib_infos, "path" => $paramPath);
22521f1c   Benjamin Renard   First commit
288
289
290
291
292
	}

	/*
	 * @brief Add linked parameter
	*/
bf27ba04   Benjamin Renard   Add templated par...
293
	private function addLinkedLocalParams($paramId,$paramsData,$templateArgs = NULL)
22521f1c   Benjamin Renard   First commit
294
	{
952dd7c7   elena   catalog integration
295
296
		$doc = new DOMDocument("1.0", "UTF-8");
		$doc->preserveWhiteSpace = false;
22521f1c   Benjamin Renard   First commit
297
298
		$doc->formatOutput = true;

cd3326be   Benjamin Renard   Fix function used...
299
		$real_param_id = $paramId;
bf27ba04   Benjamin Renard   Add templated par...
300
		if ($this->templateParamsManager->isTemplatedParam($paramId)) {
cd3326be   Benjamin Renard   Fix function used...
301
			$paramPath = $this->templateParamsManager->getTemplatePath($paramId);
8ade06fe   Benjamin Renard   Improve config load
302
			if (empty($paramPath) || !@$doc->load($paramPath))
f1252b32   Benjamin Renard   Add template for ...
303
				throw new Exception('Cannot find parameter template file '.$paramId);
bf27ba04   Benjamin Renard   Add templated par...
304
305
306
		}
		else {
			$paramPath = IHMConfigClass::getLocalParamDBPath().$paramId.".xml";
8ade06fe   Benjamin Renard   Improve config load
307
			if (empty($paramPath) || !@$doc->load($paramPath))
ab2ddaca   Benjamin Renard   Remove debug info
308
				throw new Exception('Cannot find parameter local file '.$paramId);
bf27ba04   Benjamin Renard   Add templated par...
309
310
		}
			
22521f1c   Benjamin Renard   First commit
311
312
313
314
315
316
317
318
319
320
321
322
323
324
		//<get>
		$getNodes = $doc->getElementsByTagName('get');

		if ($getNodes->length <= 0)
			throw new Exception('Parameter local file '.$paramId.' dont have a getter node');

		$getNode = $getNodes->item(0);

		//<amdaParam name="imf"/>
		$amdaParamNodes = $doc->getElementsByTagName('amdaParam');

		foreach($amdaParamNodes as $amdaParamNode)
		{
			$linkedParamId = $amdaParamNode->getAttribute('name');
cd3326be   Benjamin Renard   Fix function used...
325
			if (empty($linkedParamId))
22521f1c   Benjamin Renard   First commit
326
				continue;
7911f4bc   Benjamin Renard   Another bug with ...
327
			$template_id = $this->templateParamsManager->getTemplateId($linkedParamId);
d1a35428   Benjamin Renard   Update template a...
328
			$tempArgs = isset($templateArgs) ? $templateArgs : array();
7911f4bc   Benjamin Renard   Another bug with ...
329
330
331
			if ($template_id !== FALSE) {
				$linkedParamId = $template_id;
			}
7d35612a   Benjamin Renard   Fix ParamManager ...
332
333
			else {
				$linkedParamId = $this->templateParamsManager->replaceArgs($linkedParamId, $templateArgs);
97d1c981   Benjamin Renard   Fix bug with a te...
334
335
336
				$parsedParam = $this->templateParamsManager->parseTemplatedParam($linkedParamId);
				if ($parsedParam !== FALSE) {
					$linkedParamId = $parsedParam['paramid'];
d1a35428   Benjamin Renard   Update template a...
337
338
339
					foreach ($parsedParam['template_args'] as $key => $val) {
						$tempArgs[$key] = $val;
					}
97d1c981   Benjamin Renard   Fix bug with a te...
340
				}
7d35612a   Benjamin Renard   Fix ParamManager ...
341
			}
7911f4bc   Benjamin Renard   Another bug with ...
342
343

			if ($this->templateParamsManager->isTemplatedParam($linkedParamId)) {
d1a35428   Benjamin Renard   Update template a...
344
345
				$linkedParamPath = $this->templateParamsManager->generateTemplatedParamFile($linkedParamId, $tempArgs);
				$real_linked_param_id = $this->templateParamsManager->getTemplatedParamId($linkedParamId, $tempArgs);
cd3326be   Benjamin Renard   Fix function used...
346
347
			}
			else {
7911f4bc   Benjamin Renard   Another bug with ...
348
349
				$real_linked_param_id = $linkedParamId;
				$linkedParamPath = IHMConfigClass::getLocalParamDBPath().$real_linked_param_id.".xml";
bf27ba04   Benjamin Renard   Add templated par...
350
			}
7911f4bc   Benjamin Renard   Another bug with ...
351
352
			$paramsData->addParamToCopy($real_linked_param_id,$linkedParamPath);
			$this->addLinkedLocalParams($linkedParamId, $paramsData);
22521f1c   Benjamin Renard   First commit
353
354
355
356
357
358
359
360
		}
	}

	/*
	 * @brief Add derived parameter
	*/
	private function addDerivedParam($param,$paramsData)
	{
9b996a31   Benjamin Renard   Split param compo...
361
362
363
364
		$res = $this->splitParamComponents($param);
		$indexes = $res['indexes'];
		$param = $res['param'];

f03c62e3   Benjamin Renard   Keep in cache res...
365
		$time = time();
96c9cffa   Benjamin Renard   Keep expression p...
366
367
		if (!isset($this->userParameterMgr))
			$this->userParameterMgr = new IHMUserParamManagerClass();
22521f1c   Benjamin Renard   First commit
368
369
		
		//get derived parameter info
96c9cffa   Benjamin Renard   Keep expression p...
370
		$res = $this->userParameterMgr->getDerivedParameterFromName($param);
f03c62e3   Benjamin Renard   Keep in cache res...
371

22521f1c   Benjamin Renard   First commit
372
373
374
		if (!$res["success"])
			throw new Exception('Error to load derived parameter file : '.$res["message"]);

96c9cffa   Benjamin Renard   Keep expression p...
375
376
377
378
379
380
381
		if (isset($res["param"]["info"]["parsedExpression"])) {
			//Re use existing parsed expression info
			$expressionInfo = $res["param"]["info"]["parsedExpression"];
		}
		else {
			//parse expression
			$expressionInfo = $this->parseExpression($res["param"]["expression"], $paramsData->getWorkingPath());
a928f9d3   Benjamin Renard   New parser integr...
382

96c9cffa   Benjamin Renard   Keep expression p...
383
384
385
			if (!$expressionInfo['success']) {
				throw new Exception($expressionInfo['message']);
			}
ec67a1c5   Benjamin Renard   Store template ar...
386
			$this->userParameterMgr->saveDerivedParameterParsedExpression($res["param"]["id"], $expressionInfo["expression"], md5($res["param"]["expression"]), $expressionInfo['params']);
a928f9d3   Benjamin Renard   New parser integr...
387
		}
96c9cffa   Benjamin Renard   Keep expression p...
388

952dd7c7   elena   catalog integration
389
		$paramId = $param;
9b996a31   Benjamin Renard   Split param compo...
390
391
392
393
394
395

		$reference_param = $res["param"]["info"]["reference_param"];
		if (!empty($res["param"]["info"]["reference_param"])) {
			$res_split = $this->splitParamComponents($reference_param);
			$reference_param = $res_split['param'];
		}
d32597f2   Erdogan Furkan   #10706 - Done
396
397
398

		// On plot, no need to plot "ws_" on derived parameter legend.
		$newParamName="";
d32597f2   Erdogan Furkan   #10706 - Done
399
400
401
		if(strpos($paramId, "ws_") === 0){
			$newParamName=substr($paramId,3);
		}
952dd7c7   elena   catalog integration
402
		//create a process param for the derived parameter
e9165342   Benjamin Renard   Write data mining...
403
		$this->addProcessParam($paramId, $expressionInfo["expression"], $res["param"]["expression"],
9b996a31   Benjamin Renard   Split param compo...
404
				$expressionInfo['params'], $res["param"]["info"]["sampling_mode"], $res["param"]["info"]["timestep"], $reference_param,
c0535e83   Benjamin Renard   Use units and yTi...
405
				0,$res["param"]["dateModif"],!empty($res["param"]["info"]["units"]) ? $res["param"]["info"]["units"] : "",
b1a5ee3c   Erdogan Furkan   Integration part ...
406
407
				!empty($res["param"]["info"]["yTitle"]) ? $res["param"]["info"]["yTitle"] : $newParamName,
				!empty($res["param"]["info"]["status"]) ? $res["param"]["info"]["status"] : "", $paramsData);
f03c62e3   Benjamin Renard   Keep in cache res...
408

9b996a31   Benjamin Renard   Split param compo...
409
		return array("id" => $paramId, "indexes" => $indexes, "calib_infos" => array());
22521f1c   Benjamin Renard   First commit
410
	}
d1a35428   Benjamin Renard   Update template a...
411

ffc5cb81   Elena.Budnik   temporary commit
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
	/*
	 * @brief Add IMPEX parameter : create dynamically xml parameter descriptor in user WS
	*/
	private function addImpexParam($param,$paramsData,$templateArgs = NULL)	
	{		 	
		if (!isset($this->paramImpexMgr))
			$this->paramImpexMgr = new ImpexParamManager();
			
		$parameterID = $this->paramImpexMgr->getImpexFullParamId($param, $templateArgs);
		
		$requestNodes = $paramsData->getRequestNodes();
		 
		// it is PARAMSGEN 
		if (!$requestNodes) {
			return array("id" => $parameterID); 
		}
	 
		$timesNode = $requestNodes[0]->getTimesNode();
		$intervals = $timesNode->getIntervals();
		$originFile = IHMConfigClass::getUserWSPath().$parameterID.".xml";
	  
		if (!file_exists($originFile)) {
			// create IMPEX parameter info and data				
			$res = $this->paramImpexMgr->createImpexParameter($param, $intervals, $templateArgs);
			
			if (!$res["success"])
				throw new Exception('Error to create IMPEX parameter : '.$res["message"]);
				
			$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"],
b1a5ee3c   Erdogan Furkan   Integration part ...
444
				NULL,$res["param"]["dateModif"],"",true);
ffc5cb81   Elena.Budnik   temporary commit
445
				
577d5c04   Elena.Budnik   IMPEX integration
446
447
448
449
				$newParamNode->getInfo()->setName($res["param"]["info"]['name']);
				$newParamNode->getInfo()->setShortName($res["param"]["info"]['name']);
				$newParamNode->getInfo()->setUnits($res["param"]["info"]['units']);
				
ffc5cb81   Elena.Budnik   temporary commit
450
451
452
				$tableDef = $res["param"]["info"]["tableDef"];
				if (isset($tableDef) && array_key_exists('tableDefType', $tableDef) && ($tableDef['tableDefType'] != 'NONE'))
				{
577d5c04   Elena.Budnik   IMPEX integration
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
					switch ($tableDef['channelsDefType'])
					{
						case 'BOUND'  :
							$boundTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::BOUNDS, $res["param"]["info"]["yTitle"]);
							$boundTable->setUnits($res["param"]["info"]["yUnits"]);
							switch ($tableDef['tableDefType'])
							{
								case 'SELECT' :
									$boundTable->setBoundsName($tableDef['data']['bound']);
									$newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['bound']);
									break;
								default :
									throw new Exception("Unknown tableDefType ".$tableDef['tableDefType']);
							}
							break;
						case 'CENTER' :
							$centerTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTER, $res["param"]["info"]["yTitle"]);
							$centerTable->setUnits($res["param"]["info"]["yUnits"]);
							$centerTable->setSize($tableDef['data']['width']);
							switch ($tableDef['tableDefType'])
							{
								case 'SELECT' :
									$centerTable->setCenterName($tableDef['data']['center']);
									$newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']);
									break;
								default :
									throw new Exception("Unknown tableDefType ".$tableDef['tableDefType']);
							}
						break;
						default :
							throw new Exception("Unknown tableDefType ".$tableDef['channelsDefType']);
					}
ffc5cb81   Elena.Budnik   temporary commit
485
486
487
488
489
490
491
492
493
494
495
496
497
				}
				
				return array("id" => $res["param"]["id"], "plotType" => $res["param"]["info"]["plotType"]);
			}
		else {		     
			 // add IMPEX parameter data
			 $this->paramImpexMgr->addImpexData($param, $intervals, $templateArgs);			 
			 $paramsData->addParamToCopy($parameterID, $originFile);
			 
			 return array("id" => $parameterID);
		} 
	}
	
22521f1c   Benjamin Renard   First commit
498
499
500
501
502
	/*
	 * @brief Add uploaded parameter
	*/
	private function addUploadedParam($param,$paramsData)
	{
9b996a31   Benjamin Renard   Split param compo...
503
504
505
506
		$res = $this->splitParamComponents($param);
		$indexes = $res['indexes'];
		$param = $res['param'];

96c9cffa   Benjamin Renard   Keep expression p...
507
508
		if (!isset($this->userParameterMgr))
			$this->userParameterMgr = new IHMUserParamManagerClass();
944199fe   Benjamin Renard   Use table definit...
509
510
		
		//get uploaded parameter info
96c9cffa   Benjamin Renard   Keep expression p...
511
		$res = $this->userParameterMgr->getUploadedParameterFromName($param);
944199fe   Benjamin Renard   Use table definit...
512
513
514
		
		if (!$res["success"])
			throw new Exception('Error to load uploaded parameter file : '.$res["message"]);
67c43328   Benjamin Renard   Fix uploaded para...
515
516

		$paramId = $param;
b1a5ee3c   Erdogan Furkan   Integration part ...
517
		$status = $this->statusStrToArray($res["param"]["info"]["status"]);
67c43328   Benjamin Renard   Fix uploaded para...
518
		$newParamNode = $paramsData->addLocalParamToCreate($paramId, 
944199fe   Benjamin Renard   Use table definit...
519
520
				$res["param"]["info"]["viId"], $res["param"]["info"]["realVar"],
				$res["param"]["info"]["minSampling"], $res["param"]["info"]["maxSampling"],
e8ff4ba7   Elena.Budnik   integration of as...
521
				$res["param"]["info"]["type"],$res["param"]["info"]["size"],
b1a5ee3c   Erdogan Furkan   Integration part ...
522
				$res["param"]["info"]["fillValue"],$res["param"]["dateModif"],$status);
e8ff4ba7   Elena.Budnik   integration of as...
523

8289ec06   Benjamin Renard   Y-Title and Units...
524
525
526
527
528
529
530
531
		if (!empty($res["param"]["info"]["yTitle"])) {
			$newParamNode->getInfo()->setName($res["param"]["info"]['yTitle']);
			$newParamNode->getInfo()->setShortName($res["param"]["info"]['yTitle']);
		}
		if (!empty($res["param"]["info"]['units'])) {
			$newParamNode->getInfo()->setUnits($res["param"]["info"]['units']);
		}

944199fe   Benjamin Renard   Use table definit...
532
533
534
535
		
		$tableDef = $res["param"]["info"]["tableDef"];
		if (isset($tableDef) && array_key_exists('tableDefType', $tableDef) && ($tableDef['tableDefType'] != 'NONE'))
		{
df380a21   Benjamin Renard   Fix table name de...
536
537
			$tableName = empty($tableDef['tableName']) ? 'Table' : $tableDef['tableName'];
			$tableUnits = empty($tableDef['tableUnits']) ? '' : $tableDef['tableUnits'];
944199fe   Benjamin Renard   Use table definit...
538
539
540
			switch ($tableDef['channelsDefType'])
			{
				case 'MINMAX' :
df380a21   Benjamin Renard   Fix table name de...
541
542
					$minMaxTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::MINMAX, $tableName);
					$minMaxTable->setUnits($tableUnits);
944199fe   Benjamin Renard   Use table definit...
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
					switch ($tableDef['tableDefType'])
					{
						case 'SELECT' :
							$minMaxTable->setMinName($tableDef['data']['min']);
							$minMaxTable->setMaxName($tableDef['data']['max']);
							$newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['min']);
							$newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['max']);
							break;
						case 'MANUAL' :
							$minMaxTable->setMinName('min');
							$minMaxTable->setMaxName('max');
							$clbMinNode = $newParamNode->addClbManual('min');
							$clbMinValues = explode(',', $tableDef['data']['min']);
							foreach ($clbMinValues as $value)
								$clbMinNode->addClbValue($value);
							$clbMaxNode = $newParamNode->addClbManual('max');
							$clbMaxValues = explode(',', $tableDef['data']['max']);
							foreach ($clbMaxValues as $value)
								$clbMaxNode->addClbValue($value);
						break;
					}
					break;
				case 'BOUND'  :
df380a21   Benjamin Renard   Fix table name de...
566
567
					$boundTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::BOUNDS, $tableName);
					$boundTable->setUnits($tableUnits);
944199fe   Benjamin Renard   Use table definit...
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
					switch ($tableDef['tableDefType'])
					{
						case 'SELECT' :
							$boundTable->setBoundsName($tableDef['data']['bound']);
							$newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['bound']);
							break;
						case 'MANUAL' :
							$boundTable->setBoundsName('bound');
							$clbBoundNode = $newParamNode->addClbManual('bound');
							$clbBoundValues = explode(',', $tableDef['data']['bound']);
							foreach ($clbBoundValues as $value)
								$clbBoundNode->addClbValue($value);
							break;
					}
					break;
				case 'CENTER' :
df380a21   Benjamin Renard   Fix table name de...
584
585
					$centerTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTER, $tableName);
					$centerTable->setUnits($tableUnits);
944199fe   Benjamin Renard   Use table definit...
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
					$centerTable->setSize($tableDef['data']['width']);
					switch ($tableDef['tableDefType'])
					{
						case 'SELECT' :
							$centerTable->setCenterName($tableDef['data']['center']);
							$newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']);
							break;
						case 'MANUAL' :
							$centerTable->setCenterName('center');
							$clbCenterNode = $newParamNode->addClbManual('center');
							$clbCenterValues = explode(',', $tableDef['data']['center']);
							foreach ($clbCenterValues as $value)
								$clbCenterNode->addClbValue($value);
							break;
					}
					break;
				case 'CENTERWIDTH' :
df380a21   Benjamin Renard   Fix table name de...
603
604
					$centerWidthTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTERWIDTH, $tableName);
					$centerWidthTable->setUnits($tableUnits);
944199fe   Benjamin Renard   Use table definit...
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
					switch ($tableDef['tableDefType'])
					{
						case 'SELECT' :
							$centerWidthTable->setCenterName($tableDef['data']['center']);
							$centerWidthTable->setWidthName($tableDef['data']['width']);
							$newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']);
							$newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['width']);
							break;
						case 'MANUAL' :
							$centerWidthTable->setCenterName('center');
							$centerWidthTable->setWidthName('width');
							$clbCenterNode = $newParamNode->addClbManual('center');
							$clbWidthNode = $newParamNode->addClbManual('width');
							$clbCenterValues = explode(',', $tableDef['data']['center']);
							foreach ($clbCenterValues as $value)
								$clbCenterNode->addClbValue($value);
							$clbWidthValues = explode(',', $tableDef['data']['width']);
							foreach ($clbWidthValues as $value)
								$clbWidthNode->addClbValue($value);
							break;
					}
					break;
			}
		}
		
9b996a31   Benjamin Renard   Split param compo...
630
		return array("id" => $paramId, "indexes" => $indexes, "plotType" => $res["param"]["info"]["plotType"]);
22521f1c   Benjamin Renard   First commit
631
	}
96fa912d   Hacene SI HADJ MOHAND   ihm level instead...
632
633
634
635
636
637
638
639
640
641
642

    public function applyFilter($paramsData, $paramData, &$paramInfo) {
        $filter = (isset($paramData->{'param-drawing-object'}->{'filtering-activated'}) && ($paramData->{'param-drawing-object'}->{'filtering-activated'})) ? true : false;
        if (!$filter) {
            return;
        }
        $my_type = $paramData->{'type'};

        switch ($paramData->{'type'}) {
            case 0:
            case 1:
0f020be7   Hacene SI HADJ MOHAND   adding 2d
643
            case 2:
96fa912d   Hacene SI HADJ MOHAND   ihm level instead...
644
645
646
647
648
649
650
651
                // vector
                $dim1_index = ($dim1_is_range || !isset($paramData->{'dim1-index'}) || ($paramData->{'dim1-index'} == '')) ? '*' : $paramData->{'dim1-index'};
                $dim2_index = ($dim2_is_range || !isset($paramData->{'dim2-index'}) || ($paramData->{'dim2-index'} == '')) ? '*' : $paramData->{'dim2-index'};
                if (isset($paramData->{'param-drawing-object'}->{'filtering-level'})) {
                    switch ($paramData->{'param-drawing-object'}->{'filtering-level'}) {
                        case 1:
                            $factor = 6;
                            $nPoints = 100;
24e7e199   Hacene SI HADJ MOHAND   correcting filter...
652
                            $level = "weak";
96fa912d   Hacene SI HADJ MOHAND   ihm level instead...
653
654
655
656
                            break;
                        case 2:
                            $factor = 5;
                            $nPoints = 100;
24e7e199   Hacene SI HADJ MOHAND   correcting filter...
657
                            $level = "intermediate";
96fa912d   Hacene SI HADJ MOHAND   ihm level instead...
658
659
660
661
                            break;
                        case 3:
                            $factor = 4;
                            $nPoints = 100;
0f020be7   Hacene SI HADJ MOHAND   adding 2d
662
                            $level = "strong";
96fa912d   Hacene SI HADJ MOHAND   ihm level instead...
663
664
665
666
                            break;
                        default:
                            $factor = 6;
                            $nPoints = 100;
0f020be7   Hacene SI HADJ MOHAND   adding 2d
667
                            $level = "low";
96fa912d   Hacene SI HADJ MOHAND   ihm level instead...
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
                    }
                } else {
                    $factor = 5;
                    $nPoints = 100;
                }

                if ($dim1_index != '*') {
                    $template_args = array(
                        'paramid' => $paramInfo['id'],
                        'factor' => $factor,
                        'nPoints' => $nPoints,
                        'index' => $dim1_index,
                        'level' => $level
                    );
                    $paramInfo = $this->addExistingParam('filter_spikes_component', $paramsData, $template_args);
                } else {
                    $template_args = array(
                        'paramid' => $paramInfo['id'],
                        'factor' => $factor,
                        'nPoints' => $nPoints,
0f020be7   Hacene SI HADJ MOHAND   adding 2d
688
                        'level' => $level
96fa912d   Hacene SI HADJ MOHAND   ihm level instead...
689
690
691
692
                    );
                    $paramInfo = $this->addExistingParam('filter_spikes', $paramsData, $template_args);
                }
                break;
96fa912d   Hacene SI HADJ MOHAND   ihm level instead...
693
694
695
        }
    }

93c50989   Benjamin Renard   Support Tab2D par...
696
	public function applyRangesAndIndexes($paramsData, $paramData, $force_total_2d, &$paramInfo) {
db7ea505   Benjamin Renard   Fix min max range...
697
698
699
700
701
		$dim1_min = 0;
		$dim1_max = 0;
		$dim2_min = 0;
		$dim2_max = 0;

76792c0e   Benjamin Renard   Sum parameters un...
702
		$dim1_is_range = (isset($paramData->{'dim1-sum-type'}) && ($paramData->{'dim1-sum-type'} > 0));
2c9760b6   Benjamin Renard   Fix empty index d...
703
		$dim1_index = ($dim1_is_range || !isset($paramData->{'dim1-index'}) || ($paramData->{'dim1-index'} == '')) ? '*' : $paramData->{'dim1-index'};
db7ea505   Benjamin Renard   Fix min max range...
704
705
706
707
708
709
710
711
712
713
714
715
716
717
		if ($dim1_is_range) {
			switch ($paramData->{'dim1-sum-type'}) {
				case 1:
					//Sum between a range of value
					$dim1_min = !empty($paramData->{'dim1-min-value'}) ? $paramData->{'dim1-min-value'} : 0;
					$dim1_max = !empty($paramData->{'dim1-max-value'}) ? $paramData->{'dim1-max-value'} : 0;
					break;
				case 2:
					//Sum between indexes
					$dim1_min = !empty($paramData->{'dim1-min-index'}) ? $paramData->{'dim1-min-index'} : 0;
					$dim1_max = !empty($paramData->{'dim1-max-index'}) ? $paramData->{'dim1-max-index'} : 0;
					break;
			}
		}
93c50989   Benjamin Renard   Support Tab2D par...
718

76792c0e   Benjamin Renard   Sum parameters un...
719
		$dim2_is_range = (isset($paramData->{'dim2-sum-type'}) && ($paramData->{'dim2-sum-type'} > 0));
2c9760b6   Benjamin Renard   Fix empty index d...
720
		$dim2_index = ($dim2_is_range || !isset($paramData->{'dim2-index'}) || ($paramData->{'dim2-index'} == '')) ? '*' : $paramData->{'dim2-index'};
db7ea505   Benjamin Renard   Fix min max range...
721
722
723
724
725
726
727
728
729
730
731
732
733
734
		if ($dim2_is_range) {
			switch ($paramData->{'dim2-sum-type'}) {
				case 1:
					//Sum between a range of value
					$dim2_min = !empty($paramData->{'dim2-min-value'}) ? $paramData->{'dim2-min-value'} : 0;
					$dim2_max = !empty($paramData->{'dim2-max-value'}) ? $paramData->{'dim2-max-value'} : 0;
					break;
				case 2:
					//Sum between indexes
					$dim2_min = !empty($paramData->{'dim2-min-index'}) ? $paramData->{'dim2-min-index'} : 0;
					$dim2_max = !empty($paramData->{'dim2-max-index'}) ? $paramData->{'dim2-max-index'} : 0;
					break;
			}
		}
93c50989   Benjamin Renard   Support Tab2D par...
735
736
737
738
739
740
741
742
743
744
745
746
747
748

		switch ($paramData->{'type'}) {
			case 0:
				//scalar - nothing to do
				break;
			case 1:
				//Tab1D
				if ($dim1_is_range) {
					$template_args = array(
						'paramid' => $paramInfo['id'],
						'min' => $dim1_min,
						'max' => $dim1_max,
						'relateddim' => 0,
					);
76792c0e   Benjamin Renard   Sum parameters un...
749
					if ($paramData->{'dim1-sum-type'} == 2)
54219b37   Benjamin Renard   Add support for s...
750
751
752
						$paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args);
					else
						$paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args);
93c50989   Benjamin Renard   Support Tab2D par...
753
754
755
756
757
758
759
760
				}
				else if ($dim2_is_range) {
					$template_args = array(
						'paramid' => $paramInfo['id'],
						'min' => $dim2_min,
						'max' => $dim2_max,
						'relateddim' => 1,
					);
76792c0e   Benjamin Renard   Sum parameters un...
761
					if ($paramData->{'dim2-sum-type'} == 2)
54219b37   Benjamin Renard   Add support for s...
762
763
764
						$paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args);
					else
						$paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args);
93c50989   Benjamin Renard   Support Tab2D par...
765
766
767
768
769
770
771
772
773
774
775
				}
				else if ($dim1_index != '*') {
					$paramInfo['indexes'][] = $dim1_index;
				}
				else if ($dim2_index != '*') {
					$paramInfo['indexes'][] = $dim2_index;
				}
				break;
			case 2:
				//Tab2D
				if ($dim1_is_range && $dim2_is_range) {
76792c0e   Benjamin Renard   Sum parameters un...
776
					if ($paramData->{'dim1-sum-type'} != $paramData->{'dim2-sum-type'}) {
54219b37   Benjamin Renard   Add support for s...
777
778
						throw new Exception("Not supported - Dimensions ranges for ".$paramInfo['id']." must have the same type for each dimensions");
					}
93c50989   Benjamin Renard   Support Tab2D par...
779
780
781
782
783
784
785
786
					$template_args = array(
						'paramid' => $paramInfo['id'],
						'min1' => $dim1_min,
						'max1' => $dim1_max,
						'relateddim1' => 0,
						'min2' => $dim2_min,
						'max2' => $dim2_max,
					);
76792c0e   Benjamin Renard   Sum parameters un...
787
					if ($paramData->{'dim1-sum-type'} == 2)
54219b37   Benjamin Renard   Add support for s...
788
789
790
						$paramInfo = $this->addExistingParam('sum_into_table_indexes_2d', $paramsData, $template_args);
					else
						$paramInfo = $this->addExistingParam('sum_into_table_range_2d', $paramsData, $template_args);
93c50989   Benjamin Renard   Support Tab2D par...
791
792
793
794
795
796
797
798
				}
				else if ($dim1_is_range) {
					$template_args = array(
						'paramid' => $paramInfo['id'],
						'min' => $dim1_min,
						'max' => $dim1_max,
						'relateddim' => 0,
					);
52859c27   Benjamin Renard   Give the possibil...
799
800
801
802
					$tableLink = array(
						'paramid' => $paramInfo['id'],
						'relateddim' => 1,
					);
76792c0e   Benjamin Renard   Sum parameters un...
803
					if ($paramData->{'dim1-sum-type'} == 2)
54219b37   Benjamin Renard   Add support for s...
804
805
806
						$paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args, $tableLink);
					else
						$paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args, $tableLink);
93c50989   Benjamin Renard   Support Tab2D par...
807
808
809
810
811
812
813
814
815
816
817
					if ($dim2_index != '*') {
						$paramInfo['indexes'][] = $dim2_index;
					}
				}
				else if ($dim2_is_range) {
					$template_args = array(
						'paramid' => $paramInfo['id'],
						'min' => $dim2_min,
						'max' => $dim2_max,
						'relateddim' => 1,
					);
52859c27   Benjamin Renard   Give the possibil...
818
819
820
821
					$tableLink = array(
						'paramid' => $paramInfo['id'],
						'relateddim' => 0,
					);
76792c0e   Benjamin Renard   Sum parameters un...
822
					if ($paramData->{'dim2-sum-type'} == 2)
54219b37   Benjamin Renard   Add support for s...
823
824
825
						$paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args, $tableLink);
					else
						$paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args, $tableLink);
93c50989   Benjamin Renard   Support Tab2D par...
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
					if ($dim1_index != '*') {
						$paramInfo['indexes'][] = $dim1_index;
					}
				}
				else if (($dim1_index != '*') && ($dim2_index != '*')) {
					$paramInfo['indexes'][] = "[".$dim1_index.",".$dim2_index."]";
				}
				else if ($dim1_index != '*') {
					$paramInfo['indexes'][] = "[".$dim1_index.",*]";
				}
				else if ($dim2_index != '*') {
					$paramInfo['indexes'][] = "[*,".$dim2_index."]";
				}
				else if ($force_total_2d) {
					//total over 2 dims
					$template_args = array(
						'paramid' => $paramInfo['id'],
					);
					$paramInfo = $this->addExistingParam('total_2D', $paramsData, $template_args);
				}
				break;
		}
	}
a928f9d3   Benjamin Renard   New parser integr...
849
850

	public function parseExpression($expression, $workingDir) {
f03c62e3   Benjamin Renard   Keep in cache res...
851
852
853
854
		$outputFileName = "parser_".md5($expression).".xml";
		if (array_key_exists($outputFileName, $this->cacheExpressionParser)) {
			return $this->cacheExpressionParser[$outputFileName];
		}
a928f9d3   Benjamin Renard   New parser integr...
855
856
857
858
859
860
861
		$parserData = new ParserRequestDataClass();
		$parserData->setManagerFilePath(IHMConfigClass::getProcessManagerFilePath());
		$parserData->addExpression($expression);
		$parserData->setWorkingPath($workingDir);
		$parserData->setLocalParamsPath(IHMConfigClass::getLocalParamDBPath());
		$parserData->setConstantsFilePath(IHMConfigClass::getConstantsFilePath());
		$parserData->setFunctionsFilePath(IHMConfigClass::getFunctionsFilePath());
65912bc8   Benjamin Renard   Templated paramet...
862
		$parserData->setParamTemplatesFilePath(IHMConfigClass::getParamTemplateListFilePath());
8cf39be4   Benjamin Renard   Add functions arg...
863
		$parserData->setFunctionsArgsListFilePath(IHMConfigClass::getFunctionsArgsListFilePath());
f03c62e3   Benjamin Renard   Keep in cache res...
864
		$parserData->setOutputFileName($outputFileName);
a928f9d3   Benjamin Renard   New parser integr...
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
		$resultFilePath = $workingDir."/".$outputFileName;

		$parserRequest = new ParserRequestClass();
		$parserRequest->setData($parserData);

		if (!$parserRequest->init() || !$parserRequest->run()) {
			if (file_exists($resultFilePath)) {
				unlink($resultFilePath);
			}
			return array('success' => FALSE, 'message' => 'Error to init or run expression parser');
		}

		//Load result file
		$doc = new DOMDocument();
		$doc->load($resultFilePath);
		if (!$doc->load($resultFilePath)) {
			if (file_exists($resultFilePath)) {
				unlink($resultFilePath);
			}
			return array('success' => FALSE, 'message' => 'Error to load parser result file');
		}

		$expressionNodes = $doc->getElementsByTagName('expression');
		if ($expressionNodes->length == 0) {
			unlink($resultFilePath);
			return array('success' => FALSE, 'message' => 'Cannot get expression nodes in parser result file');
		}

		$crtExpressionNode = NULL;
		foreach ($expressionNodes as $expressionNode) {
			$ihmExpressionNodes = $expressionNode->getElementsByTagName('ihm');
			if ($ihmExpressionNodes->length == 0) {
				continue;
			}
			if ($ihmExpressionNodes->item(0)->nodeValue == $expression) {
				$crtExpressionNode = $expressionNode;
				break;
			}
		}
		
		if (!isset($crtExpressionNode)) {
			unlink($resultFilePath);
			return array('success' => FALSE, 'message' => 'Cannot retrieve expression in parser result file');
		}

		if ($crtExpressionNode->getAttribute('success') != "true") {
			unlink($resultFilePath);
8b185bf5   Benjamin Renard   Minor fix
912
			return array('success' => FALSE, 'message' => 'Syntax error in expression '.$expression);
a928f9d3   Benjamin Renard   New parser integr...
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
		}

		$kernelExpressionNodes = $crtExpressionNode->getElementsByTagName('kernel');
		if ($kernelExpressionNodes->length == 0) {
			unlink($resultFilePath);
			return array('success' => FALSE, 'message' => 'Cannot retrieve kernel expression in parser result file');
		}

		$kernelExpression = $kernelExpressionNodes->item(0)->nodeValue;

		if (empty($kernelExpression)) {
			unlink($resultFilePath);
			return array('success' => FALSE, 'message' => 'Parser return an empty expression');
		}

		$params = array();
		$paramsNodes = $crtExpressionNode->getElementsByTagName('params');
		if ($paramsNodes->length != 0) {
			$paramNodes = $paramsNodes->item(0)->getElementsByTagName('param');
			if ($paramNodes->length != 0) {
				foreach ($paramNodes as $paramNode) {
					if (!empty($paramNode->nodeValue)) {
						$params[] = array(
							'paramid' => $paramNode->nodeValue
						);
					}
				}
			}
		}

		unlink($resultFilePath);
		
		if (empty($params)) {
			return array('success' => FALSE, 'message' => 'Expression should contain at least one parameter');
		}

7fc2b4b7   Benjamin Renard   Fix templated par...
949
950
951
952
953
954
955
		foreach ($params as &$param) {
			$templated_param = $this->templateParamsManager->parseTemplatedParam($param['paramid']);
			if ($templated_param !== FALSE) {
				$param = $templated_param;
			}
		}

f03c62e3   Benjamin Renard   Keep in cache res...
956
957
		$this->cacheExpressionParser[$outputFileName] = array('success' => TRUE, 'expression' => $kernelExpression, 'params' => $params);
		return $this->cacheExpressionParser[$outputFileName];
a928f9d3   Benjamin Renard   New parser integr...
958
	}
c3e6d894   Benjamin Renard   Init IHMParamTemp...
959
960
961
962

	public function getTemplateParamsManager() {
		return $this->templateParamsManager;
	}
22521f1c   Benjamin Renard   First commit
963
}