Commit 4a438b99da5ded006edce23c875f4dcbc1004e81

Authored by elena
1 parent e82af71b

catalog draft

php/classes/CatalogCacheMgr.php
@@ -10,7 +10,8 @@ class CatIntervalCacheObject extends IntervalCacheObject @@ -10,7 +10,8 @@ class CatIntervalCacheObject extends IntervalCacheObject
10 // for catalog 10 // for catalog
11 private $params = array(); 11 private $params = array();
12 12
13 - public function toArray() { 13 + public function toArray()
  14 + {
14 $result = array( 15 $result = array(
15 "cacheId" => $this->id, 16 "cacheId" => $this->id,
16 "start" => $this->getStartToISO(), 17 "start" => $this->getStartToISO(),
@@ -30,26 +31,28 @@ class CatIntervalCacheObject extends IntervalCacheObject @@ -30,26 +31,28 @@ class CatIntervalCacheObject extends IntervalCacheObject
30 } 31 }
31 32
32 // for catalog 33 // for catalog
33 - public function setParams($params) {  
34 - $this->params = $params;  
35 - 34 + public function setParams($params)
  35 + {
  36 + $this->params = $params;
36 } 37 }
37 38
38 - public function getParams() { 39 + public function getParams()
  40 + {
39 return $this->params; 41 return $this->params;
40 } 42 }
41 43
42 - public function writeBin($handle, $paramsNumber, $paramsSizes) { 44 + public function writeBin($handle, $paramsNumber, $paramsSizes)
  45 + {
43 fwrite($handle,pack('L6',$this->id,$this->index,$this->start,$this->stop,$this->isNew,$this->isModified)); 46 fwrite($handle,pack('L6',$this->id,$this->index,$this->start,$this->stop,$this->isNew,$this->isModified));
44 for ($i = 0; $i < $paramsNumber; $i++) { 47 for ($i = 0; $i < $paramsNumber; $i++) {
45 $paramString = $this->params[$i]; 48 $paramString = $this->params[$i];
46 $paramArray = explode(',',$this->params[$i]); 49 $paramArray = explode(',',$this->params[$i]);
47 for ($j = 0; $j < $paramsSizes[$i]; $j++) fwrite($handle,pack('d', $paramArray[$j])); 50 for ($j = 0; $j < $paramsSizes[$i]; $j++) fwrite($handle,pack('d', $paramArray[$j]));
48 - }  
49 - 51 + }
50 } 52 }
51 53
52 - public function loadBin($handle, $paramsNumber, $paramsSizes) { 54 + public function loadBin($handle, $paramsNumber, $paramsSizes)
  55 + {
53 $array = unpack('L6int',fread($handle,6*4)); 56 $array = unpack('L6int',fread($handle,6*4));
54 $this->id = $array['int1']; 57 $this->id = $array['int1'];
55 $this->index = $array['int2']; 58 $this->index = $array['int2'];
@@ -69,7 +72,8 @@ class CatIntervalCacheObject extends IntervalCacheObject @@ -69,7 +72,8 @@ class CatIntervalCacheObject extends IntervalCacheObject
69 72
70 } 73 }
71 74
72 - public function dump() { 75 + public function dump()
  76 + {
73 echo " => Interval : id = ".$this->id.", index = ".$this->index.", start = ".$this->start.", stop = ".$this->stop.", isNew = ".$this->isNew.", isModified = ".$this->isModified.PHP_EOL; 77 echo " => Interval : id = ".$this->id.", index = ".$this->index.", start = ".$this->start.", stop = ".$this->stop.", isNew = ".$this->isNew.", isModified = ".$this->isModified.PHP_EOL;
74 } 78 }
75 } 79 }
@@ -79,36 +83,40 @@ class CatalogCacheObject extends TimeTableCacheObject @@ -79,36 +83,40 @@ class CatalogCacheObject extends TimeTableCacheObject
79 private $paramsNumber; 83 private $paramsNumber;
80 private $paramsSizes = array(); 84 private $paramsSizes = array();
81 85
82 - public function addInterval($startIso, $stopIso, $params, $isNew = false, $index = -1) {  
83 - $interval = new CatIntervalCacheObject($this->lastId, count($this->intervals));  
84 - ++$this->lastId;  
85 - $interval->setStartFromISO($startIso);  
86 - $interval->setStopFromISO($stopIso);  
87 - // for catalog  
88 - $interval->setParams($params); 86 + public function addInterval($startIso, $stopIso, $params, $isNew = false, $index = -1)
  87 + {
  88 + $interval = new CatIntervalCacheObject($this->lastId, count($this->intervals));
  89 + ++$this->lastId;
  90 + $interval->setStartFromISO($startIso);
  91 + $interval->setStopFromISO($stopIso);
  92 + // for catalog
  93 + $interval->setParams($params);
89 94
90 - $interval->setIsNew($isNew);  
91 - array_push($this->intervals, $interval);  
92 - if ($index < 0)  
93 - array_push($this->indexes, count($this->intervals) - 1);  
94 - else  
95 - array_splice($this->indexes, $index, 0, array(count($this->intervals) - 1));  
96 - if ($isNew)  
97 - $this->isModified = true;  
98 -  
99 - return $interval; 95 + $interval->setIsNew($isNew);
  96 + array_push($this->intervals, $interval);
  97 + if ($index < 0)
  98 + array_push($this->indexes, count($this->intervals) - 1);
  99 + else
  100 + array_splice($this->indexes, $index, 0, array(count($this->intervals) - 1));
  101 + if ($isNew)
  102 + $this->isModified = true;
  103 +
  104 + return $interval;
100 } 105 }
101 106
102 - public function setParamsNumber($number){ 107 + public function setParamsNumber($number)
  108 + {
103 $this->paramsNumber = $number; 109 $this->paramsNumber = $number;
104 } 110 }
105 111
106 - public function setParamsSizes($params){  
107 - for ($i = 0; $i < $this->paramsNumber; $i++)  
108 - $this->paramsSizes[$i] = $params[$i]['size']; 112 + public function setParamsSizes($params)
  113 + {
  114 + for ($i = 0; $i < $this->paramsNumber; $i++)
  115 + $this->paramsSizes[$i] = $params[$i]['size'];
109 } 116 }
110 117
111 - public function writeBin($handle) { 118 + public function writeBin($handle)
  119 + {
112 //Magic key ("TTC") 120 //Magic key ("TTC")
113 fwrite($handle,pack('C3',ord('T'),ord('T'),ord('C'))); 121 fwrite($handle,pack('C3',ord('T'),ord('T'),ord('C')));
114 122
@@ -206,7 +214,7 @@ class CatalogCacheObject extends TimeTableCacheObject @@ -206,7 +214,7 @@ class CatalogCacheObject extends TimeTableCacheObject
206 $interval->loadBin($handle, $this->paramsNumber, $this->paramsSizes); 214 $interval->loadBin($handle, $this->paramsNumber, $this->paramsSizes);
207 array_push($this->intervals, $interval); 215 array_push($this->intervals, $interval);
208 } 216 }
209 - 217 +
210 //Indexes 218 //Indexes
211 $res = unpack('Ldata',fread($handle,4)); 219 $res = unpack('Ldata',fread($handle,4));
212 $nbIndexes = $res['data']; 220 $nbIndexes = $res['data'];
@@ -218,7 +226,6 @@ class CatalogCacheObject extends TimeTableCacheObject @@ -218,7 +226,6 @@ class CatalogCacheObject extends TimeTableCacheObject
218 226
219 return true; 227 return true;
220 } 228 }
221 -  
222 } 229 }
223 230
224 class CatalogCacheMgr extends TimeTableCacheMgr 231 class CatalogCacheMgr extends TimeTableCacheMgr
@@ -273,11 +280,12 @@ class CatalogCacheMgr extends TimeTableCacheMgr @@ -273,11 +280,12 @@ class CatalogCacheMgr extends TimeTableCacheMgr
273 'status' => $this->cache->getStatus(), 'parameters' => $paramHeaders); 280 'status' => $this->cache->getStatus(), 'parameters' => $paramHeaders);
274 } 281 }
275 282
276 - public function initFromTT($id, $typeTT) { 283 + public function initFromTT($id, $typeTT)
  284 + {
277 //Create new cache 285 //Create new cache
278 - $this->cache = new CatalogeCacheObject(); 286 + $this->cache = new CatalogCacheObject();
279 287
280 - //Load intervals from TT file and add to cache 288 + //Load intervals from catalog file and add to cache
281 $intervals_res = $this->ttMgr->loadIntervalsFromTT($id,$typeTT); 289 $intervals_res = $this->ttMgr->loadIntervalsFromTT($id,$typeTT);
282 290
283 if (!$intervals_res['success']) 291 if (!$intervals_res['success'])
@@ -286,21 +294,26 @@ class CatalogCacheMgr extends TimeTableCacheMgr @@ -286,21 +294,26 @@ class CatalogCacheMgr extends TimeTableCacheMgr
286 foreach ($intervals_res['intervals'] as $interval) 294 foreach ($intervals_res['intervals'] as $interval)
287 { 295 {
288 //Add interval 296 //Add interval
289 - $this->cache->addInterval($interval['start'], $interval['stop']); 297 + $this->cache->addInterval($interval['start'], $interval['stop'], $interval['paramTable']);
290 } 298 }
291 299
  300 + $paramHeaders = $intervals_res['parameters'];
  301 +
  302 + $this->cache->setParamsNumber(count($paramHeaders));
  303 + $this->cache->setParamsSizes($paramHeaders);
292 unset($intervals_res); 304 unset($intervals_res);
293 305
294 //Update cache 306 //Update cache
295 $this->cache->updateIndexes(); 307 $this->cache->updateIndexes();
296 308
297 //Save cache file 309 //Save cache file
298 - return array('success' => $this->saveToFile(), 'token' => $this->cache->getToken(), 'status' => $this->cache->getStatus()); 310 + return array('success' => $this->saveToFile(), 'token' => $this->cache->getToken(),
  311 + 'status' => $this->cache->getStatus(),'parameters' => $paramHeaders);
299 } 312 }
300 313
301 314
302 - protected function loadFromFile() {  
303 - 315 + protected function loadFromFile()
  316 + {
304 if (!file_exists($this->getCacheFilePath())) 317 if (!file_exists($this->getCacheFilePath()))
305 return false; 318 return false;
306 $this->cache = new CatalogCacheObject(); 319 $this->cache = new CatalogCacheObject();
@@ -313,15 +326,16 @@ class CatalogCacheMgr extends TimeTableCacheMgr @@ -313,15 +326,16 @@ class CatalogCacheMgr extends TimeTableCacheMgr
313 $result = true; 326 $result = true;
314 } 327 }
315 fclose($handle); 328 fclose($handle);
316 - return $result; 329 + return $result;
317 } 330 }
318 331
319 - protected function getCacheFilePath() { 332 + protected function getCacheFilePath()
  333 + {
320 return USERTTDIR.(self::$cache_file); 334 return USERTTDIR.(self::$cache_file);
321 } 335 }
322 336
323 - public function saveInTT($id, $action, $token) {  
324 - 337 + public function saveInTT($id, $action, $token)
  338 + {
325 if (!$this->loadFromFile()) 339 if (!$this->loadFromFile())
326 return array('success' => false, 'message' => 'Cannot load cache file'); 340 return array('success' => false, 'message' => 'Cannot load cache file');
327 341
@@ -334,11 +348,8 @@ class CatalogCacheMgr extends TimeTableCacheMgr @@ -334,11 +348,8 @@ class CatalogCacheMgr extends TimeTableCacheMgr
334 $intervals = $this->cache->getIntervalsArray(NULL,NULL,true); 348 $intervals = $this->cache->getIntervalsArray(NULL,NULL,true);
335 349
336 $this->cache->reset(); 350 $this->cache->reset();
337 -  
338 - return $this->ttMgr->saveIntervals($id, $intervals, $action);  
339 - }  
340 351
341 -  
342 - 352 + return $this->ttMgr->saveIntervals($id, $intervals, $action);
  353 + }
343 } 354 }
344 ?> 355 ?>
345 \ No newline at end of file 356 \ No newline at end of file
php/classes/CatalogMgr.php
@@ -100,10 +100,8 @@ class CatalogMgr extends TimeTableMgr { @@ -100,10 +100,8 @@ class CatalogMgr extends TimeTableMgr {
100 $attributesToReturn['parameters'] = $paramsArray; 100 $attributesToReturn['parameters'] = $paramsArray;
101 } 101 }
102 else 102 else
103 - return array('error' => 'No information on parameters in result file');  
104 -  
105 -  
106 - } 103 + return array('error' => 'No information on parameters in result file');
  104 + }
107 105
108 return $attributesToReturn; 106 return $attributesToReturn;
109 } 107 }
@@ -111,7 +109,6 @@ class CatalogMgr extends TimeTableMgr { @@ -111,7 +109,6 @@ class CatalogMgr extends TimeTableMgr {
111 109
112 public function loadIntervalsFromTT($id, $typeTT, $start = NULL, $limit = NULL) 110 public function loadIntervalsFromTT($id, $typeTT, $start = NULL, $limit = NULL)
113 { 111 {
114 -  
115 if ($typeTT == 'sharedcatalog') { 112 if ($typeTT == 'sharedcatalog') {
116 $pathid = SHAREDPATH.'TT/'.$id; 113 $pathid = SHAREDPATH.'TT/'.$id;
117 } 114 }
@@ -120,43 +117,71 @@ class CatalogMgr extends TimeTableMgr { @@ -120,43 +117,71 @@ class CatalogMgr extends TimeTableMgr {
120 } 117 }
121 118
122 //load intervals from TT id 119 //load intervals from TT id
123 - if (!file_exists($pathid.'.xml'))  
124 - return array('success' => false, 'message' => "Cannot find Catalog file ".$id); 120 + if (!file_exists($pathid.'.xml'))
  121 + return array('success' => false, 'message' => "Cannot find Catalog file ".$id);
125 122
126 $this->objectDom->load($pathid.'.xml'); 123 $this->objectDom->load($pathid.'.xml');
127 124
128 - if (!($objToGet = $this->objectDom->getElementById($id)))  
129 - return array('success' => false, 'message' => NO_SUCH_ID." ".$id); 125 + if (!($objToGet = $this->objectDom->getElementById($id)))
  126 + return array('success' => false, 'message' => NO_SUCH_ID." ".$id);
130 127
131 $xpath = new DOMXPath($this->objectDom); 128 $xpath = new DOMXPath($this->objectDom);
132 $intervals = $xpath->query('//intervals'); 129 $intervals = $xpath->query('//intervals');
133 130
134 $result = array(); 131 $result = array();
135 132
136 - if (!isset($start) || !isset($limit))  
137 - {  
138 - foreach ($intervals as $interval)  
139 - {  
140 - $startTime = $interval->getElementsByTagName('start')->item(0)->nodeValue;  
141 - $stopTime = $interval->getElementsByTagName('stop')->item(0)->nodeValue;  
142 - array_push($result, array('start' => $startTime, 'stop' => $stopTime));  
143 - }  
144 - }  
145 - else 133 + if (!isset($start) || !isset($limit))
  134 + {
  135 + foreach ($intervals as $interval)
  136 + {
  137 + $startTime = $interval->getElementsByTagName('start')->item(0)->nodeValue;
  138 + $stopTime = $interval->getElementsByTagName('stop')->item(0)->nodeValue;
  139 + // for catalog
  140 + $paramNodes = $interval->getElementsByTagName('param');
  141 + $params = array();
  142 + if ($paramNodes->length > 0)
  143 + foreach ( $paramNodes as $paramNode ) $params[] = $paramNode->nodeValue;
  144 +
  145 + array_push($result, array('start' => $startTime, 'stop' => $stopTime,'paramTable' => $params));
  146 +
  147 + }
  148 + }
  149 + else
146 { 150 {
147 - for ($i = 0; $i < $limit; ++$i)  
148 - { 151 + for ($i = 0; $i < $limit; ++$i)
  152 + {
149 if ($start+$i >= $intervals->length) 153 if ($start+$i >= $intervals->length)
150 break; 154 break;
151 - $startTime = $intervals->item($start+$i)->getElementsByTagName('start')->item(0)->nodeValue;  
152 - $stopTime = $intervals->item($start+$i)->getElementsByTagName('stop')->item(0)->nodeValue;  
153 - array_push($result, array('start' => $startTime, 'stop' => $stopTime));  
154 - }  
155 - }  
156 -  
157 - return array( 155 + $startTime = $intervals->item($start+$i)->getElementsByTagName('start')->item(0)->nodeValue;
  156 + $stopTime = $intervals->item($start+$i)->getElementsByTagName('stop')->item(0)->nodeValue;
  157 + // for catalog
  158 + $paramNodes = $intervals->item($start+$i)->getElementsByTagName('param');
  159 + $params = array();
  160 + if ($paramNodes->length > 0)
  161 + foreach ( $paramNodes as $paramNode ) $params[] = $paramNode->nodeValue;
  162 +
  163 + array_push($result, array('start' => $startTime, 'stop' => $stopTime,'paramTable' => $params));
  164 + }
  165 + }
  166 + // for catalog : params header
  167 + $paramsNodes = $xpath->query('//parametres/param');
  168 + $paramsArray = array();
  169 +
  170 + if ($paramsNodes->length > 0)
  171 + {
  172 + foreach ($paramsNodes as $paramNode)
  173 + {
  174 + $oneParam = array();
  175 + foreach ($paramNode->attributes as $attr)
  176 + $oneParam[$attr->nodeName] = $attr->nodeValue;
  177 + $paramsArray[] = $oneParam;
  178 + }
  179 + }
  180 +
  181 + return array(
158 'totalCount' => $intervals->length, 182 'totalCount' => $intervals->length,
159 'intervals' => $result, 183 'intervals' => $result,
  184 + 'parameters' => $paramsArray,
160 'start' => isset($start) ? $start : 0, 185 'start' => isset($start) ? $start : 0,
161 'limit' => isset($limit) ? $limit : 0, 186 'limit' => isset($limit) ? $limit : 0,
162 'success' => true 187 'success' => true
@@ -167,34 +192,36 @@ class CatalogMgr extends TimeTableMgr { @@ -167,34 +192,36 @@ class CatalogMgr extends TimeTableMgr {
167 /* 192 /*
168 * catalog header 193 * catalog header
169 */ 194 */
170 - protected function setParamDescription($params) {  
171 -  
172 - $paramsElement = $this->objectDom->createElement('parametres');  
173 - foreach ($params as $param) {  
174 - $paramElement = $this->objectDom->createElement('param');  
175 - $attrArray = (array)$param;  
176 - foreach ($attrArray as $key => $value)  
177 - $paramElement->setAttribute($key, $value);  
178 - $paramsElement->appendChild($paramElement);  
179 - }  
180 -  
181 - return $paramsElement;  
182 - }  
183 -  
184 - protected function createIntervalElement($interval) {  
185 - $newInterval = $this->objectDom->createElement('intervals');  
186 - $newInterval->appendChild($this->objectDom->createElement('start',$interval['start']));  
187 - $newInterval->appendChild($this->objectDom->createElement('stop',$interval['stop']));  
188 - foreach ($interval as $key =>$value) {  
189 - if (substr($key,0,5) == 'param')  
190 - $newInterval->appendChild($this->objectDom->createElement('param', $value));  
191 - 195 + protected function setParamDescription($params)
  196 + {
  197 + $paramsElement = $this->objectDom->createElement('parametres');
  198 + foreach ($params as $param)
  199 + {
  200 + $paramElement = $this->objectDom->createElement('param');
  201 + $attrArray = (array)$param;
  202 + foreach ($attrArray as $key => $value)
  203 + $paramElement->setAttribute($key, $value);
  204 + $paramsElement->appendChild($paramElement);
  205 + }
  206 +
  207 + return $paramsElement;
192 } 208 }
  209 +
  210 + protected function createIntervalElement($interval)
  211 + {
  212 + $newInterval = $this->objectDom->createElement('intervals');
  213 + $newInterval->appendChild($this->objectDom->createElement('start',$interval['start']));
  214 + $newInterval->appendChild($this->objectDom->createElement('stop',$interval['stop']));
  215 + foreach ($interval as $key =>$value) {
  216 + if (substr($key,0,5) == 'param')
  217 + $newInterval->appendChild($this->objectDom->createElement('param', $value));
  218 +
  219 + }
193 return $newInterval; 220 return $newInterval;
194 } 221 }
195 222
196 - public function createObject($p, $folder){  
197 - 223 + public function createObject($p, $folder)
  224 + {
198 if ($p -> leaf) 225 if ($p -> leaf)
199 { 226 {
200 $result = $this->createParameter($p, $folder); 227 $result = $this->createParameter($p, $folder);
php/classes/TimeTableMgr.php
@@ -7,23 +7,23 @@ @@ -7,23 +7,23 @@
7 * 7 *
8 */ 8 */
9 9
10 -function timeFormat($myString) {  
11 - if (format == "Y z H i s") {  
12 - $tt = getdate(strtotime($myString));  
13 - return sprintf("%04d",$tt["year"])." "  
14 - .sprintf("%03d",$tt["yday"]+1)." "  
15 - .sprintf("%02d",$tt["hours"])." "  
16 - .sprintf("%02d",$tt["minutes"])." "  
17 - .sprintf("%02d",$tt["seconds"]);  
18 - }  
19 - return date(format,strtotime($myString));  
20 -  
21 - }  
22 -  
23 -class TimeTableMgr extends AmdaObjectMgr {  
24 - 10 +function timeFormat($myString)
  11 +{
  12 + if (format == "Y z H i s") {
  13 + $tt = getdate(strtotime($myString));
  14 + return sprintf("%04d",$tt["year"])." "
  15 + .sprintf("%03d",$tt["yday"]+1)." "
  16 + .sprintf("%02d",$tt["hours"])." "
  17 + .sprintf("%02d",$tt["minutes"])." "
  18 + .sprintf("%02d",$tt["seconds"]);
  19 + }
  20 + return date(format,strtotime($myString));
  21 +}
25 22
26 - function __construct($user) { 23 +class TimeTableMgr extends AmdaObjectMgr
  24 +{
  25 + function __construct($user)
  26 + {
27 parent::__construct('Tt.xml'); 27 parent::__construct('Tt.xml');
28 $this->contentRootId = 'timeTable-treeRootNode'; 28 $this->contentRootId = 'timeTable-treeRootNode';
29 $this->contentRootTag = 'timetabList'; 29 $this->contentRootTag = 'timetabList';
@@ -38,7 +38,6 @@ class TimeTableMgr extends AmdaObjectMgr { @@ -38,7 +38,6 @@ class TimeTableMgr extends AmdaObjectMgr {
38 } 38 }
39 } 39 }
40 40
41 -  
42 protected function createDom() { 41 protected function createDom() {
43 42
44 $types = array('timetab' => 'timeTable', 'catalog' => 'catalog'); 43 $types = array('timetab' => 'timeTable', 'catalog' => 'catalog');
@@ -51,14 +50,15 @@ class TimeTableMgr extends AmdaObjectMgr { @@ -51,14 +50,15 @@ class TimeTableMgr extends AmdaObjectMgr {
51 $typeElement->setAttribute('xml:id', $contentId); 50 $typeElement->setAttribute('xml:id', $contentId);
52 $rootElement->appendChild($typeElement); 51 $rootElement->appendChild($typeElement);
53 } 52 }
54 - $this->contentDom->appendChild($rootElement); 53 + $this->contentDom->appendChild($rootElement);
55 $this->contentDom->save($this->xmlName); 54 $this->contentDom->save($this->xmlName);
56 } 55 }
57 56
58 /* 57 /*
59 - * rename Time Table in id.xml  
60 - */  
61 - protected function renameInResource($name, $id) { 58 + * rename Time Table in id.xml
  59 + */
  60 + protected function renameInResource($name, $id)
  61 + {
62 if (!file_exists(USERTTDIR.$id.'.xml')) return false; 62 if (!file_exists(USERTTDIR.$id.'.xml')) return false;
63 63
64 $this->objectDom -> load(USERTTDIR.$id.'.xml'); 64 $this->objectDom -> load(USERTTDIR.$id.'.xml');
@@ -69,13 +69,14 @@ class TimeTableMgr extends AmdaObjectMgr { @@ -69,13 +69,14 @@ class TimeTableMgr extends AmdaObjectMgr {
69 return true; 69 return true;
70 } 70 }
71 71
72 - protected function deleteParameter($id){ 72 + protected function deleteParameter($id)
  73 + {
73 if (file_exists(USERTTDIR.$id.'.xml')) unlink(USERTTDIR.$id.'.xml'); 74 if (file_exists(USERTTDIR.$id.'.xml')) unlink(USERTTDIR.$id.'.xml');
74 } 75 }
75 76
76 /* 77 /*
77 - * Check if difference is name and info only  
78 - */ 78 + * Check if difference is name and info only
  79 + */
79 protected function renameOnly($p) { 80 protected function renameOnly($p) {
80 //if (!($p->intervals)) return true; 81 //if (!($p->intervals)) return true;
81 return false; 82 return false;
@@ -90,7 +91,8 @@ class TimeTableMgr extends AmdaObjectMgr { @@ -90,7 +91,8 @@ class TimeTableMgr extends AmdaObjectMgr {
90 /* 91 /*
91 * Create Time Table 92 * Create Time Table
92 */ 93 */
93 - protected function createParameter($p, $folder){ 94 + protected function createParameter($p, $folder)
  95 + {
94 if ($this -> objectExistsByName($p->name)) { 96 if ($this -> objectExistsByName($p->name)) {
95 $p -> id = $this -> getObjectIdByName($p->name); 97 $p -> id = $this -> getObjectIdByName($p->name);
96 $this -> deleteObject($p); 98 $this -> deleteObject($p);
@@ -137,119 +139,117 @@ class TimeTableMgr extends AmdaObjectMgr { @@ -137,119 +139,117 @@ class TimeTableMgr extends AmdaObjectMgr {
137 $obj->intervals = $p->nbIntervals; 139 $obj->intervals = $p->nbIntervals;
138 $this -> addToContent($obj, $folder); 140 $this -> addToContent($obj, $folder);
139 return array('id' => $this->id,'created' => $this->created,'info' =>$obj->intervals.' intervals' ); 141 return array('id' => $this->id,'created' => $this->created,'info' =>$obj->intervals.' intervals' );
140 -  
141 } 142 }
142 143
143 - protected function call_intersection($fst, $snd) {  
144 - $inf = ( $fst[0] > $snd[0] ) ? $fst[0] : $snd[0];  
145 - $sup = ( $fst[1] < $snd[1] ) ? $fst[1] : $snd[1];  
146 - if ( $inf >= $sup ) { $inter[] = array(0,0); }  
147 - else {$inter[] = array($inf,$sup); }  
148 - return $inter;  
149 - } 144 + protected function call_intersection($fst, $snd)
  145 + {
  146 + $inf = ( $fst[0] > $snd[0] ) ? $fst[0] : $snd[0];
  147 + $sup = ( $fst[1] < $snd[1] ) ? $fst[1] : $snd[1];
  148 + if ( $inf >= $sup ) { $inter[] = array(0,0); }
  149 + else {$inter[] = array($inf,$sup); }
  150 + return $inter;
  151 + }
150 152
151 /* 153 /*
152 * For TT download : file format in text 154 * For TT download : file format in text
153 */ 155 */
154 - protected function xsl2text($file,$format) {  
155 - define("format", $format);  
156 - $xslt = new XSLTProcessor(); 156 + protected function xsl2text($file,$format)
  157 + {
  158 + define("format", $format);
  159 + $xslt = new XSLTProcessor();
157 160
158 - // add PHP functions to XSLT functions  
159 - $xslt -> registerPHPFunctions();  
160 -  
161 - // Load Time table  
162 - $xml = new domDocument("1.0");  
163 - $xml->load($file);  
164 -  
165 - // Load XSL file  
166 - $xsl = new domDocument("1.0");  
167 - if ($format == "Y-m-dTH:i:s") $xslName = "xml2iso.xsl";  
168 - else $xslName = "xml2all.xsl";  
169 - $xsl->load(XMLPATH.$xslName);  
170 -  
171 - // Import XSL and write output file in text format  
172 - $xslt -> importStylesheet($xsl);  
173 - $filename = $xml->getElementsByTagName('name')->item(0)->nodeValue.".txt";  
174 - $output=fopen(USERWORKINGDIR.$filename, "w");  
175 - fwrite($output, trim($xslt -> transformToDoc($xml)->firstChild->wholeText));  
176 - fclose($output); 161 + // add PHP functions to XSLT functions
  162 + $xslt -> registerPHPFunctions();
  163 +
  164 + // Load Time table
  165 + $xml = new domDocument("1.0");
  166 + $xml->load($file);
  167 +
  168 + // Load XSL file
  169 + $xsl = new domDocument("1.0");
  170 + if ($format == "Y-m-dTH:i:s") $xslName = "xml2iso.xsl";
  171 + else $xslName = "xml2all.xsl";
  172 + $xsl->load(XMLPATH.$xslName);
  173 +
  174 + // Import XSL and write output file in text format
  175 + $xslt -> importStylesheet($xsl);
  176 + $filename = $xml->getElementsByTagName('name')->item(0)->nodeValue.".txt";
  177 + $output=fopen(USERWORKINGDIR.$filename, "w");
  178 + fwrite($output, trim($xslt -> transformToDoc($xml)->firstChild->wholeText));
  179 + fclose($output);
177 180
178 return USERWORKINGDIR.$filename; 181 return USERWORKINGDIR.$filename;
179 } 182 }
180 183
181 /* 184 /*
182 - * For TT download : file format in vot 185 + * For TT download : file format in vot
183 */ 186 */
184 - public function xsl2vot($file,$format) { 187 + public function xsl2vot($file,$format)
  188 + {
185 $xslt = new XSLTProcessor(); 189 $xslt = new XSLTProcessor();
186 190
187 - // Load Time table  
188 - $xml = new domDocument("1.0");  
189 - $xml->load($file);  
190 -  
191 - // Load XSL file  
192 - $xsl = new domDocument("1.0");  
193 - $xsl->load(XMLPATH.'xml2vot.xsl');  
194 -  
195 - // Import XSL and write output file in vot format  
196 - $xslt -> importStylesheet($xsl);  
197 - $vot = new domDocument("1.0");  
198 - $vot -> loadXML($xslt -> transformToXML($xml));  
199 - $filename = $xml->getElementsByTagName('name')->item(0)->nodeValue.".xml";  
200 - $vot -> save(USERWORKINGDIR.$filename);  
201 -  
202 - return USERWORKINGDIR.$filename; 191 + // Load Time table
  192 + $xml = new domDocument("1.0");
  193 + $xml->load($file);
  194 +
  195 + // Load XSL file
  196 + $xsl = new domDocument("1.0");
  197 + $xsl->load(XMLPATH.'xml2vot.xsl');
  198 +
  199 + // Import XSL and write output file in vot format
  200 + $xslt -> importStylesheet($xsl);
  201 + $vot = new domDocument("1.0");
  202 + $vot -> loadXML($xslt -> transformToXML($xml));
  203 + $filename = $xml->getElementsByTagName('name')->item(0)->nodeValue.".xml";
  204 + $vot -> save(USERWORKINGDIR.$filename);
  205 +
  206 + return USERWORKINGDIR.$filename;
203 } 207 }
204 208
205 /* 209 /*
206 * Uploaded text file => convert to array 210 * Uploaded text file => convert to array
207 */ 211 */
208 - protected function text2amda($tmp_file, $onlyDescription = false) {  
209 -  
210 -  
211 - $suffix = explode('.', basename($tmp_file));  
212 -  
213 - $lines = file($tmp_file,FILE_SKIP_EMPTY_LINES);  
214 -  
215 - $description="Uploaded Time Table".PHP_EOL;  
216 -  
217 - foreach ($lines as $line){  
218 - if ($line[0] == '#') $description=$description."\n".substr($line,1,-1);  
219 - else {  
220 - $date = explode(' ',$line);  
221 - if (!strtotime(trim($date[0]))) {  
222 - $description=$description."\n".$line;  
223 - continue;  
224 - }  
225 -// check if it is ISO format  
226 - if (!isset($isIso)) $isIso = preg_match('/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})$/', trim($date[0]));  
227 - if (!$isIso) { 212 + protected function text2amda($tmp_file, $onlyDescription = false)
  213 + {
  214 + $suffix = explode('.', basename($tmp_file));
  215 + $lines = file($tmp_file,FILE_SKIP_EMPTY_LINES);
  216 + $description="Uploaded Time Table".PHP_EOL;
  217 +
  218 + foreach ($lines as $line){
  219 + if ($line[0] == '#') $description=$description."\n".substr($line,1,-1);
  220 + else {
  221 + $date = explode(' ',$line);
  222 + if (!strtotime(trim($date[0]))) {
  223 + $description=$description."\n".$line;
  224 + continue;
  225 + }
  226 + // check if it is ISO format
  227 + if (!isset($isIso)) $isIso = preg_match('/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})$/', trim($date[0]));
  228 + if (!$isIso) {
228 $tempT = strtotime(trim($date[0])); 229 $tempT = strtotime(trim($date[0]));
229 $startDate = date('Y-m-d',$tempT)."T".date('H:i:s',$tempT); 230 $startDate = date('Y-m-d',$tempT)."T".date('H:i:s',$tempT);
230 $tempT = strtotime(trim($date[1])); 231 $tempT = strtotime(trim($date[1]));
231 $stopDate = date('Y-m-d',$tempT)."T".date('H:i:s',$tempT); 232 $stopDate = date('Y-m-d',$tempT)."T".date('H:i:s',$tempT);
232 -//TODO convert time into non standard formats  
233 - // $startDate = DateTime::createFromFormat($timeFormat, trim($date[0]);  
234 - // $start = $startDate->format('Y-m-d')."T".$startDate->format('H:i:s');  
235 - // $stopDate = DateTime::createFromFormat($timeFormat, trim($date[1]);  
236 - // $stop = $stopDate->format('Y-m-d')."T".$stopDate->format('H:i:s');  
237 - if (!$onlyDescription)  
238 - $attributesToReturn['intervals'][] = array('start' => $startDate, 'stop' => $stopDate);  
239 - }  
240 - else {  
241 - if (!$onlyDescription) 233 + //TODO convert time into non standard formats
  234 + // $startDate = DateTime::createFromFormat($timeFormat, trim($date[0]);
  235 + // $start = $startDate->format('Y-m-d')."T".$startDate->format('H:i:s');
  236 + // $stopDate = DateTime::createFromFormat($timeFormat, trim($date[1]);
  237 + // $stop = $stopDate->format('Y-m-d')."T".$stopDate->format('H:i:s');
  238 + if (!$onlyDescription)
  239 + $attributesToReturn['intervals'][] = array('start' => $startDate, 'stop' => $stopDate);
  240 + }
  241 + else {
  242 + if (!$onlyDescription)
242 $attributesToReturn['intervals'][] = array('start' => trim($date[0]), 'stop' => trim($date[1])); 243 $attributesToReturn['intervals'][] = array('start' => trim($date[0]), 'stop' => trim($date[1]));
243 } 244 }
244 } 245 }
245 } 246 }
246 247
247 - $attributesToReturn['description'] = $description;  
248 - $attributesToReturn['name'] = basename($tmp_file, '.'.$suffix[1]);  
249 - $attributesToReturn['created'] = date('Y-m-d')."T".date('H:i:s'); 248 + $attributesToReturn['description'] = $description;
  249 + $attributesToReturn['name'] = basename($tmp_file, '.'.$suffix[1]);
  250 + $attributesToReturn['created'] = date('Y-m-d')."T".date('H:i:s');
250 251
251 return $attributesToReturn; 252 return $attributesToReturn;
252 -  
253 } 253 }
254 254
255 255
@@ -288,7 +288,7 @@ class TimeTableMgr extends AmdaObjectMgr { @@ -288,7 +288,7 @@ class TimeTableMgr extends AmdaObjectMgr {
288 288
289 function getObject($id, $nodeType) { 289 function getObject($id, $nodeType) {
290 290
291 - if ($nodeType == 'sharedtimeTable') { 291 + if (substr($nodeType,0,6) == 'shared') {
292 $pathid = SHAREDPATH.'TT/'.$id; 292 $pathid = SHAREDPATH.'TT/'.$id;
293 } 293 }
294 else { 294 else {
@@ -303,20 +303,20 @@ class TimeTableMgr extends AmdaObjectMgr { @@ -303,20 +303,20 @@ class TimeTableMgr extends AmdaObjectMgr {
303 303
304 $nbInt = 0; 304 $nbInt = 0;
305 foreach($attributes as $attribute) 305 foreach($attributes as $attribute)
306 - if($attribute->nodeType == XML_ELEMENT_NODE){  
307 - /*if ($attribute->tagName == 'intervals') {  
308 - $start = $attribute -> getElementsByTagName('start')->item(0) -> nodeValue;  
309 - $stop = $attribute -> getElementsByTagName('stop')->item(0) -> nodeValue;  
310 - $attributesToReturn['intervals'][] = array('start' => $start, 'stop' => $stop);  
311 - }  
312 - else  
313 - $attributesToReturn[$attribute->tagName] = $attribute->nodeValue;*/  
314 - //BRE - load all except intervals - Intervals will be loaded later with 'loadIntervalsFromTT' function  
315 - if ($attribute->tagName != 'intervals')  
316 - $attributesToReturn[$attribute->tagName] = $attribute->nodeValue;  
317 - else  
318 - $nbInt++;  
319 - } 306 + if($attribute->nodeType == XML_ELEMENT_NODE){
  307 + /*if ($attribute->tagName == 'intervals') {
  308 + $start = $attribute -> getElementsByTagName('start')->item(0) -> nodeValue;
  309 + $stop = $attribute -> getElementsByTagName('stop')->item(0) -> nodeValue;
  310 + $attributesToReturn['intervals'][] = array('start' => $start, 'stop' => $stop);
  311 + }
  312 + else
  313 + $attributesToReturn[$attribute->tagName] = $attribute->nodeValue;*/
  314 + //BRE - load all except intervals - Intervals will be loaded later with 'loadIntervalsFromTT' function
  315 + if ($attribute->tagName != 'intervals')
  316 + $attributesToReturn[$attribute->tagName] = $attribute->nodeValue;
  317 + else
  318 + $nbInt++;
  319 + }
320 320
321 $attributesToReturn['nbIntervals'] = $nbInt; 321 $attributesToReturn['nbIntervals'] = $nbInt;
322 322
@@ -769,7 +769,7 @@ class TimeTableMgr extends AmdaObjectMgr { @@ -769,7 +769,7 @@ class TimeTableMgr extends AmdaObjectMgr {
769 769
770 $transform = "xsl2".$obj->fileformat; 770 $transform = "xsl2".$obj->fileformat;
771 $format = $obj->timeformat; 771 $format = $obj->timeformat;
772 -// shared or my 772 + // shared or my
773 773
774 774
775 for ($i=0; $i < count($obj->list); $i++) { 775 for ($i=0; $i < count($obj->list); $i++) {