Commit 52859c2724cd9367d8ab8606eeaf699592f3f42e

Authored by Benjamin Renard
1 parent 2c9760b6

Give the possibility to define a table link (used by #6103)

src/InputOutput/IHMImpl/Tools/IHMParamManagerClass.php
@@ -23,7 +23,7 @@ class IHMParamManagerClass @@ -23,7 +23,7 @@ class IHMParamManagerClass
23 /* 23 /*
24 * @brief Add an existing parameter 24 * @brief Add an existing parameter
25 */ 25 */
26 - public function addExistingParam($param, $paramsData, $templateArgs = NULL) 26 + public function addExistingParam($param, $paramsData, $templateArgs = NULL, $tableLink = NULL)
27 { 27 {
28 if ($this->isDerivedParam($param)) 28 if ($this->isDerivedParam($param))
29 return $this->addDerivedParam($param,$paramsData); 29 return $this->addDerivedParam($param,$paramsData);
@@ -32,7 +32,7 @@ class IHMParamManagerClass @@ -32,7 +32,7 @@ class IHMParamManagerClass
32 else if ($this->isImpexParam($param)) 32 else if ($this->isImpexParam($param))
33 return $this->addImpexParam($param,$paramsData,$templateArgs); 33 return $this->addImpexParam($param,$paramsData,$templateArgs);
34 else 34 else
35 - return $this->addLocalParam($param,$paramsData,$templateArgs); 35 + return $this->addLocalParam($param,$paramsData,$templateArgs, $tableLink);
36 return ""; 36 return "";
37 } 37 }
38 38
@@ -82,7 +82,7 @@ class IHMParamManagerClass @@ -82,7 +82,7 @@ class IHMParamManagerClass
82 /* 82 /*
83 * @brief Add a local parameter 83 * @brief Add a local parameter
84 */ 84 */
85 - private function addLocalParam($param, $paramsData, $templateArgs) 85 + private function addLocalParam($param, $paramsData, $templateArgs, $tableLink)
86 { 86 {
87 //local parameter 87 //local parameter
88 $indexes = array(); 88 $indexes = array();
@@ -101,9 +101,8 @@ class IHMParamManagerClass @@ -101,9 +101,8 @@ class IHMParamManagerClass
101 //check templated parameter 101 //check templated parameter
102 $real_param_id = $paramId; 102 $real_param_id = $paramId;
103 if ($this->templateParamsManager->isTemplatedParam($paramId)) { 103 if ($this->templateParamsManager->isTemplatedParam($paramId)) {
104 - $paramPath = $this->templateParamsManager->generateTemplatedParamFile($paramId, $templateArgs); 104 + $paramPath = $this->templateParamsManager->generateTemplatedParamFile($paramId, $templateArgs, $tableLink);
105 $real_param_id = $this->templateParamsManager->getTemplatedParamId($paramId, $templateArgs); 105 $real_param_id = $this->templateParamsManager->getTemplatedParamId($paramId, $templateArgs);
106 -  
107 if (empty($paramPath) || !file_exists($paramPath)) 106 if (empty($paramPath) || !file_exists($paramPath))
108 throw new Exception('Cannot generate parameter template file '.$paramId); 107 throw new Exception('Cannot generate parameter template file '.$paramId);
109 } 108 }
@@ -485,7 +484,11 @@ class IHMParamManagerClass @@ -485,7 +484,11 @@ class IHMParamManagerClass
485 'max' => $dim1_max, 484 'max' => $dim1_max,
486 'relateddim' => 0, 485 'relateddim' => 0,
487 ); 486 );
488 - $paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args); 487 + $tableLink = array(
  488 + 'paramid' => $paramInfo['id'],
  489 + 'relateddim' => 1,
  490 + );
  491 + $paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args, $tableLink);
489 if ($dim2_index != '*') { 492 if ($dim2_index != '*') {
490 $paramInfo['indexes'][] = $dim2_index; 493 $paramInfo['indexes'][] = $dim2_index;
491 } 494 }
@@ -497,7 +500,11 @@ class IHMParamManagerClass @@ -497,7 +500,11 @@ class IHMParamManagerClass
497 'max' => $dim2_max, 500 'max' => $dim2_max,
498 'relateddim' => 1, 501 'relateddim' => 1,
499 ); 502 );
500 - $paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args); 503 + $tableLink = array(
  504 + 'paramid' => $paramInfo['id'],
  505 + 'relateddim' => 0,
  506 + );
  507 + $paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args, $tableLink);
501 if ($dim1_index != '*') { 508 if ($dim1_index != '*') {
502 $paramInfo['indexes'][] = $dim1_index; 509 $paramInfo['indexes'][] = $dim1_index;
503 } 510 }
src/InputOutput/IHMImpl/Tools/IHMParamTemplateClass.php
@@ -138,7 +138,7 @@ class IHMParamTemplateClass @@ -138,7 +138,7 @@ class IHMParamTemplateClass
138 /* 138 /*
139 * @brief Generate parameter file from template 139 * @brief Generate parameter file from template
140 */ 140 */
141 - public function generateTemplatedParamFile($param_id, $template_args) { 141 + public function generateTemplatedParamFile($param_id, $template_args, $table_link = NULL) {
142 $templatePath = $this->getTemplatePath($param_id); 142 $templatePath = $this->getTemplatePath($param_id);
143 if (empty($templatePath)) 143 if (empty($templatePath))
144 return ""; 144 return "";
@@ -177,6 +177,38 @@ class IHMParamTemplateClass @@ -177,6 +177,38 @@ class IHMParamTemplateClass
177 } 177 }
178 fclose($templateHandle); 178 fclose($templateHandle);
179 fclose($dstHandle); 179 fclose($dstHandle);
  180 +
  181 + if (isset($table_link)) {
  182 + //Inject table link
  183 + $xml = new DOMDocument();
  184 + $xml->preserveWhiteSpace = TRUE;
  185 + $xml->load($dstFilePath);
  186 +
  187 + $infoNodes = $xml->documentElement->getElementsByTagName('info');
  188 + if ($infoNodes->length == 0) {
  189 + $infoNode = $xml->createElement('info');
  190 + $infoNode = $xml->documentElement->insertBefore($infoNode, $xml->documentElement->firstChild);
  191 + }
  192 + else {
  193 + $infoNode = $infoNodes->item(0);
  194 + }
  195 +
  196 + $tableNodes = $infoNode->getElementsByTagName('table');
  197 + if ($tableNodes->length == 0) {
  198 + $tableNode = $xml->createElement('table');
  199 + $tableNode = $infoNode->appendChild($tableNode);
  200 + }
  201 + else {
  202 + $tableNode = $tableNodes->item(0);
  203 + }
  204 +
  205 + $linkTableNode = $xml->createElement('linkTable');
  206 + $linkTableNode->setAttribute('originParamId', $table_link['paramid']);
  207 + $linkTableNode->setAttribute('originTableDim', $table_link['relateddim']);
  208 + $tableNode->appendChild($linkTableNode);
  209 +
  210 + $xml->save($dstFilePath);
  211 + }
180 212
181 $dateModifTemplate = filemtime($templatePath); 213 $dateModifTemplate = filemtime($templatePath);
182 touch($dstFilePath, $dateModifTemplate); 214 touch($dstFilePath, $dateModifTemplate);