Commit 6207ec142c12b5f0ade271a982bb087dea40f4e1
1 parent
4078a635
Exists in
master
and in
111 other branches
#5919 non standard formats for TT upload
Showing
1 changed file
with
27 additions
and
27 deletions
Show diff stats
php/classes/TimeTableMgr.php
... | ... | @@ -114,16 +114,6 @@ class TimeTableMgr extends AmdaObjectMgr |
114 | 114 | if ($key == 'created') { |
115 | 115 | $rootElement->appendChild($this->objectDom->createElement($key, $this->created)); |
116 | 116 | } |
117 | - /*else if ($key == 'intervals') { | |
118 | - $n_int = 0; | |
119 | - foreach ($value as $item) { | |
120 | - $newInterval = $this->objectDom->createElement('intervals'); | |
121 | - $newInterval->appendChild($this->objectDom->createElement('start', $item->start)); | |
122 | - $newInterval->appendChild($this->objectDom->createElement('stop', $item->stop)); | |
123 | - $rootElement->appendChild($newInterval); | |
124 | - $n_int++; | |
125 | - } | |
126 | - }*/ | |
127 | 117 | // it is catalog |
128 | 118 | else if ($key == 'parameters') { |
129 | 119 | $paramsElement = $this->setParamDescription($value); |
... | ... | @@ -161,28 +151,39 @@ class TimeTableMgr extends AmdaObjectMgr |
161 | 151 | $lines = file($tmp_file,FILE_SKIP_EMPTY_LINES); |
162 | 152 | $description="Uploaded Time Table".PHP_EOL; |
163 | 153 | |
164 | - foreach ($lines as $line){ | |
165 | - if ($line[0] == '#') $description=$description.PHP_EOL.substr($line,1,-1); | |
154 | + foreach ($lines as $line) | |
155 | + { | |
156 | + if ($line[0] == '#') { | |
157 | + $description=$description.PHP_EOL.substr($line,1,-1); | |
158 | + } | |
166 | 159 | else { |
167 | - $date = explode(' ', preg_replace('!\s+!', ' ', $line)); | |
160 | + $date = explode(' ', trim(preg_replace('!\s+!', ' ',$line))); | |
161 | + | |
168 | 162 | if (!strtotime(trim($date[0]))) { |
169 | 163 | $description=$description.PHP_EOL.$line; |
170 | 164 | continue; |
171 | 165 | } |
172 | 166 | // check if it is ISO format |
173 | - if (!isset($isIso)) $isIso = preg_match('/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})$/', trim($date[0])); | |
167 | + if (!isset($isIso)) | |
168 | + $isIso = preg_match('/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})$/', trim($date[0])); | |
169 | + | |
174 | 170 | if (!$isIso) { |
175 | - if (count($date) == 2) { | |
176 | - $tempStartT = strtotime(trim($date[0])); | |
177 | - $tempStopT = strtotime(trim($date[1])); | |
178 | - } | |
179 | - else { // y-m-d h:m:s for example | |
180 | - $tempStartT = strtotime($date[0]." ".$date[1]); | |
181 | - $tempStopT = strtotime($date[2]." ".$date[3]); | |
182 | - } | |
171 | + // y-m-d h:m:s for example | |
172 | + $dateLength = count($date) / 2; | |
173 | + | |
174 | + $tempStart = $date[0]; | |
175 | + $tempStop = $date[$dateLength]; | |
183 | 176 | |
184 | - $startDate = date('Y-m-d\TH:i:s',$tempStartT); | |
185 | - $stopDate = date('Y-m-d\TH:i:s',$tempStopT); | |
177 | + if ($dateLength > 1) { | |
178 | + for ($i = 1; $i < $dateLength; $i++) | |
179 | + $tempStart.= $date[$i]; | |
180 | + | |
181 | + for ($i = $dateLength + 1; $i < $dateLength * 2; $i++) | |
182 | + $tempStop .= $date[$i]; | |
183 | + } | |
184 | + | |
185 | + $startDate = date('Y-m-d\TH:i:s',strtotime($tempStart)); | |
186 | + $stopDate = date('Y-m-d\TH:i:s',strtotime($tempStop)); | |
186 | 187 | |
187 | 188 | if (!$onlyDescription) |
188 | 189 | $attributesToReturn['intervals'][] = array('start' => $startDate, 'stop' => $stopDate); |
... | ... | @@ -193,15 +194,14 @@ class TimeTableMgr extends AmdaObjectMgr |
193 | 194 | } |
194 | 195 | } |
195 | 196 | } |
196 | - | |
197 | + | |
197 | 198 | $attributesToReturn['description'] = $description; |
198 | 199 | $attributesToReturn['name'] = basename($tmp_file, '.'.$suffix[1]); |
199 | 200 | $attributesToReturn['created'] = date('Y-m-d\TH:i:s'); |
200 | 201 | |
201 | 202 | return $attributesToReturn; |
202 | 203 | } |
203 | - | |
204 | - | |
204 | + | |
205 | 205 | /* |
206 | 206 | * Uploaded vot TT => convert to array |
207 | 207 | */ |
... | ... |