Commit 9ced131cd3a642d159c5a6309fac0ff6920105d5
1 parent
14008bfe
Exists in
alias
request with aliases processing
Showing
3 changed files
with
55 additions
and
36 deletions
Show diff stats
php/classes/AliasMgr.php
@@ -61,10 +61,31 @@ class AliasMgr extends AmdaObjectMgr { | @@ -61,10 +61,31 @@ class AliasMgr extends AmdaObjectMgr { | ||
61 | /***************************************************************** | 61 | /***************************************************************** |
62 | * PUBLIC FUNCTIONS | 62 | * PUBLIC FUNCTIONS |
63 | *****************************************************************/ | 63 | *****************************************************************/ |
64 | - | 64 | + |
65 | + public function getAliasArraySorted($byParamLength) { | ||
66 | + $AliasList = $this->contentDom->getElementsByTagName('alias'); | ||
67 | + $AliasArray = array(); | ||
68 | + | ||
69 | + foreach ($AliasList as $alias) { | ||
70 | + $AliasArray[$alias->getAttribute('xml:id')] = $alias->getAttribute('name'); | ||
71 | + } | ||
72 | + | ||
73 | + if ($byParamLength) { // sort array by parameter length | ||
74 | + $keys = array_map('strlen', array_keys($AliasArray)); | ||
75 | + array_multisort($keys, SORT_DESC, $AliasArray); | ||
76 | + } | ||
77 | + else { // sort array by alias length | ||
78 | + $keys = array_map('strlen',$AliasArray); | ||
79 | + array_multisort($keys,SORT_DESC,$AliasArray); | ||
80 | + } | ||
81 | + | ||
82 | + return $AliasArray; | ||
83 | + } | ||
84 | + | ||
85 | + | ||
65 | public function getList() { | 86 | public function getList() { |
66 | $AliasList = $this->contentDom->getElementsByTagName('alias'); | 87 | $AliasList = $this->contentDom->getElementsByTagName('alias'); |
67 | - | 88 | + |
68 | return $AliasList; | 89 | return $AliasList; |
69 | } | 90 | } |
70 | 91 | ||
@@ -72,10 +93,12 @@ class AliasMgr extends AmdaObjectMgr { | @@ -72,10 +93,12 @@ class AliasMgr extends AmdaObjectMgr { | ||
72 | 93 | ||
73 | $aliasName="#".$aliasName; | 94 | $aliasName="#".$aliasName; |
74 | $pos = strpos($chain, $paramName); | 95 | $pos = strpos($chain, $paramName); |
96 | + | ||
75 | while ( $pos !== FALSE ) { | 97 | while ( $pos !== FALSE ) { |
76 | $pos = $pos+strlen($paramName); | 98 | $pos = $pos+strlen($paramName); |
77 | if (preg_match('/[-+*,^<>&|=\/\[\]\(\)\ ]/', $chain[$pos]) || $chain[$pos] === '') { | 99 | if (preg_match('/[-+*,^<>&|=\/\[\]\(\)\ ]/', $chain[$pos]) || $chain[$pos] === '') { |
78 | $chain = substr_replace($chain, $aliasName,$pos-strlen($paramName),strlen($paramName)); | 100 | $chain = substr_replace($chain, $aliasName,$pos-strlen($paramName),strlen($paramName)); |
101 | + $pos = $pos-strlen($paramName)+strlen($aliasName); | ||
79 | } | 102 | } |
80 | $pos = strpos($chain, $paramName, $pos); | 103 | $pos = strpos($chain, $paramName, $pos); |
81 | } | 104 | } |
@@ -90,6 +113,7 @@ class AliasMgr extends AmdaObjectMgr { | @@ -90,6 +113,7 @@ class AliasMgr extends AmdaObjectMgr { | ||
90 | $pos = $pos+strlen($aliasName); | 113 | $pos = $pos+strlen($aliasName); |
91 | if (preg_match('/[-+*,^<>&|=\/\[\]\(\)\ ]/', $chain[$pos]) || $chain[$pos] === '') { | 114 | if (preg_match('/[-+*,^<>&|=\/\[\]\(\)\ ]/', $chain[$pos]) || $chain[$pos] === '') { |
92 | $chain = substr_replace($chain, $paramName,$pos-strlen($aliasName),strlen($aliasName)); | 115 | $chain = substr_replace($chain, $paramName,$pos-strlen($aliasName),strlen($aliasName)); |
116 | + $pos = $pos-strlen($aliasName)+strlen($paramName); | ||
93 | } | 117 | } |
94 | $pos = strpos($chain, $aliasName, $pos); | 118 | $pos = strpos($chain, $aliasName, $pos); |
95 | } | 119 | } |
php/classes/AmdaObjectMgr.php
@@ -223,23 +223,24 @@ class AmdaObjectMgr | @@ -223,23 +223,24 @@ class AmdaObjectMgr | ||
223 | protected function setAlias($chain) | 223 | protected function setAlias($chain) |
224 | { | 224 | { |
225 | $aliasMgr = new AliasMgr(); | 225 | $aliasMgr = new AliasMgr(); |
226 | - $listeAlias = $aliasMgr->getList(); | ||
227 | - | ||
228 | - foreach($listeAlias as $alias) | 226 | + $aliasArray = $aliasMgr->getAliasArraySorted(true); |
227 | + | ||
228 | + foreach($aliasArray as $key => $value) | ||
229 | { | 229 | { |
230 | - $chain = $aliasMgr->substrParamAlias($chain, $alias->getAttribute("xml:id"),$alias->getAttribute("name")); | 230 | + $chain = $aliasMgr->substrParamAlias($chain, $key,$value); |
231 | } | 231 | } |
232 | + | ||
232 | return $chain; | 233 | return $chain; |
233 | } | 234 | } |
234 | 235 | ||
235 | protected function resetAlias($chain) | 236 | protected function resetAlias($chain) |
236 | { | 237 | { |
237 | $aliasMgr = new AliasMgr(); | 238 | $aliasMgr = new AliasMgr(); |
238 | - $listeAlias = $aliasMgr->getList(); | 239 | + $aliasArray = $aliasMgr->getAliasArraySorted(false); |
239 | 240 | ||
240 | - foreach($listeAlias as $alias) | 241 | + foreach($aliasArray as $key => $value) |
241 | { | 242 | { |
242 | - $chain = $aliasMgr->substrAliasParam($chain, $alias->getAttribute("xml:id"),$alias->getAttribute("name")); | 243 | + $chain = $aliasMgr->substrAliasParam($chain, $key, $value); |
243 | } | 244 | } |
244 | return $chain; | 245 | return $chain; |
245 | } | 246 | } |
php/classes/RequestMgr.php
@@ -102,23 +102,29 @@ class RequestMgr extends AmdaObjectMgr | @@ -102,23 +102,29 @@ class RequestMgr extends AmdaObjectMgr | ||
102 | if (!($objToGet = $this->contentDom->getElementById($id))) return array('error' => NO_SUCH_ID); | 102 | if (!($objToGet = $this->contentDom->getElementById($id))) return array('error' => NO_SUCH_ID); |
103 | 103 | ||
104 | $obj = json_decode(file_get_contents(USERREQDIR.$id)); | 104 | $obj = json_decode(file_get_contents(USERREQDIR.$id)); |
105 | + | ||
105 | //if alias exists, replace parameter name by alias name | 106 | //if alias exists, replace parameter name by alias name |
106 | - if (file_exists(USERWSDIR.'Alias.xml')) | ||
107 | - { | ||
108 | - if ($this->type == 'condition') | ||
109 | - { | ||
110 | - $obj->expression =$this->setAlias($obj->expression); | 107 | + if (file_exists(USERWSDIR.'Alias.xml')) { |
108 | + if ($this->type == 'condition') { | ||
109 | + $obj->expression = $this->setAlias($obj->expression); | ||
111 | } | 110 | } |
112 | - else if ($this->type == 'request') | ||
113 | - { | ||
114 | - for ($i=0; $i < count($obj->children); $i++) { | ||
115 | - for ($j=0; $j < count($obj->children[$i]->children); $j++) { | ||
116 | - $obj->children[$i]->children[$j]->name = $this->setAlias($obj->children[$i]->children[$j]->name); | 111 | + else if ($this->type == 'request') { |
112 | + $tabs = $obj->tabs; | ||
113 | + foreach ($tabs as $tab) { // tabs | ||
114 | + $panels = $tab->panels; | ||
115 | + foreach ($panels as $panel) { // panels | ||
116 | + $params = $panel->params; | ||
117 | + foreach ($params as $param) { // params | ||
118 | + $alias = $this->setAlias($param->paramid); | ||
119 | + if ($alias != $param->paramid) { | ||
120 | + $param->{'real-paramid'} = $param->paramid; | ||
121 | + $param->{'real-type'} = $param->type; | ||
122 | + $param->paramid = $alias; | ||
123 | + } | ||
124 | + } | ||
117 | } | 125 | } |
118 | } | 126 | } |
119 | - //TODO Ajout des SCATTER | ||
120 | - // if $obj->children[$i]->plotType == "SCATTER" | ||
121 | - //$obj->children[$i]->scatterParam->data->name pour 1 panel (bug si 2 panels devient $obj->children[$i]->scatterParam->data->data->name) | 127 | + //TODO add SCATTER |
122 | } | 128 | } |
123 | } | 129 | } |
124 | //if Start Time - Stop Time | 130 | //if Start Time - Stop Time |
@@ -161,21 +167,9 @@ class RequestMgr extends AmdaObjectMgr | @@ -161,21 +167,9 @@ class RequestMgr extends AmdaObjectMgr | ||
161 | { | 167 | { |
162 | if ($this->type == 'condition') | 168 | if ($this->type == 'condition') |
163 | { | 169 | { |
164 | - $p->expression = $this->resetAlias($p->expression); | 170 | + $p->expression = $this->resetAlias(trim($p->expression)); |
165 | $info = $p->expression; | 171 | $info = $p->expression; |
166 | } | 172 | } |
167 | - else if ($this->type == 'request') | ||
168 | - { | ||
169 | - $info = ''; | ||
170 | - for ($i=0; $i < count($p->children); $i++) | ||
171 | - { | ||
172 | - for ($j=0; $j < count($p->children[$i]->children); $j++) | ||
173 | - { | ||
174 | - $p->children[$i]->children[$j]->name = $this->resetAlias($p->children[$i]->children[$j]->name); | ||
175 | - $info = $info.' '.$p->children[$i]->children[$j]->name; | ||
176 | - } | ||
177 | - } | ||
178 | - } | ||
179 | } | 173 | } |
180 | 174 | ||
181 | $this->descFileName = USERREQDIR.$this->id; | 175 | $this->descFileName = USERREQDIR.$this->id; |
@@ -192,7 +186,7 @@ class RequestMgr extends AmdaObjectMgr | @@ -192,7 +186,7 @@ class RequestMgr extends AmdaObjectMgr | ||
192 | 186 | ||
193 | public static function checkRequest($obj) | 187 | public static function checkRequest($obj) |
194 | { | 188 | { |
195 | - if (!file_exists(orbitsAllXml)) return array('success' => false, 'message' => 'no orbits descriotion file'); | 189 | + if (!file_exists(orbitsAllXml)) return array('success' => false, 'message' => 'no orbits description file'); |
196 | 190 | ||
197 | //check for orbit templateArgs | 191 | //check for orbit templateArgs |
198 | $args = array(); | 192 | $args = array(); |