Commit 307aa386a9b97043425a971806003df796c783e9

Authored by Benjamin Renard
1 parent 10a74d7d

Split plot requests

Showing 1 changed file with 45 additions and 2 deletions   Show diff stats
src/InputOutput/IHMImpl/Tools/IHMUserWSManagerClass.php
... ... @@ -56,6 +56,8 @@ class IHMUserWSManagerClass
56 56 if (empty($this->wsInfo)) {
57 57 return FALSE;
58 58 }
  59 + $this->wsInfo["version"] = 0;// DEBUG - To Remove!!!
  60 +
59 61 return TRUE;
60 62 }
61 63  
... ... @@ -115,6 +117,7 @@ class IHMUserWSManagerClass
115 117 }
116 118  
117 119 // Split requests
  120 + $split_plot = array();
118 121 foreach ($plot_requests as $id => $node) {
119 122 $req_data_path = IHMConfigClass::getStoredRequestPath() . $id;
120 123 if (!file_exists($req_data_path)) {
... ... @@ -124,14 +127,54 @@ class IHMUserWSManagerClass
124 127 if (!$req_data_content) {
125 128 continue;
126 129 }
127   - $req_data_json = json_decode($req_data_content);
  130 + $req_data_json = json_decode($req_data_content,TRUE);
128 131 if (!$req_data_json) {
129 132 continue;
130 133 }
131   - // ToDo
  134 + if (array_key_exists("tabs", $req_data_json)) {
  135 + $split_plot[$id] = array();
  136 + $tab_index = 1;
  137 + foreach ($req_data_json["tabs"] as $tab) {
  138 + $new_splitted_request = array_merge(array(), $tab);
  139 + foreach (array_keys($req_data_json) as $key) {
  140 + if (in_array($key, array('tabs', 'startDate', 'stopDate'))) {
  141 + continue;
  142 + }
  143 + $new_splitted_request[$key] = $req_data_json[$key];
  144 + }
  145 + if (count($req_data_json["tabs"]) > 1) {
  146 + if (!empty($new_splitted_request['tab-name'])) {
  147 + $new_splitted_request['name'] .= ('_' . $new_splitted_request['tab-name']);
  148 + }
  149 + else {
  150 + $new_splitted_request['name'] .= ('_Plot' . $tab_index);
  151 + }
  152 + }
  153 + foreach (array("tab-name", "last-plotted-tab", "active-tab-id", "last-tab-id", "multi-plot-linked") as $key) {
  154 + unset($new_splitted_request[$key]);
  155 + }
  156 + ++$last_id;
  157 + $new_splitted_request['id'] = "req_".$last_id;
  158 + file_put_contents(IHMConfigClass::getStoredRequestPath() . $new_splitted_request['id'], json_encode($new_splitted_request));
  159 + $split_plot[$id][$new_splitted_request['id']] = $new_splitted_request['name'];
  160 + ++$tab_index;
  161 + }
  162 + }
132 163 }
133 164  
  165 + //Apply split in user requests file
  166 + foreach ($split_plot as $old_key => $split) {
  167 + $parentNode = $plot_requests[$old_key]->parentNode;
  168 + $parentNode->removeChild($plot_requests[$old_key]);
  169 + foreach ($split as $new_key => $new_name) {
  170 + $new_node = $dom->createElement("request");
  171 + $new_node->setAttribute("xml:id", $new_key);
  172 + $new_node->setAttribute("name", $new_name);
  173 + $parentNode->appendChild($new_node);
  174 + }
  175 + }
134 176  
  177 + $dom->save($req_mgr_file_path);
135 178 return TRUE;
136 179 }
137 180 }
... ...