Commit 5446b8f017bc0d68955adf6851df5ebdb1a20004
1 parent
2190f380
Exists in
master
and in
101 other branches
Move CacheTools in TimeUtils
Showing
4 changed files
with
264 additions
and
260 deletions
Show diff stats
php/classes/CatalogCacheMgr.php
@@ -3,14 +3,14 @@ | @@ -3,14 +3,14 @@ | ||
3 | /** | 3 | /** |
4 | * @class CatalogCacheMgr | 4 | * @class CatalogCacheMgr |
5 | */ | 5 | */ |
6 | - | ||
7 | - | 6 | + |
7 | + | ||
8 | class CatIntervalCacheObject extends IntervalCacheObject | 8 | class CatIntervalCacheObject extends IntervalCacheObject |
9 | { | 9 | { |
10 | - // for catalog | 10 | + // for catalog |
11 | private $params = array(); | 11 | private $params = array(); |
12 | - | ||
13 | - public function toArray() | 12 | + |
13 | + public function toArray() | ||
14 | { | 14 | { |
15 | $result = array( | 15 | $result = array( |
16 | "cacheId" => $this->id, | 16 | "cacheId" => $this->id, |
@@ -19,54 +19,54 @@ class CatIntervalCacheObject extends IntervalCacheObject | @@ -19,54 +19,54 @@ class CatIntervalCacheObject extends IntervalCacheObject | ||
19 | ); | 19 | ); |
20 | if ($this->isNew) | 20 | if ($this->isNew) |
21 | $result["isNew"] = true; | 21 | $result["isNew"] = true; |
22 | - | 22 | + |
23 | if ($this->isModified) | 23 | if ($this->isModified) |
24 | $result["isModified"] = true; | 24 | $result["isModified"] = true; |
25 | - | ||
26 | - for ($i = 0; $i < count($this->params); $i++) | 25 | + |
26 | + for ($i = 0; $i < count($this->params); $i++) | ||
27 | { | 27 | { |
28 | $paramObject = array(); | 28 | $paramObject = array(); |
29 | $index = 'param'.sprintf("%d",$i+2); | 29 | $index = 'param'.sprintf("%d",$i+2); |
30 | - $result[$index] = $this->params[$i]; | ||
31 | - } | ||
32 | - return $result; | 30 | + $result[$index] = $this->params[$i]; |
31 | + } | ||
32 | + return $result; | ||
33 | } | 33 | } |
34 | 34 | ||
35 | - // for catalog | ||
36 | - public function setParams($params) | 35 | + // for catalog |
36 | + public function setParams($params) | ||
37 | { | 37 | { |
38 | - $this->params = $params; | 38 | + $this->params = $params; |
39 | } | 39 | } |
40 | - | ||
41 | - public function getParams() | ||
42 | - { | ||
43 | - return $this->params; | 40 | + |
41 | + public function getParams() | ||
42 | + { | ||
43 | + return $this->params; | ||
44 | } | 44 | } |
45 | - | ||
46 | - public function writeBin($handle, $paramsNumber, $paramsSizes, $paramsTypes) | 45 | + |
46 | + public function writeBin($handle, $paramsNumber, $paramsSizes, $paramsTypes) | ||
47 | { | 47 | { |
48 | fwrite($handle,pack('L6',$this->id,$this->index,$this->start,$this->stop,$this->isNew,$this->isModified)); | 48 | fwrite($handle,pack('L6',$this->id,$this->index,$this->start,$this->stop,$this->isNew,$this->isModified)); |
49 | - for ($i = 0; $i < $paramsNumber; $i++) | 49 | + for ($i = 0; $i < $paramsNumber; $i++) |
50 | { | 50 | { |
51 | if ($paramsTypes[$i] == '2') // string | 51 | if ($paramsTypes[$i] == '2') // string |
52 | { | 52 | { |
53 | fwrite($handle,pack('d', strlen($this->params[$i]))); | 53 | fwrite($handle,pack('d', strlen($this->params[$i]))); |
54 | fwrite($handle, $this->params[$i],strlen($this->params[$i])); | 54 | fwrite($handle, $this->params[$i],strlen($this->params[$i])); |
55 | } | 55 | } |
56 | - else | 56 | + else |
57 | { | 57 | { |
58 | - if ($paramsTypes[$i] == '1') | ||
59 | - $paramString = CacheTools::iso2stamp($this->params[$i]); | 58 | + if ($paramsTypes[$i] == '1') |
59 | + $paramString = TimeUtils::iso2stamp($this->params[$i]); | ||
60 | else | 60 | else |
61 | $paramString = $this->params[$i]; | 61 | $paramString = $this->params[$i]; |
62 | - | 62 | + |
63 | $paramArray = explode(',',$paramString); | 63 | $paramArray = explode(',',$paramString); |
64 | for ($j = 0; $j < $paramsSizes[$i]; $j++) fwrite($handle,pack('d', $paramArray[$j])); | 64 | for ($j = 0; $j < $paramsSizes[$i]; $j++) fwrite($handle,pack('d', $paramArray[$j])); |
65 | } | 65 | } |
66 | - } | 66 | + } |
67 | } | 67 | } |
68 | - | ||
69 | - public function loadBin($handle, $paramsNumber, $paramsSizes, $paramsTypes) | 68 | + |
69 | + public function loadBin($handle, $paramsNumber, $paramsSizes, $paramsTypes) | ||
70 | { | 70 | { |
71 | $array = unpack('L6int',fread($handle,6*4)); | 71 | $array = unpack('L6int',fread($handle,6*4)); |
72 | $this->id = $array['int1']; | 72 | $this->id = $array['int1']; |
@@ -75,45 +75,45 @@ class CatIntervalCacheObject extends IntervalCacheObject | @@ -75,45 +75,45 @@ class CatIntervalCacheObject extends IntervalCacheObject | ||
75 | $this->stop = $array['int4']; | 75 | $this->stop = $array['int4']; |
76 | $this->isNew = $array['int5']; | 76 | $this->isNew = $array['int5']; |
77 | $this->isModified = $array['int6']; | 77 | $this->isModified = $array['int6']; |
78 | - | 78 | + |
79 | for ($i = 0; $i < $paramsNumber; $i++) { | 79 | for ($i = 0; $i < $paramsNumber; $i++) { |
80 | $this->params[$i] = null; | 80 | $this->params[$i] = null; |
81 | - | ||
82 | - for ($j = 0; $j < $paramsSizes[$i]; $j++) | 81 | + |
82 | + for ($j = 0; $j < $paramsSizes[$i]; $j++) | ||
83 | { | 83 | { |
84 | $val = unpack('dval',fread($handle,8)); | 84 | $val = unpack('dval',fread($handle,8)); |
85 | - | 85 | + |
86 | if ($paramsTypes[$i] == '2') // string | 86 | if ($paramsTypes[$i] == '2') // string |
87 | { | 87 | { |
88 | $this->params[$i] = fread($handle,$val['val']); | 88 | $this->params[$i] = fread($handle,$val['val']); |
89 | } | 89 | } |
90 | - else | 90 | + else |
91 | { | 91 | { |
92 | if ($paramsTypes[$i] == '1') | 92 | if ($paramsTypes[$i] == '1') |
93 | - $this->params[$i] .= CacheTools::stamp2iso($val['val']); | ||
94 | - else | 93 | + $this->params[$i] .= TimeUtils::stamp2iso($val['val']); |
94 | + else | ||
95 | $this->params[$i] .= $val['val']; | 95 | $this->params[$i] .= $val['val']; |
96 | - | 96 | + |
97 | if ($j != $paramsSizes[$i] - 1) $this->params[$i] .= ','; | 97 | if ($j != $paramsSizes[$i] - 1) $this->params[$i] .= ','; |
98 | } | 98 | } |
99 | - } | 99 | + } |
100 | } | 100 | } |
101 | - | 101 | + |
102 | } | 102 | } |
103 | - | ||
104 | - public function dump() | 103 | + |
104 | + public function dump() | ||
105 | { | 105 | { |
106 | echo " => Interval : id = ".$this->id.", index = ".$this->index.", start = ".$this->start.", stop = ".$this->stop.", isNew = ".$this->isNew.", isModified = ".$this->isModified.PHP_EOL; | 106 | echo " => Interval : id = ".$this->id.", index = ".$this->index.", start = ".$this->start.", stop = ".$this->stop.", isNew = ".$this->isNew.", isModified = ".$this->isModified.PHP_EOL; |
107 | } | 107 | } |
108 | -} | ||
109 | - | 108 | +} |
109 | + | ||
110 | class CatalogCacheObject extends TimeTableCacheObject | 110 | class CatalogCacheObject extends TimeTableCacheObject |
111 | { | 111 | { |
112 | private $paramsNumber; | 112 | private $paramsNumber; |
113 | private $paramsSizes = array(); | 113 | private $paramsSizes = array(); |
114 | private $paramsTypes = array(); | 114 | private $paramsTypes = array(); |
115 | - | ||
116 | - public function addInterval($startIso, $stopIso, $params, $isNew = false, $index = -1) | 115 | + |
116 | + public function addInterval($startIso, $stopIso, $params, $isNew = false, $index = -1) | ||
117 | { | 117 | { |
118 | $interval = new CatIntervalCacheObject($this->lastId, count($this->intervals)); | 118 | $interval = new CatIntervalCacheObject($this->lastId, count($this->intervals)); |
119 | ++$this->lastId; | 119 | ++$this->lastId; |
@@ -124,88 +124,88 @@ class CatalogCacheObject extends TimeTableCacheObject | @@ -124,88 +124,88 @@ class CatalogCacheObject extends TimeTableCacheObject | ||
124 | 124 | ||
125 | $interval->setIsNew($isNew); | 125 | $interval->setIsNew($isNew); |
126 | array_push($this->intervals, $interval); | 126 | array_push($this->intervals, $interval); |
127 | - | 127 | + |
128 | if ($index < 0) | 128 | if ($index < 0) |
129 | array_push($this->indexes, count($this->intervals) - 1); | 129 | array_push($this->indexes, count($this->intervals) - 1); |
130 | else | 130 | else |
131 | array_splice($this->indexes, $index, 0, array(count($this->intervals) - 1)); | 131 | array_splice($this->indexes, $index, 0, array(count($this->intervals) - 1)); |
132 | - | 132 | + |
133 | if ($isNew) | 133 | if ($isNew) |
134 | $this->isModified = true; | 134 | $this->isModified = true; |
135 | - | 135 | + |
136 | return $interval; | 136 | return $interval; |
137 | } | 137 | } |
138 | - | 138 | + |
139 | public function setParamsNumber($number) | 139 | public function setParamsNumber($number) |
140 | { | 140 | { |
141 | $this->paramsNumber = $number; | 141 | $this->paramsNumber = $number; |
142 | } | 142 | } |
143 | - | 143 | + |
144 | public function setParamsSizes($params) | 144 | public function setParamsSizes($params) |
145 | { | 145 | { |
146 | - for ($i = 0; $i < $this->paramsNumber; $i++) | ||
147 | - $this->paramsSizes[$i] = $params[$i]['size']; | 146 | + for ($i = 0; $i < $this->paramsNumber; $i++) |
147 | + $this->paramsSizes[$i] = $params[$i]['size']; | ||
148 | } | 148 | } |
149 | - | 149 | + |
150 | public function setParamsTypes($params) | 150 | public function setParamsTypes($params) |
151 | { | 151 | { |
152 | - for ($i = 0; $i < $this->paramsNumber; $i++) | ||
153 | - $this->paramsTypes[$i] = $params[$i]['type']; | 152 | + for ($i = 0; $i < $this->paramsNumber; $i++) |
153 | + $this->paramsTypes[$i] = $params[$i]['type']; | ||
154 | } | 154 | } |
155 | - | ||
156 | - public function writeBin($handle) | 155 | + |
156 | + public function writeBin($handle) | ||
157 | { | 157 | { |
158 | //Magic key ("TTC") | 158 | //Magic key ("TTC") |
159 | fwrite($handle,pack('C3',ord('T'),ord('T'),ord('C'))); | 159 | fwrite($handle,pack('C3',ord('T'),ord('T'),ord('C'))); |
160 | - | 160 | + |
161 | //Version | 161 | //Version |
162 | fwrite($handle,pack('L',TimeTableCacheObject::$format_version)); | 162 | fwrite($handle,pack('L',TimeTableCacheObject::$format_version)); |
163 | - | 163 | + |
164 | //Token | 164 | //Token |
165 | for ($i = 0; $i < TimeTableCacheObject::$token_len; ++$i) | 165 | for ($i = 0; $i < TimeTableCacheObject::$token_len; ++$i) |
166 | fwrite($handle,pack('C',ord($this->token[$i]))); | 166 | fwrite($handle,pack('C',ord($this->token[$i]))); |
167 | - | 167 | + |
168 | //Modified | 168 | //Modified |
169 | fwrite($handle,pack('L',$this->isModified)); | 169 | fwrite($handle,pack('L',$this->isModified)); |
170 | - | 170 | + |
171 | //Filter | 171 | //Filter |
172 | $this->filter->writeBin($handle); | 172 | $this->filter->writeBin($handle); |
173 | - | 173 | + |
174 | //Sort | 174 | //Sort |
175 | $this->sort->writeBin($handle); | 175 | $this->sort->writeBin($handle); |
176 | - | 176 | + |
177 | //Params Number | 177 | //Params Number |
178 | fwrite($handle,pack('L',$this->paramsNumber)); | 178 | fwrite($handle,pack('L',$this->paramsNumber)); |
179 | - | 179 | + |
180 | //Params Sizes | 180 | //Params Sizes |
181 | - for ($i = 0; $i < $this->paramsNumber; $i++) | 181 | + for ($i = 0; $i < $this->paramsNumber; $i++) |
182 | fwrite($handle,pack('L',$this->paramsSizes[$i])); | 182 | fwrite($handle,pack('L',$this->paramsSizes[$i])); |
183 | - | 183 | + |
184 | //Params Types | 184 | //Params Types |
185 | - for ($i = 0; $i < $this->paramsNumber; $i++) | 185 | + for ($i = 0; $i < $this->paramsNumber; $i++) |
186 | fwrite($handle,pack('L',$this->paramsTypes[$i])); | 186 | fwrite($handle,pack('L',$this->paramsTypes[$i])); |
187 | - | 187 | + |
188 | //Intervals | 188 | //Intervals |
189 | fwrite($handle,pack('L2', count($this->intervals), $this->lastId)); | 189 | fwrite($handle,pack('L2', count($this->intervals), $this->lastId)); |
190 | - | 190 | + |
191 | 191 | ||
192 | foreach($this->intervals as $interval) | 192 | foreach($this->intervals as $interval) |
193 | $interval->writeBin($handle,$this->paramsNumber,$this->paramsSizes, $this->paramsTypes); | 193 | $interval->writeBin($handle,$this->paramsNumber,$this->paramsSizes, $this->paramsTypes); |
194 | - | 194 | + |
195 | //Indexes | 195 | //Indexes |
196 | fwrite($handle,pack('L',count($this->indexes))); | 196 | fwrite($handle,pack('L',count($this->indexes))); |
197 | foreach($this->indexes as $index) | 197 | foreach($this->indexes as $index) |
198 | fwrite($handle,pack('L',$index)); | 198 | fwrite($handle,pack('L',$index)); |
199 | } | 199 | } |
200 | - | 200 | + |
201 | public function loadBin($handle) { | 201 | public function loadBin($handle) { |
202 | //Magic key ("TTC") | 202 | //Magic key ("TTC") |
203 | if (!$res = unpack('C3key',fread($handle,3))) | 203 | if (!$res = unpack('C3key',fread($handle,3))) |
204 | return false; | 204 | return false; |
205 | - | 205 | + |
206 | if (($res['key1'] != ord('T')) || ($res['key2'] != ord('T')) || ($res['key3'] != ord('C'))) | 206 | if (($res['key1'] != ord('T')) || ($res['key2'] != ord('T')) || ($res['key3'] != ord('C'))) |
207 | return false; | 207 | return false; |
208 | - | 208 | + |
209 | //Version | 209 | //Version |
210 | if (!$res = unpack('Lversion',fread($handle,4))) | 210 | if (!$res = unpack('Lversion',fread($handle,4))) |
211 | return false; | 211 | return false; |
@@ -221,23 +221,23 @@ class CatalogCacheObject extends TimeTableCacheObject | @@ -221,23 +221,23 @@ class CatalogCacheObject extends TimeTableCacheObject | ||
221 | $token .= chr($res['token']); | 221 | $token .= chr($res['token']); |
222 | } | 222 | } |
223 | $this->token = $token; | 223 | $this->token = $token; |
224 | - | 224 | + |
225 | //Modified | 225 | //Modified |
226 | if (!$res = unpack('Lmodified',fread($handle,4))) | 226 | if (!$res = unpack('Lmodified',fread($handle,4))) |
227 | return false; | 227 | return false; |
228 | $this->isModified = $res['modified']; | 228 | $this->isModified = $res['modified']; |
229 | - | 229 | + |
230 | //Filter | 230 | //Filter |
231 | $this->filter->loadBin($handle); | 231 | $this->filter->loadBin($handle); |
232 | - | 232 | + |
233 | //Sort | 233 | //Sort |
234 | $this->sort->loadBin($handle); | 234 | $this->sort->loadBin($handle); |
235 | - | 235 | + |
236 | //ParamsNumber | 236 | //ParamsNumber |
237 | if (!$res = unpack('Lnumber',fread($handle,4))) | 237 | if (!$res = unpack('Lnumber',fread($handle,4))) |
238 | return false; | 238 | return false; |
239 | $this->paramsNumber = $res['number']; | 239 | $this->paramsNumber = $res['number']; |
240 | - | 240 | + |
241 | //ParamsSizes | 241 | //ParamsSizes |
242 | for ($i = 0; $i < $this->paramsNumber; $i++) { | 242 | for ($i = 0; $i < $this->paramsNumber; $i++) { |
243 | if (!$res = unpack('Lsize',fread($handle,4))) | 243 | if (!$res = unpack('Lsize',fread($handle,4))) |
@@ -254,14 +254,14 @@ class CatalogCacheObject extends TimeTableCacheObject | @@ -254,14 +254,14 @@ class CatalogCacheObject extends TimeTableCacheObject | ||
254 | $res = unpack('L2data',fread($handle,2*4)); | 254 | $res = unpack('L2data',fread($handle,2*4)); |
255 | $nbIntervals = $res['data1']; | 255 | $nbIntervals = $res['data1']; |
256 | $this->lastId = $res['data2']; | 256 | $this->lastId = $res['data2']; |
257 | - | 257 | + |
258 | for ($i = 0; $i < $nbIntervals; ++$i) | 258 | for ($i = 0; $i < $nbIntervals; ++$i) |
259 | { | 259 | { |
260 | $interval = new CatIntervalCacheObject(-1); | 260 | $interval = new CatIntervalCacheObject(-1); |
261 | - $interval->loadBin($handle, $this->paramsNumber, $this->paramsSizes, $this->paramsTypes); | 261 | + $interval->loadBin($handle, $this->paramsNumber, $this->paramsSizes, $this->paramsTypes); |
262 | array_push($this->intervals, $interval); | 262 | array_push($this->intervals, $interval); |
263 | } | 263 | } |
264 | - | 264 | + |
265 | //Indexes | 265 | //Indexes |
266 | $res = unpack('Ldata',fread($handle,4)); | 266 | $res = unpack('Ldata',fread($handle,4)); |
267 | $nbIndexes = $res['data']; | 267 | $nbIndexes = $res['data']; |
@@ -270,29 +270,29 @@ class CatalogCacheObject extends TimeTableCacheObject | @@ -270,29 +270,29 @@ class CatalogCacheObject extends TimeTableCacheObject | ||
270 | $res = unpack('Lindex',fread($handle,4)); | 270 | $res = unpack('Lindex',fread($handle,4)); |
271 | array_push($this->indexes, $res['index']); | 271 | array_push($this->indexes, $res['index']); |
272 | } | 272 | } |
273 | - | 273 | + |
274 | return true; | 274 | return true; |
275 | } | 275 | } |
276 | - | ||
277 | - public function modifyIntervalFromId($obj) { | ||
278 | - | 276 | + |
277 | + public function modifyIntervalFromId($obj) { | ||
278 | + | ||
279 | foreach ($this->intervals as $interval) | 279 | foreach ($this->intervals as $interval) |
280 | { | 280 | { |
281 | if ($interval->getId() == $obj->cacheId) | 281 | if ($interval->getId() == $obj->cacheId) |
282 | - { | ||
283 | - foreach((array)$obj as $key => $val) { | ||
284 | - | 282 | + { |
283 | + foreach((array)$obj as $key => $val) { | ||
284 | + | ||
285 | if ($key == 'start') | 285 | if ($key == 'start') |
286 | $interval->setStartFromISO($val); | 286 | $interval->setStartFromISO($val); |
287 | else if ($key == 'stop') | 287 | else if ($key == 'stop') |
288 | - $interval->setStopFromISO($val); | 288 | + $interval->setStopFromISO($val); |
289 | else { | 289 | else { |
290 | if (strpos($key, 'param') === false) | 290 | if (strpos($key, 'param') === false) |
291 | continue; | 291 | continue; |
292 | $params = $interval->getParams(); | 292 | $params = $interval->getParams(); |
293 | $paramIndex = (int)substr($key,5); | 293 | $paramIndex = (int)substr($key,5); |
294 | $params[$paramIndex-2] = $val; | 294 | $params[$paramIndex-2] = $val; |
295 | - $interval->setParams($params); | 295 | + $interval->setParams($params); |
296 | } | 296 | } |
297 | } | 297 | } |
298 | $interval->setIsModified(true); | 298 | $interval->setIsModified(true); |
@@ -300,33 +300,33 @@ class CatalogCacheObject extends TimeTableCacheObject | @@ -300,33 +300,33 @@ class CatalogCacheObject extends TimeTableCacheObject | ||
300 | return true; | 300 | return true; |
301 | } | 301 | } |
302 | } | 302 | } |
303 | - | 303 | + |
304 | return false; | 304 | return false; |
305 | } | 305 | } |
306 | } | 306 | } |
307 | 307 | ||
308 | -class CatalogCacheMgr extends TimeTableCacheMgr | 308 | +class CatalogCacheMgr extends TimeTableCacheMgr |
309 | { | 309 | { |
310 | - | 310 | + |
311 | protected static $cache_file = "cacheCat"; | 311 | protected static $cache_file = "cacheCat"; |
312 | - | 312 | + |
313 | protected $ttMgr = null; | 313 | protected $ttMgr = null; |
314 | protected $cache = null; | 314 | protected $cache = null; |
315 | 315 | ||
316 | function __construct() { | 316 | function __construct() { |
317 | - | 317 | + |
318 | $this->ttMgr = new CatalogMgr(); | 318 | $this->ttMgr = new CatalogMgr(); |
319 | } | 319 | } |
320 | - | ||
321 | - | 320 | + |
321 | + | ||
322 | public function initFromTmpObject($folderId, $name) { | 322 | public function initFromTmpObject($folderId, $name) { |
323 | - | ||
324 | - //Create new cache | 323 | + |
324 | + //Create new cache | ||
325 | $this->cache = new CatalogCacheObject(); | 325 | $this->cache = new CatalogCacheObject(); |
326 | 326 | ||
327 | //Load intervals from TmpObject file (Statistics Module) | 327 | //Load intervals from TmpObject file (Statistics Module) |
328 | $intervals_res = $this->ttMgr->getTmpObject($folderId, $name); | 328 | $intervals_res = $this->ttMgr->getTmpObject($folderId, $name); |
329 | - | 329 | + |
330 | if (!isset($intervals_res)) | 330 | if (!isset($intervals_res)) |
331 | return array('success' => false, 'message' => 'Cannot get Tmp Object'); | 331 | return array('success' => false, 'message' => 'Cannot get Tmp Object'); |
332 | 332 | ||
@@ -336,28 +336,28 @@ class CatalogCacheMgr extends TimeTableCacheMgr | @@ -336,28 +336,28 @@ class CatalogCacheMgr extends TimeTableCacheMgr | ||
336 | { | 336 | { |
337 | //Add interval | 337 | //Add interval |
338 | $this->cache->addInterval($interval['start'], $interval['stop'], $interval['paramTable']); | 338 | $this->cache->addInterval($interval['start'], $interval['stop'], $interval['paramTable']); |
339 | - | 339 | + |
340 | } | 340 | } |
341 | } | 341 | } |
342 | 342 | ||
343 | $this->cache->setIsModified(true); | 343 | $this->cache->setIsModified(true); |
344 | - | 344 | + |
345 | $paramHeaders = $intervals_res['parameters']; | 345 | $paramHeaders = $intervals_res['parameters']; |
346 | - | 346 | + |
347 | $this->cache->setParamsNumber(count($paramHeaders)); | 347 | $this->cache->setParamsNumber(count($paramHeaders)); |
348 | $this->cache->setParamsSizes($paramHeaders); | 348 | $this->cache->setParamsSizes($paramHeaders); |
349 | $this->cache->setParamsTypes($paramHeaders); | 349 | $this->cache->setParamsTypes($paramHeaders); |
350 | - | ||
351 | - unset($intervals_res); | ||
352 | - | 350 | + |
351 | + unset($intervals_res); | ||
352 | + | ||
353 | //Update cache | 353 | //Update cache |
354 | $this->cache->updateIndexes(); | 354 | $this->cache->updateIndexes(); |
355 | 355 | ||
356 | //Save cache file | 356 | //Save cache file |
357 | - return array('success'=>$this->saveToFile(), 'token'=>$this->cache->getToken(), | 357 | + return array('success'=>$this->saveToFile(), 'token'=>$this->cache->getToken(), |
358 | 'status'=>$this->cache->getStatus(), 'parameters'=>$paramHeaders); | 358 | 'status'=>$this->cache->getStatus(), 'parameters'=>$paramHeaders); |
359 | } | 359 | } |
360 | - | 360 | + |
361 | public function initFromUploadedFile($name, $format) | 361 | public function initFromUploadedFile($name, $format) |
362 | { | 362 | { |
363 | //Create new cache | 363 | //Create new cache |
@@ -380,29 +380,29 @@ class CatalogCacheMgr extends TimeTableCacheMgr | @@ -380,29 +380,29 @@ class CatalogCacheMgr extends TimeTableCacheMgr | ||
380 | 380 | ||
381 | $this->cache->setIsModified(true); | 381 | $this->cache->setIsModified(true); |
382 | $paramHeaders = $intervals_res['parameters']; | 382 | $paramHeaders = $intervals_res['parameters']; |
383 | - | 383 | + |
384 | $this->cache->setParamsNumber(count($paramHeaders)); | 384 | $this->cache->setParamsNumber(count($paramHeaders)); |
385 | $this->cache->setParamsSizes($paramHeaders); | 385 | $this->cache->setParamsSizes($paramHeaders); |
386 | $this->cache->setParamsTypes($paramHeaders); | 386 | $this->cache->setParamsTypes($paramHeaders); |
387 | - | 387 | + |
388 | unset($intervals_res); | 388 | unset($intervals_res); |
389 | - | 389 | + |
390 | //Update cache | 390 | //Update cache |
391 | $this->cache->updateIndexes(); | 391 | $this->cache->updateIndexes(); |
392 | 392 | ||
393 | //Save cache file | 393 | //Save cache file |
394 | - return array('success'=>$this->saveToFile(), 'token'=>$this->cache->getToken(), | 394 | + return array('success'=>$this->saveToFile(), 'token'=>$this->cache->getToken(), |
395 | 'status'=>$this->cache->getStatus(), 'parameters'=>$paramHeaders); | 395 | 'status'=>$this->cache->getStatus(), 'parameters'=>$paramHeaders); |
396 | } | 396 | } |
397 | - | ||
398 | - public function initFromTT($id, $typeTT) | 397 | + |
398 | + public function initFromTT($id, $typeTT) | ||
399 | { | 399 | { |
400 | //Create new cache | 400 | //Create new cache |
401 | $this->cache = new CatalogCacheObject(); | 401 | $this->cache = new CatalogCacheObject(); |
402 | 402 | ||
403 | //Load intervals from catalog file and add to cache | 403 | //Load intervals from catalog file and add to cache |
404 | $intervals_res = $this->ttMgr->loadIntervalsFromTT($id,$typeTT); | 404 | $intervals_res = $this->ttMgr->loadIntervalsFromTT($id,$typeTT); |
405 | - | 405 | + |
406 | if (!$intervals_res['success']) | 406 | if (!$intervals_res['success']) |
407 | return $intervals_res; | 407 | return $intervals_res; |
408 | 408 | ||
@@ -411,13 +411,13 @@ class CatalogCacheMgr extends TimeTableCacheMgr | @@ -411,13 +411,13 @@ class CatalogCacheMgr extends TimeTableCacheMgr | ||
411 | //Add interval | 411 | //Add interval |
412 | $this->cache->addInterval($interval['start'], $interval['stop'], $interval['paramTable']); | 412 | $this->cache->addInterval($interval['start'], $interval['stop'], $interval['paramTable']); |
413 | } | 413 | } |
414 | - | 414 | + |
415 | $paramHeaders = $intervals_res['parameters']; | 415 | $paramHeaders = $intervals_res['parameters']; |
416 | - | 416 | + |
417 | $this->cache->setParamsNumber(count($paramHeaders)); | 417 | $this->cache->setParamsNumber(count($paramHeaders)); |
418 | $this->cache->setParamsSizes($paramHeaders); | 418 | $this->cache->setParamsSizes($paramHeaders); |
419 | $this->cache->setParamsTypes($paramHeaders); | 419 | $this->cache->setParamsTypes($paramHeaders); |
420 | - | 420 | + |
421 | unset($intervals_res); | 421 | unset($intervals_res); |
422 | 422 | ||
423 | //Update cache | 423 | //Update cache |
@@ -429,8 +429,8 @@ class CatalogCacheMgr extends TimeTableCacheMgr | @@ -429,8 +429,8 @@ class CatalogCacheMgr extends TimeTableCacheMgr | ||
429 | } | 429 | } |
430 | 430 | ||
431 | 431 | ||
432 | - protected function loadFromFile() | ||
433 | - { | 432 | + protected function loadFromFile() |
433 | + { | ||
434 | if (!file_exists($this->getCacheFilePath())) | 434 | if (!file_exists($this->getCacheFilePath())) |
435 | return false; | 435 | return false; |
436 | $this->cache = new CatalogCacheObject(); | 436 | $this->cache = new CatalogCacheObject(); |
@@ -445,30 +445,30 @@ class CatalogCacheMgr extends TimeTableCacheMgr | @@ -445,30 +445,30 @@ class CatalogCacheMgr extends TimeTableCacheMgr | ||
445 | fclose($handle); | 445 | fclose($handle); |
446 | return $result; | 446 | return $result; |
447 | } | 447 | } |
448 | - | ||
449 | - protected function getCacheFilePath() | 448 | + |
449 | + protected function getCacheFilePath() | ||
450 | { | 450 | { |
451 | return USERTTDIR.(self::$cache_file); | 451 | return USERTTDIR.(self::$cache_file); |
452 | } | 452 | } |
453 | 453 | ||
454 | - public function saveInTT($id, $action, $token) | ||
455 | - { | 454 | + public function saveInTT($id, $action, $token) |
455 | + { | ||
456 | if (!$this->loadFromFile()) | 456 | if (!$this->loadFromFile()) |
457 | return array('success' => false, 'message' => 'Cannot load cache file'); | 457 | return array('success' => false, 'message' => 'Cannot load cache file'); |
458 | 458 | ||
459 | if ($token != $this->cache->getToken()) | 459 | if ($token != $this->cache->getToken()) |
460 | return array('success' => false, 'message' => 'Cache token check error'); | 460 | return array('success' => false, 'message' => 'Cache token check error'); |
461 | - | 461 | + |
462 | $this->cache->updateIndexes(); | 462 | $this->cache->updateIndexes(); |
463 | $this->saveToFile(); | 463 | $this->saveToFile(); |
464 | - | 464 | + |
465 | $intervals = $this->cache->getIntervalsArray(NULL,NULL,true); | 465 | $intervals = $this->cache->getIntervalsArray(NULL,NULL,true); |
466 | - | 466 | + |
467 | $this->cache->reset(); | 467 | $this->cache->reset(); |
468 | 468 | ||
469 | return $this->ttMgr->saveIntervals($id, $intervals, $action); | 469 | return $this->ttMgr->saveIntervals($id, $intervals, $action); |
470 | } | 470 | } |
471 | - | 471 | + |
472 | public function addInterval($index, $start, $stop, $params) { | 472 | public function addInterval($index, $start, $stop, $params) { |
473 | if (!$this->loadFromFile()) | 473 | if (!$this->loadFromFile()) |
474 | return array('success' => false, 'message' => 'Cannot load cache file'); | 474 | return array('success' => false, 'message' => 'Cannot load cache file'); |
@@ -481,42 +481,42 @@ class CatalogCacheMgr extends TimeTableCacheMgr | @@ -481,42 +481,42 @@ class CatalogCacheMgr extends TimeTableCacheMgr | ||
481 | 481 | ||
482 | if (!isset($stop)) | 482 | if (!isset($stop)) |
483 | $stop = date('Y-m-d\TH:i:s'); | 483 | $stop = date('Y-m-d\TH:i:s'); |
484 | - | 484 | + |
485 | if (!isset($params)) | 485 | if (!isset($params)) |
486 | - $params = []; | ||
487 | - | 486 | + $params = []; |
487 | + | ||
488 | $this->cache->addInterval($start, $stop, $params, true, $index); | 488 | $this->cache->addInterval($start, $stop, $params, true, $index); |
489 | - | 489 | + |
490 | //$this->cache->updateIndexes(); | 490 | //$this->cache->updateIndexes(); |
491 | - | 491 | + |
492 | $this->saveToFile(); | 492 | $this->saveToFile(); |
493 | - | 493 | + |
494 | return array('success' => true, 'index' => $index, 'status' => $this->cache->getStatus()); | 494 | return array('success' => true, 'index' => $index, 'status' => $this->cache->getStatus()); |
495 | } | 495 | } |
496 | - | 496 | + |
497 | public function modifyIntervalFromId($obj) { | 497 | public function modifyIntervalFromId($obj) { |
498 | if (!$this->loadFromFile()) | 498 | if (!$this->loadFromFile()) |
499 | return array('success' => false, 'message' => 'Cannot load cache file'); | 499 | return array('success' => false, 'message' => 'Cannot load cache file'); |
500 | 500 | ||
501 | $this->cache->modifyIntervalFromId($obj); | 501 | $this->cache->modifyIntervalFromId($obj); |
502 | - | 502 | + |
503 | $this->saveToFile(); | 503 | $this->saveToFile(); |
504 | - | 504 | + |
505 | return array('success' => true, 'status' => $this->cache->getStatus()); | 505 | return array('success' => true, 'status' => $this->cache->getStatus()); |
506 | } | 506 | } |
507 | - | 507 | + |
508 | public function initTTCache($nparams) { | 508 | public function initTTCache($nparams) { |
509 | //Create new cache | 509 | //Create new cache |
510 | $this->cache = new CatalogCacheObject(); | 510 | $this->cache = new CatalogCacheObject(); |
511 | $this->cache->setParamsNumber((int)$nparams); | 511 | $this->cache->setParamsNumber((int)$nparams); |
512 | $paramHeaders = array(); | 512 | $paramHeaders = array(); |
513 | - | 513 | + |
514 | for ($i = 0; $i < (int)$nparams; $i++) { | 514 | for ($i = 0; $i < (int)$nparams; $i++) { |
515 | $paramHeaders[$i]['id'] = 'id_'.(string)($i+1); | 515 | $paramHeaders[$i]['id'] = 'id_'.(string)($i+1); |
516 | $paramHeaders[$i]['name'] = 'param_'.(string)($i+1); | 516 | $paramHeaders[$i]['name'] = 'param_'.(string)($i+1); |
517 | $paramHeaders[$i]['size'] = 1; | 517 | $paramHeaders[$i]['size'] = 1; |
518 | $paramHeaders[$i]['type'] = 'Float'; | 518 | $paramHeaders[$i]['type'] = 'Float'; |
519 | - | 519 | + |
520 | } | 520 | } |
521 | $this->cache->setParamsSizes($paramHeaders); | 521 | $this->cache->setParamsSizes($paramHeaders); |
522 | $this->cache->setParamsTypes($paramHeaders); | 522 | $this->cache->setParamsTypes($paramHeaders); |
@@ -525,4 +525,4 @@ class CatalogCacheMgr extends TimeTableCacheMgr | @@ -525,4 +525,4 @@ class CatalogCacheMgr extends TimeTableCacheMgr | ||
525 | 'status' => $this->cache->getStatus(), 'parameters' => $paramHeaders); | 525 | 'status' => $this->cache->getStatus(), 'parameters' => $paramHeaders); |
526 | } | 526 | } |
527 | } | 527 | } |
528 | -?> | ||
529 | \ No newline at end of file | 528 | \ No newline at end of file |
529 | +?> |
php/classes/IntervalCacheObject.php
@@ -16,11 +16,11 @@ class IntervalCacheObject | @@ -16,11 +16,11 @@ class IntervalCacheObject | ||
16 | public function getId() { | 16 | public function getId() { |
17 | return $this->id; | 17 | return $this->id; |
18 | } | 18 | } |
19 | - | 19 | + |
20 | public function getIndex() { | 20 | public function getIndex() { |
21 | return $this->index; | 21 | return $this->index; |
22 | } | 22 | } |
23 | - | 23 | + |
24 | public function setIndex($index) { | 24 | public function setIndex($index) { |
25 | $this->index = $index; | 25 | $this->index = $index; |
26 | } | 26 | } |
@@ -28,35 +28,35 @@ class IntervalCacheObject | @@ -28,35 +28,35 @@ class IntervalCacheObject | ||
28 | public function getStartToStamp() { | 28 | public function getStartToStamp() { |
29 | return $this->start; | 29 | return $this->start; |
30 | } | 30 | } |
31 | - | 31 | + |
32 | public function getStartToISO() { | 32 | public function getStartToISO() { |
33 | - return CacheTools::stamp2iso($this->start); | 33 | + return TimeUtils::stamp2iso($this->start); |
34 | } | 34 | } |
35 | 35 | ||
36 | public function setStartFromStamp($stamp) { | 36 | public function setStartFromStamp($stamp) { |
37 | $this->start = $stamp; | 37 | $this->start = $stamp; |
38 | } | 38 | } |
39 | - | 39 | + |
40 | public function setStartFromISO($iso) { | 40 | public function setStartFromISO($iso) { |
41 | - $this->start = CacheTools::iso2stamp($iso); | 41 | + $this->start = TimeUtils::iso2stamp($iso); |
42 | } | 42 | } |
43 | 43 | ||
44 | public function getStopToStamp() { | 44 | public function getStopToStamp() { |
45 | return $this->stop; | 45 | return $this->stop; |
46 | } | 46 | } |
47 | - | 47 | + |
48 | public function getStopToISO() { | 48 | public function getStopToISO() { |
49 | - return CacheTools::stamp2iso($this->stop); | 49 | + return TimeUtils::stamp2iso($this->stop); |
50 | } | 50 | } |
51 | 51 | ||
52 | public function setStopFromStamp($stamp) { | 52 | public function setStopFromStamp($stamp) { |
53 | $this->stop = $stamp; | 53 | $this->stop = $stamp; |
54 | } | 54 | } |
55 | - | 55 | + |
56 | public function setStopFromISO($iso) { | 56 | public function setStopFromISO($iso) { |
57 | - $this->stop = CacheTools::iso2stamp($iso); | 57 | + $this->stop = TimeUtils::iso2stamp($iso); |
58 | } | 58 | } |
59 | - | 59 | + |
60 | public function getDuration() { | 60 | public function getDuration() { |
61 | return ($this->stop-$this->start); | 61 | return ($this->stop-$this->start); |
62 | } | 62 | } |
@@ -76,7 +76,7 @@ class IntervalCacheObject | @@ -76,7 +76,7 @@ class IntervalCacheObject | ||
76 | public function setIsNew($isNew) { | 76 | public function setIsNew($isNew) { |
77 | $this->isNew = $isNew; | 77 | $this->isNew = $isNew; |
78 | } | 78 | } |
79 | - | 79 | + |
80 | public function toArray() { | 80 | public function toArray() { |
81 | $result = array( | 81 | $result = array( |
82 | "cacheId" => $this->id, | 82 | "cacheId" => $this->id, |
@@ -87,16 +87,16 @@ class IntervalCacheObject | @@ -87,16 +87,16 @@ class IntervalCacheObject | ||
87 | $result["isNew"] = true; | 87 | $result["isNew"] = true; |
88 | if ($this->isModified) | 88 | if ($this->isModified) |
89 | $result["isModified"] = true; | 89 | $result["isModified"] = true; |
90 | - | 90 | + |
91 | return $result; | 91 | return $result; |
92 | } | 92 | } |
93 | 93 | ||
94 | - | ||
95 | - | 94 | + |
95 | + | ||
96 | public function writeBin($handle) { | 96 | public function writeBin($handle) { |
97 | fwrite($handle,pack('L6',$this->id,$this->index,$this->start,$this->stop,$this->isNew,$this->isModified)); | 97 | fwrite($handle,pack('L6',$this->id,$this->index,$this->start,$this->stop,$this->isNew,$this->isModified)); |
98 | } | 98 | } |
99 | - | 99 | + |
100 | public function loadBin($handle) { | 100 | public function loadBin($handle) { |
101 | $array = unpack('L6int',fread($handle,6*4)); | 101 | $array = unpack('L6int',fread($handle,6*4)); |
102 | $this->id = $array['int1']; | 102 | $this->id = $array['int1']; |
@@ -106,7 +106,7 @@ class IntervalCacheObject | @@ -106,7 +106,7 @@ class IntervalCacheObject | ||
106 | $this->isNew = $array['int5']; | 106 | $this->isNew = $array['int5']; |
107 | $this->isModified = $array['int6']; | 107 | $this->isModified = $array['int6']; |
108 | } | 108 | } |
109 | - | 109 | + |
110 | public function dump() { | 110 | public function dump() { |
111 | echo " => Interval : id = ".$this->id.", index = ".$this->index.", start = ".$this->start.", stop = ".$this->stop.", isNew = ".$this->isNew.", isModified = ".$this->isModified.PHP_EOL; | 111 | echo " => Interval : id = ".$this->id.", index = ".$this->index.", start = ".$this->start.", stop = ".$this->stop.", isNew = ".$this->isNew.", isModified = ".$this->isModified.PHP_EOL; |
112 | } | 112 | } |
php/classes/TimeTableCacheMgr.php
1 | <?php | 1 | <?php |
2 | -class CacheTools | ||
3 | -{ | ||
4 | - public static function iso2stamp($iso) { | ||
5 | - try { | ||
6 | - $time = new DateTime($iso); | ||
7 | - } | ||
8 | - catch (Exception $e) { | ||
9 | - $time = new DateTime('1970-01-01T00:00:00Z'); | ||
10 | - } | ||
11 | - $stamp = $time->format('U'); | ||
12 | - unset($time); | ||
13 | - return $stamp; | ||
14 | - } | ||
15 | - | ||
16 | - public static function stamp2iso($stamp) { | ||
17 | - return date('Y-m-d\TH:i:s',$stamp); | ||
18 | - } | ||
19 | -} | ||
20 | 2 | ||
21 | class SortPartCacheObject | 3 | class SortPartCacheObject |
22 | { | 4 | { |
@@ -26,31 +8,31 @@ class SortPartCacheObject | @@ -26,31 +8,31 @@ class SortPartCacheObject | ||
26 | public static $TYPE_DURATION_SEC = 3; | 8 | public static $TYPE_DURATION_SEC = 3; |
27 | public static $TYPE_DURATION_MIN = 4; | 9 | public static $TYPE_DURATION_MIN = 4; |
28 | public static $TYPE_DURATION_HOUR = 5; | 10 | public static $TYPE_DURATION_HOUR = 5; |
29 | - | 11 | + |
30 | public static $DIRECTION_UNKNOWN = 0; | 12 | public static $DIRECTION_UNKNOWN = 0; |
31 | public static $DIRECTION_ASC = 1; | 13 | public static $DIRECTION_ASC = 1; |
32 | public static $DIRECTION_DES = 2; | 14 | public static $DIRECTION_DES = 2; |
33 | - | 15 | + |
34 | protected $type; | 16 | protected $type; |
35 | protected $dir; | 17 | protected $dir; |
36 | - | 18 | + |
37 | function __construct() { | 19 | function __construct() { |
38 | $this->type = self::$TYPE_UNKNOWN; | 20 | $this->type = self::$TYPE_UNKNOWN; |
39 | $this->dir = self::$DIRECTION_UNKNOWN; | 21 | $this->dir = self::$DIRECTION_UNKNOWN; |
40 | } | 22 | } |
41 | - | 23 | + |
42 | public function getType() { | 24 | public function getType() { |
43 | return $this->type; | 25 | return $this->type; |
44 | } | 26 | } |
45 | - | 27 | + |
46 | public function getDir() { | 28 | public function getDir() { |
47 | return $this->dir; | 29 | return $this->dir; |
48 | } | 30 | } |
49 | - | 31 | + |
50 | public function isSame($part) { | 32 | public function isSame($part) { |
51 | return (($this->type == $part->getType()) && ($this->dir == $part->getDir())); | 33 | return (($this->type == $part->getType()) && ($this->dir == $part->getDir())); |
52 | } | 34 | } |
53 | - | 35 | + |
54 | public function compare($interval_a, $interval_b) { | 36 | public function compare($interval_a, $interval_b) { |
55 | switch ($this->type) { | 37 | switch ($this->type) { |
56 | case self::$TYPE_START : | 38 | case self::$TYPE_START : |
@@ -59,7 +41,7 @@ class SortPartCacheObject | @@ -59,7 +41,7 @@ class SortPartCacheObject | ||
59 | case self::$DIRECTION_ASC : | 41 | case self::$DIRECTION_ASC : |
60 | return ($interval_b->getStartToStamp() - $interval_a->getStartToStamp()); | 42 | return ($interval_b->getStartToStamp() - $interval_a->getStartToStamp()); |
61 | default : | 43 | default : |
62 | - return ($interval_a->getStartToStamp() - $interval_b->getStartToStamp()); | 44 | + return ($interval_a->getStartToStamp() - $interval_b->getStartToStamp()); |
63 | } | 45 | } |
64 | } | 46 | } |
65 | break; | 47 | break; |
@@ -90,7 +72,7 @@ class SortPartCacheObject | @@ -90,7 +72,7 @@ class SortPartCacheObject | ||
90 | } | 72 | } |
91 | return 0; | 73 | return 0; |
92 | } | 74 | } |
93 | - | 75 | + |
94 | public function loadFromObject($part_obj) { | 76 | public function loadFromObject($part_obj) { |
95 | switch ($part_obj->property) | 77 | switch ($part_obj->property) |
96 | { | 78 | { |
@@ -112,7 +94,7 @@ class SortPartCacheObject | @@ -112,7 +94,7 @@ class SortPartCacheObject | ||
112 | default: | 94 | default: |
113 | $this->type = self::$TYPE_UNKNOWN; | 95 | $this->type = self::$TYPE_UNKNOWN; |
114 | } | 96 | } |
115 | - | 97 | + |
116 | switch ($part_obj->direction) | 98 | switch ($part_obj->direction) |
117 | { | 99 | { |
118 | case 'ASC' : | 100 | case 'ASC' : |
@@ -125,17 +107,17 @@ class SortPartCacheObject | @@ -125,17 +107,17 @@ class SortPartCacheObject | ||
125 | $this->dir = self::$DIRECTION_UNKNOWN; | 107 | $this->dir = self::$DIRECTION_UNKNOWN; |
126 | } | 108 | } |
127 | } | 109 | } |
128 | - | 110 | + |
129 | public function writeBin($handle) { | 111 | public function writeBin($handle) { |
130 | fwrite($handle,pack('L2',$this->type,$this->dir)); | 112 | fwrite($handle,pack('L2',$this->type,$this->dir)); |
131 | } | 113 | } |
132 | - | 114 | + |
133 | public function loadBin($handle) { | 115 | public function loadBin($handle) { |
134 | $res = unpack('L2data',fread($handle,4*2)); | 116 | $res = unpack('L2data',fread($handle,4*2)); |
135 | $this->type = $res['data1']; | 117 | $this->type = $res['data1']; |
136 | $this->dir = $res['data2']; | 118 | $this->dir = $res['data2']; |
137 | } | 119 | } |
138 | - | 120 | + |
139 | public function dump() { | 121 | public function dump() { |
140 | echo " => SortPartCacheObject : type = "; | 122 | echo " => SortPartCacheObject : type = "; |
141 | switch ($this->type) | 123 | switch ($this->type) |
@@ -202,7 +184,7 @@ class SortCacheObject | @@ -202,7 +184,7 @@ class SortCacheObject | ||
202 | array_push($this->parts, $part); | 184 | array_push($this->parts, $part); |
203 | } | 185 | } |
204 | } | 186 | } |
205 | - | 187 | + |
206 | public function isSameFromObject($sort_obj) { | 188 | public function isSameFromObject($sort_obj) { |
207 | $sort = new SortCacheObject(); | 189 | $sort = new SortCacheObject(); |
208 | $sort->loadFromObject($sort_obj); | 190 | $sort->loadFromObject($sort_obj); |
@@ -221,23 +203,23 @@ class SortCacheObject | @@ -221,23 +203,23 @@ class SortCacheObject | ||
221 | return false; | 203 | return false; |
222 | } | 204 | } |
223 | } | 205 | } |
224 | - | 206 | + |
225 | return true; | 207 | return true; |
226 | } | 208 | } |
227 | 209 | ||
228 | public function apply($intervals) { | 210 | public function apply($intervals) { |
229 | $sorted_indexes = array(); | 211 | $sorted_indexes = array(); |
230 | - | 212 | + |
231 | global $global_parts, $global_intervals; | 213 | global $global_parts, $global_intervals; |
232 | $global_parts = $this->parts; | 214 | $global_parts = $this->parts; |
233 | $global_intervals = $intervals; | 215 | $global_intervals = $intervals; |
234 | - | 216 | + |
235 | foreach ($intervals as $interval) | 217 | foreach ($intervals as $interval) |
236 | array_push($sorted_indexes, $interval->getIndex()); | 218 | array_push($sorted_indexes, $interval->getIndex()); |
237 | - | 219 | + |
238 | if (count($global_parts) == 0) | 220 | if (count($global_parts) == 0) |
239 | return $sorted_indexes; | 221 | return $sorted_indexes; |
240 | - | 222 | + |
241 | usort($sorted_indexes, function ($index_a, $index_b) { | 223 | usort($sorted_indexes, function ($index_a, $index_b) { |
242 | global $global_parts, $global_intervals; | 224 | global $global_parts, $global_intervals; |
243 | foreach ($global_parts as $part) | 225 | foreach ($global_parts as $part) |
@@ -284,38 +266,38 @@ class FilterPartCacheObject | @@ -284,38 +266,38 @@ class FilterPartCacheObject | ||
284 | public static $TYPE_DURATION_SEC = 3; | 266 | public static $TYPE_DURATION_SEC = 3; |
285 | public static $TYPE_DURATION_MIN = 4; | 267 | public static $TYPE_DURATION_MIN = 4; |
286 | public static $TYPE_DURATION_HOUR = 5; | 268 | public static $TYPE_DURATION_HOUR = 5; |
287 | - | 269 | + |
288 | public static $OPERATION_UNKNOWN = 0; | 270 | public static $OPERATION_UNKNOWN = 0; |
289 | public static $OPERATION_LT = 1; | 271 | public static $OPERATION_LT = 1; |
290 | public static $OPERATION_GT = 2; | 272 | public static $OPERATION_GT = 2; |
291 | public static $OPERATION_EQ = 3; | 273 | public static $OPERATION_EQ = 3; |
292 | - | 274 | + |
293 | protected $type; | 275 | protected $type; |
294 | protected $op; | 276 | protected $op; |
295 | protected $value; | 277 | protected $value; |
296 | - | 278 | + |
297 | function __construct() { | 279 | function __construct() { |
298 | $this->type = self::$TYPE_UNKNOWN; | 280 | $this->type = self::$TYPE_UNKNOWN; |
299 | $this->op = self::$OPERATION_UNKNOWN; | 281 | $this->op = self::$OPERATION_UNKNOWN; |
300 | $this->value = 0.; | 282 | $this->value = 0.; |
301 | } | 283 | } |
302 | - | 284 | + |
303 | public function getType() { | 285 | public function getType() { |
304 | return $this->type; | 286 | return $this->type; |
305 | } | 287 | } |
306 | - | 288 | + |
307 | public function getOp() { | 289 | public function getOp() { |
308 | return $this->op; | 290 | return $this->op; |
309 | } | 291 | } |
310 | - | 292 | + |
311 | public function getValue() { | 293 | public function getValue() { |
312 | return $this->value; | 294 | return $this->value; |
313 | } | 295 | } |
314 | - | 296 | + |
315 | public function isSame($part) { | 297 | public function isSame($part) { |
316 | return (($this->type == $part->getType()) && ($this->op == $part->getOp()) && ($this->value == $part->getValue())); | 298 | return (($this->type == $part->getType()) && ($this->op == $part->getOp()) && ($this->value == $part->getValue())); |
317 | } | 299 | } |
318 | - | 300 | + |
319 | public function toFiltered($interval) { | 301 | public function toFiltered($interval) { |
320 | switch ($this->type) { | 302 | switch ($this->type) { |
321 | case self::$TYPE_START : | 303 | case self::$TYPE_START : |
@@ -371,17 +353,17 @@ class FilterPartCacheObject | @@ -371,17 +353,17 @@ class FilterPartCacheObject | ||
371 | return false; | 353 | return false; |
372 | } | 354 | } |
373 | } | 355 | } |
374 | - | 356 | + |
375 | public function loadFromObject($part_obj) { | 357 | public function loadFromObject($part_obj) { |
376 | $this->value = 0.; | 358 | $this->value = 0.; |
377 | switch ($part_obj->field) | 359 | switch ($part_obj->field) |
378 | { | 360 | { |
379 | case 'start' : | 361 | case 'start' : |
380 | - $this->value = CacheTools::iso2stamp($part_obj->value); | 362 | + $this->value = TimeUtils::iso2stamp($part_obj->value); |
381 | $this->type = self::$TYPE_START; | 363 | $this->type = self::$TYPE_START; |
382 | break; | 364 | break; |
383 | case 'stop' : | 365 | case 'stop' : |
384 | - $this->value = CacheTools::iso2stamp($part_obj->value); | 366 | + $this->value = TimeUtils::iso2stamp($part_obj->value); |
385 | $this->type = self::$TYPE_STOP; | 367 | $this->type = self::$TYPE_STOP; |
386 | break; | 368 | break; |
387 | case 'durationMin' : | 369 | case 'durationMin' : |
@@ -400,7 +382,7 @@ class FilterPartCacheObject | @@ -400,7 +382,7 @@ class FilterPartCacheObject | ||
400 | $this->value = 0.; | 382 | $this->value = 0.; |
401 | $this->type = self::$TYPE_UNKNOWN; | 383 | $this->type = self::$TYPE_UNKNOWN; |
402 | } | 384 | } |
403 | - | 385 | + |
404 | switch ($part_obj->comparison) | 386 | switch ($part_obj->comparison) |
405 | { | 387 | { |
406 | case 'lt' : | 388 | case 'lt' : |
@@ -416,21 +398,21 @@ class FilterPartCacheObject | @@ -416,21 +398,21 @@ class FilterPartCacheObject | ||
416 | $this->op = self::$OPERATION_UNKNOWN; | 398 | $this->op = self::$OPERATION_UNKNOWN; |
417 | } | 399 | } |
418 | } | 400 | } |
419 | - | 401 | + |
420 | public function writeBin($handle) { | 402 | public function writeBin($handle) { |
421 | fwrite($handle,pack('L2',$this->type,$this->op)); | 403 | fwrite($handle,pack('L2',$this->type,$this->op)); |
422 | fwrite($handle,pack('f',$this->value)); | 404 | fwrite($handle,pack('f',$this->value)); |
423 | } | 405 | } |
424 | - | 406 | + |
425 | public function loadBin($handle) { | 407 | public function loadBin($handle) { |
426 | $res = unpack('L2data',fread($handle,4*2)); | 408 | $res = unpack('L2data',fread($handle,4*2)); |
427 | $this->type = $res['data1']; | 409 | $this->type = $res['data1']; |
428 | $this->op = $res['data2']; | 410 | $this->op = $res['data2']; |
429 | - | 411 | + |
430 | $res = unpack('fvalue',fread($handle,4)); | 412 | $res = unpack('fvalue',fread($handle,4)); |
431 | $this->value = $res['value']; | 413 | $this->value = $res['value']; |
432 | } | 414 | } |
433 | - | 415 | + |
434 | public function dump() { | 416 | public function dump() { |
435 | echo " => FilterPartCacheObject : type = "; | 417 | echo " => FilterPartCacheObject : type = "; |
436 | switch ($this->type) | 418 | switch ($this->type) |
@@ -475,27 +457,27 @@ class FilterPartCacheObject | @@ -475,27 +457,27 @@ class FilterPartCacheObject | ||
475 | class FilterCacheObject | 457 | class FilterCacheObject |
476 | { | 458 | { |
477 | protected $parts = array(); | 459 | protected $parts = array(); |
478 | - | 460 | + |
479 | function __construct() { | 461 | function __construct() { |
480 | - | 462 | + |
481 | } | 463 | } |
482 | - | 464 | + |
483 | public function getParts() { | 465 | public function getParts() { |
484 | return $this->parts; | 466 | return $this->parts; |
485 | } | 467 | } |
486 | - | 468 | + |
487 | public function reset() { | 469 | public function reset() { |
488 | $this->parts = array(); | 470 | $this->parts = array(); |
489 | } | 471 | } |
490 | - | 472 | + |
491 | public function isEmpty() { | 473 | public function isEmpty() { |
492 | return (count($this->parts) == 0); | 474 | return (count($this->parts) == 0); |
493 | } | 475 | } |
494 | - | 476 | + |
495 | public function loadFromJSON($filter_json) { | 477 | public function loadFromJSON($filter_json) { |
496 | $this->reset(); | 478 | $this->reset(); |
497 | $filter_obj = json_decode($filter_json); | 479 | $filter_obj = json_decode($filter_json); |
498 | - | 480 | + |
499 | foreach ($filter_obj as $filter_part) | 481 | foreach ($filter_obj as $filter_part) |
500 | { | 482 | { |
501 | $part = new FilterPartCacheObject(); | 483 | $part = new FilterPartCacheObject(); |
@@ -503,11 +485,11 @@ class FilterCacheObject | @@ -503,11 +485,11 @@ class FilterCacheObject | ||
503 | array_push($this->parts, $part); | 485 | array_push($this->parts, $part); |
504 | } | 486 | } |
505 | } | 487 | } |
506 | - | 488 | + |
507 | public function isSame($filter) { | 489 | public function isSame($filter) { |
508 | if (count($this->parts) != count($filter->getParts())) | 490 | if (count($this->parts) != count($filter->getParts())) |
509 | return false; | 491 | return false; |
510 | - | 492 | + |
511 | $identique = true; | 493 | $identique = true; |
512 | for ($i = 0; $i < count($this->parts); ++$i) | 494 | for ($i = 0; $i < count($this->parts); ++$i) |
513 | { | 495 | { |
@@ -516,16 +498,16 @@ class FilterCacheObject | @@ -516,16 +498,16 @@ class FilterCacheObject | ||
516 | return false; | 498 | return false; |
517 | } | 499 | } |
518 | } | 500 | } |
519 | - | 501 | + |
520 | return true; | 502 | return true; |
521 | } | 503 | } |
522 | - | 504 | + |
523 | public function isSameFromJSON($filter_json) { | 505 | public function isSameFromJSON($filter_json) { |
524 | $filter = new FilterCacheObject(); | 506 | $filter = new FilterCacheObject(); |
525 | $filter->loadFromJSON($filter_json); | 507 | $filter->loadFromJSON($filter_json); |
526 | return $this->isSame($filter); | 508 | return $this->isSame($filter); |
527 | } | 509 | } |
528 | - | 510 | + |
529 | public function toFiltered($interval) { | 511 | public function toFiltered($interval) { |
530 | foreach ($this->parts as $part) | 512 | foreach ($this->parts as $part) |
531 | { | 513 | { |
@@ -534,13 +516,13 @@ class FilterCacheObject | @@ -534,13 +516,13 @@ class FilterCacheObject | ||
534 | } | 516 | } |
535 | return false; | 517 | return false; |
536 | } | 518 | } |
537 | - | 519 | + |
538 | public function writeBin($handle) { | 520 | public function writeBin($handle) { |
539 | fwrite($handle,pack('L',count($this->parts))); | 521 | fwrite($handle,pack('L',count($this->parts))); |
540 | foreach ($this->parts as $part) | 522 | foreach ($this->parts as $part) |
541 | $part->writeBin($handle); | 523 | $part->writeBin($handle); |
542 | } | 524 | } |
543 | - | 525 | + |
544 | public function loadBin($handle) { | 526 | public function loadBin($handle) { |
545 | $this->reset(); | 527 | $this->reset(); |
546 | $res = unpack('Lcount',fread($handle,4)); | 528 | $res = unpack('Lcount',fread($handle,4)); |
@@ -551,7 +533,7 @@ class FilterCacheObject | @@ -551,7 +533,7 @@ class FilterCacheObject | ||
551 | array_push($this->parts, $part); | 533 | array_push($this->parts, $part); |
552 | } | 534 | } |
553 | } | 535 | } |
554 | - | 536 | + |
555 | public function dump() { | 537 | public function dump() { |
556 | echo " => FilterCacheObject : number of parts = ".count($this->parts).PHP_EOL; | 538 | echo " => FilterCacheObject : number of parts = ".count($this->parts).PHP_EOL; |
557 | foreach ($this->parts as $part) | 539 | foreach ($this->parts as $part) |
@@ -562,7 +544,7 @@ class FilterCacheObject | @@ -562,7 +544,7 @@ class FilterCacheObject | ||
562 | class TimeTableCacheMgr | 544 | class TimeTableCacheMgr |
563 | { | 545 | { |
564 | protected static $cache_file = "cacheTT"; | 546 | protected static $cache_file = "cacheTT"; |
565 | - | 547 | + |
566 | protected $ttMgr = null; | 548 | protected $ttMgr = null; |
567 | protected $cache = null; | 549 | protected $cache = null; |
568 | 550 | ||
@@ -574,7 +556,7 @@ class FilterCacheObject | @@ -574,7 +556,7 @@ class FilterCacheObject | ||
574 | public function initTTCache() { | 556 | public function initTTCache() { |
575 | //Create new cache | 557 | //Create new cache |
576 | $this->cache = new TimeTableCacheObject(); | 558 | $this->cache = new TimeTableCacheObject(); |
577 | - | 559 | + |
578 | //Save cache file | 560 | //Save cache file |
579 | return array('success' => $this->saveToFile(), 'token' => $this->cache->getToken(), 'status' => $this->cache->getStatus()); | 561 | return array('success' => $this->saveToFile(), 'token' => $this->cache->getToken(), 'status' => $this->cache->getStatus()); |
580 | } | 562 | } |
@@ -585,7 +567,7 @@ class FilterCacheObject | @@ -585,7 +567,7 @@ class FilterCacheObject | ||
585 | 567 | ||
586 | //Load intervals from TT file and add to cache | 568 | //Load intervals from TT file and add to cache |
587 | $intervals_res = $this->ttMgr->loadIntervalsFromTT($id,$typeTT); | 569 | $intervals_res = $this->ttMgr->loadIntervalsFromTT($id,$typeTT); |
588 | - | 570 | + |
589 | if (!$intervals_res['success']) | 571 | if (!$intervals_res['success']) |
590 | return $intervals_res; | 572 | return $intervals_res; |
591 | 573 | ||
@@ -594,7 +576,7 @@ class FilterCacheObject | @@ -594,7 +576,7 @@ class FilterCacheObject | ||
594 | //Add interval | 576 | //Add interval |
595 | $this->cache->addInterval($interval['start'], $interval['stop']); | 577 | $this->cache->addInterval($interval['start'], $interval['stop']); |
596 | } | 578 | } |
597 | - | 579 | + |
598 | unset($intervals_res); | 580 | unset($intervals_res); |
599 | 581 | ||
600 | //Update cache | 582 | //Update cache |
@@ -650,9 +632,9 @@ class FilterCacheObject | @@ -650,9 +632,9 @@ class FilterCacheObject | ||
650 | } | 632 | } |
651 | 633 | ||
652 | $this->cache->setIsModified(true); | 634 | $this->cache->setIsModified(true); |
653 | - | 635 | + |
654 | unset($intervals_res); | 636 | unset($intervals_res); |
655 | - | 637 | + |
656 | //Update cache | 638 | //Update cache |
657 | $this->cache->updateIndexes(); | 639 | $this->cache->updateIndexes(); |
658 | 640 | ||
@@ -680,9 +662,9 @@ class FilterCacheObject | @@ -680,9 +662,9 @@ class FilterCacheObject | ||
680 | } | 662 | } |
681 | 663 | ||
682 | $this->cache->setIsModified(true); | 664 | $this->cache->setIsModified(true); |
683 | - | 665 | + |
684 | unset($intervals_res); | 666 | unset($intervals_res); |
685 | - | 667 | + |
686 | //Update cache | 668 | //Update cache |
687 | $this->cache->updateIndexes(); | 669 | $this->cache->updateIndexes(); |
688 | 670 | ||
@@ -696,14 +678,14 @@ class FilterCacheObject | @@ -696,14 +678,14 @@ class FilterCacheObject | ||
696 | 678 | ||
697 | if ($token != $this->cache->getToken()) | 679 | if ($token != $this->cache->getToken()) |
698 | return array('success' => false, 'message' => 'Cache token check error'); | 680 | return array('success' => false, 'message' => 'Cache token check error'); |
699 | - | 681 | + |
700 | $this->cache->updateIndexes(); | 682 | $this->cache->updateIndexes(); |
701 | $this->saveToFile(); | 683 | $this->saveToFile(); |
702 | - | 684 | + |
703 | $intervals = $this->cache->getIntervalsArray(NULL,NULL,true); | 685 | $intervals = $this->cache->getIntervalsArray(NULL,NULL,true); |
704 | - | 686 | + |
705 | $this->cache->reset(); | 687 | $this->cache->reset(); |
706 | - | 688 | + |
707 | $res_intervals = array(); | 689 | $res_intervals = array(); |
708 | foreach ($intervals as $interval) | 690 | foreach ($intervals as $interval) |
709 | { | 691 | { |
@@ -717,7 +699,7 @@ class FilterCacheObject | @@ -717,7 +699,7 @@ class FilterCacheObject | ||
717 | } | 699 | } |
718 | 700 | ||
719 | unset($intervals); | 701 | unset($intervals); |
720 | - | 702 | + |
721 | return $this->ttMgr->saveIntervals($id, $res_intervals, $action); | 703 | return $this->ttMgr->saveIntervals($id, $res_intervals, $action); |
722 | } | 704 | } |
723 | 705 | ||
@@ -742,7 +724,7 @@ class FilterCacheObject | @@ -742,7 +724,7 @@ class FilterCacheObject | ||
742 | $this->cache->getFilter()->reset(); | 724 | $this->cache->getFilter()->reset(); |
743 | } | 725 | } |
744 | } | 726 | } |
745 | - | 727 | + |
746 | if (isset($sort_obj)) | 728 | if (isset($sort_obj)) |
747 | { | 729 | { |
748 | if (!$this->cache->getSort()->isSameFromObject($sort_obj)) | 730 | if (!$this->cache->getSort()->isSameFromObject($sort_obj)) |
@@ -759,7 +741,7 @@ class FilterCacheObject | @@ -759,7 +741,7 @@ class FilterCacheObject | ||
759 | $this->cache->getSort()->reset(); | 741 | $this->cache->getSort()->reset(); |
760 | } | 742 | } |
761 | } | 743 | } |
762 | - | 744 | + |
763 | if ($needToUpdate) | 745 | if ($needToUpdate) |
764 | { | 746 | { |
765 | $this->cache->updateIndexes(); | 747 | $this->cache->updateIndexes(); |
@@ -789,13 +771,13 @@ class FilterCacheObject | @@ -789,13 +771,13 @@ class FilterCacheObject | ||
789 | 771 | ||
790 | if (!isset($stop)) | 772 | if (!isset($stop)) |
791 | $stop = date('Y-m-d\TH:i:s'); | 773 | $stop = date('Y-m-d\TH:i:s'); |
792 | - | 774 | + |
793 | $this->cache->addInterval($start, $stop, true, $index); | 775 | $this->cache->addInterval($start, $stop, true, $index); |
794 | - | 776 | + |
795 | //$this->cache->updateIndexes(); | 777 | //$this->cache->updateIndexes(); |
796 | - | 778 | + |
797 | $this->saveToFile(); | 779 | $this->saveToFile(); |
798 | - | 780 | + |
799 | return array('success' => true, 'index' => $index, 'status' => $this->cache->getStatus()); | 781 | return array('success' => true, 'index' => $index, 'status' => $this->cache->getStatus()); |
800 | } | 782 | } |
801 | 783 | ||
@@ -804,7 +786,7 @@ class FilterCacheObject | @@ -804,7 +786,7 @@ class FilterCacheObject | ||
804 | return array('success' => false, 'message' => 'Cannot load cache file'); | 786 | return array('success' => false, 'message' => 'Cannot load cache file'); |
805 | 787 | ||
806 | $this->cache->removeIntervalFromId($id); | 788 | $this->cache->removeIntervalFromId($id); |
807 | - | 789 | + |
808 | $this->cache->updateIndexes(); | 790 | $this->cache->updateIndexes(); |
809 | 791 | ||
810 | $this->saveToFile(); | 792 | $this->saveToFile(); |
@@ -817,38 +799,38 @@ class FilterCacheObject | @@ -817,38 +799,38 @@ class FilterCacheObject | ||
817 | return array('success' => false, 'message' => 'Cannot load cache file'); | 799 | return array('success' => false, 'message' => 'Cannot load cache file'); |
818 | 800 | ||
819 | $this->cache->modifyIntervalFromId($id, $start, $stop); | 801 | $this->cache->modifyIntervalFromId($id, $start, $stop); |
820 | - | 802 | + |
821 | $this->saveToFile(); | 803 | $this->saveToFile(); |
822 | - | 804 | + |
823 | return array('success' => true, 'status' => $this->cache->getStatus()); | 805 | return array('success' => true, 'status' => $this->cache->getStatus()); |
824 | } | 806 | } |
825 | - | 807 | + |
826 | public function operationIntervals($extendTime, $shiftTime) { | 808 | public function operationIntervals($extendTime, $shiftTime) { |
827 | if (!$this->loadFromFile()) | 809 | if (!$this->loadFromFile()) |
828 | return array('success' => false, 'message' => 'Cannot load cache file'); | 810 | return array('success' => false, 'message' => 'Cannot load cache file'); |
829 | - | 811 | + |
830 | $this->cache->operationIntervals($extendTime, $shiftTime); | 812 | $this->cache->operationIntervals($extendTime, $shiftTime); |
831 | - | 813 | + |
832 | $this->saveToFile(); | 814 | $this->saveToFile(); |
833 | - | 815 | + |
834 | return array('success' => true, 'status' => $this->cache->getStatus()); | 816 | return array('success' => true, 'status' => $this->cache->getStatus()); |
835 | } | 817 | } |
836 | - | 818 | + |
837 | public function mergeIntervals() { | 819 | public function mergeIntervals() { |
838 | if (!$this->loadFromFile()) | 820 | if (!$this->loadFromFile()) |
839 | return array('success' => false, 'message' => 'Cannot load cache file'); | 821 | return array('success' => false, 'message' => 'Cannot load cache file'); |
840 | - | 822 | + |
841 | $this->cache->mergeIntervals(); | 823 | $this->cache->mergeIntervals(); |
842 | - | 824 | + |
843 | $this->saveToFile(); | 825 | $this->saveToFile(); |
844 | - | 826 | + |
845 | return array('success' => true, 'status' => $this->cache->getStatus()); | 827 | return array('success' => true, 'status' => $this->cache->getStatus()); |
846 | } | 828 | } |
847 | - | 829 | + |
848 | public function getStatistics() { | 830 | public function getStatistics() { |
849 | if (!$this->loadFromFile()) | 831 | if (!$this->loadFromFile()) |
850 | return array('success' => false, 'message' => 'Cannot load cache file'); | 832 | return array('success' => false, 'message' => 'Cannot load cache file'); |
851 | - | 833 | + |
852 | return array('success' => true, "result" => $this->cache->getStatistics(), 'status' => $this->cache->getStatus()); | 834 | return array('success' => true, "result" => $this->cache->getStatistics(), 'status' => $this->cache->getStatus()); |
853 | } | 835 | } |
854 | 836 | ||
@@ -860,11 +842,11 @@ class FilterCacheObject | @@ -860,11 +842,11 @@ class FilterCacheObject | ||
860 | } | 842 | } |
861 | $this->cache->dump(); | 843 | $this->cache->dump(); |
862 | } | 844 | } |
863 | - | 845 | + |
864 | protected function getCacheFilePath() { | 846 | protected function getCacheFilePath() { |
865 | return USERTTDIR.(self::$cache_file); | 847 | return USERTTDIR.(self::$cache_file); |
866 | } | 848 | } |
867 | - | 849 | + |
868 | protected function saveToFile() { | 850 | protected function saveToFile() { |
869 | if (!isset($this->cache)) | 851 | if (!isset($this->cache)) |
870 | return false; | 852 | return false; |
@@ -879,7 +861,7 @@ class FilterCacheObject | @@ -879,7 +861,7 @@ class FilterCacheObject | ||
879 | fclose($handle); | 861 | fclose($handle); |
880 | return $result; | 862 | return $result; |
881 | } | 863 | } |
882 | - | 864 | + |
883 | protected function loadFromFile() { | 865 | protected function loadFromFile() { |
884 | if (!file_exists($this->getCacheFilePath())) | 866 | if (!file_exists($this->getCacheFilePath())) |
885 | return false; | 867 | return false; |
@@ -0,0 +1,22 @@ | @@ -0,0 +1,22 @@ | ||
1 | +<?php | ||
2 | + | ||
3 | +class TimeUtils | ||
4 | +{ | ||
5 | + public static function iso2stamp($iso) { | ||
6 | + try { | ||
7 | + $time = new DateTime($iso); | ||
8 | + } | ||
9 | + catch (Exception $e) { | ||
10 | + $time = new DateTime('1970-01-01T00:00:00Z'); | ||
11 | + } | ||
12 | + $stamp = $time->format('U'); | ||
13 | + unset($time); | ||
14 | + return $stamp; | ||
15 | + } | ||
16 | + | ||
17 | + public static function stamp2iso($stamp) { | ||
18 | + return date('Y-m-d\TH:i:s',$stamp); | ||
19 | + } | ||
20 | +} | ||
21 | + | ||
22 | +?> |