Commit 2a24088cb94976e35dc48e85d9d5c7115e18d8b3
1 parent
5446b8f0
Exists in
master
and in
101 other branches
Split some source files
Showing
6 changed files
with
853 additions
and
842 deletions
Show diff stats
@@ -0,0 +1,105 @@ | @@ -0,0 +1,105 @@ | ||
1 | +<?php | ||
2 | + | ||
3 | +class CatIntervalCacheObject extends IntervalCacheObject | ||
4 | +{ | ||
5 | + // for catalog | ||
6 | + private $params = array(); | ||
7 | + | ||
8 | + public function toArray() | ||
9 | + { | ||
10 | + $result = array( | ||
11 | + "cacheId" => $this->id, | ||
12 | + "start" => $this->getStartToISO(), | ||
13 | + "stop" => $this->getStopToISO() | ||
14 | + ); | ||
15 | + if ($this->isNew) | ||
16 | + $result["isNew"] = true; | ||
17 | + | ||
18 | + if ($this->isModified) | ||
19 | + $result["isModified"] = true; | ||
20 | + | ||
21 | + for ($i = 0; $i < count($this->params); $i++) | ||
22 | + { | ||
23 | + $paramObject = array(); | ||
24 | + $index = 'param'.sprintf("%d",$i+2); | ||
25 | + $result[$index] = $this->params[$i]; | ||
26 | + } | ||
27 | + return $result; | ||
28 | + } | ||
29 | + | ||
30 | + // for catalog | ||
31 | + public function setParams($params) | ||
32 | + { | ||
33 | + $this->params = $params; | ||
34 | + } | ||
35 | + | ||
36 | + public function getParams() | ||
37 | + { | ||
38 | + return $this->params; | ||
39 | + } | ||
40 | + | ||
41 | + public function writeBin($handle, $paramsNumber, $paramsSizes, $paramsTypes) | ||
42 | + { | ||
43 | + fwrite($handle,pack('L6',$this->id,$this->index,$this->start,$this->stop,$this->isNew,$this->isModified)); | ||
44 | + for ($i = 0; $i < $paramsNumber; $i++) | ||
45 | + { | ||
46 | + if ($paramsTypes[$i] == '2') // string | ||
47 | + { | ||
48 | + fwrite($handle,pack('d', strlen($this->params[$i]))); | ||
49 | + fwrite($handle, $this->params[$i],strlen($this->params[$i])); | ||
50 | + } | ||
51 | + else | ||
52 | + { | ||
53 | + if ($paramsTypes[$i] == '1') | ||
54 | + $paramString = TimeUtils::iso2stamp($this->params[$i]); | ||
55 | + else | ||
56 | + $paramString = $this->params[$i]; | ||
57 | + | ||
58 | + $paramArray = explode(',',$paramString); | ||
59 | + for ($j = 0; $j < $paramsSizes[$i]; $j++) fwrite($handle,pack('d', $paramArray[$j])); | ||
60 | + } | ||
61 | + } | ||
62 | + } | ||
63 | + | ||
64 | + public function loadBin($handle, $paramsNumber, $paramsSizes, $paramsTypes) | ||
65 | + { | ||
66 | + $array = unpack('L6int',fread($handle,6*4)); | ||
67 | + $this->id = $array['int1']; | ||
68 | + $this->index = $array['int2']; | ||
69 | + $this->start = $array['int3']; | ||
70 | + $this->stop = $array['int4']; | ||
71 | + $this->isNew = $array['int5']; | ||
72 | + $this->isModified = $array['int6']; | ||
73 | + | ||
74 | + for ($i = 0; $i < $paramsNumber; $i++) { | ||
75 | + $this->params[$i] = null; | ||
76 | + | ||
77 | + for ($j = 0; $j < $paramsSizes[$i]; $j++) | ||
78 | + { | ||
79 | + $val = unpack('dval',fread($handle,8)); | ||
80 | + | ||
81 | + if ($paramsTypes[$i] == '2') // string | ||
82 | + { | ||
83 | + $this->params[$i] = fread($handle,$val['val']); | ||
84 | + } | ||
85 | + else | ||
86 | + { | ||
87 | + if ($paramsTypes[$i] == '1') | ||
88 | + $this->params[$i] .= TimeUtils::stamp2iso($val['val']); | ||
89 | + else | ||
90 | + $this->params[$i] .= $val['val']; | ||
91 | + | ||
92 | + if ($j != $paramsSizes[$i] - 1) $this->params[$i] .= ','; | ||
93 | + } | ||
94 | + } | ||
95 | + } | ||
96 | + | ||
97 | + } | ||
98 | + | ||
99 | + public function dump() | ||
100 | + { | ||
101 | + echo " => Interval : id = ".$this->id.", index = ".$this->index.", start = ".$this->start.", stop = ".$this->stop.", isNew = ".$this->isNew.", isModified = ".$this->isModified.PHP_EOL; | ||
102 | + } | ||
103 | +} | ||
104 | + | ||
105 | + ?> |
php/classes/CatalogCacheMgr.php
@@ -4,307 +4,6 @@ | @@ -4,307 +4,6 @@ | ||
4 | * @class CatalogCacheMgr | 4 | * @class CatalogCacheMgr |
5 | */ | 5 | */ |
6 | 6 | ||
7 | - | ||
8 | -class CatIntervalCacheObject extends IntervalCacheObject | ||
9 | -{ | ||
10 | - // for catalog | ||
11 | - private $params = array(); | ||
12 | - | ||
13 | - public function toArray() | ||
14 | - { | ||
15 | - $result = array( | ||
16 | - "cacheId" => $this->id, | ||
17 | - "start" => $this->getStartToISO(), | ||
18 | - "stop" => $this->getStopToISO() | ||
19 | - ); | ||
20 | - if ($this->isNew) | ||
21 | - $result["isNew"] = true; | ||
22 | - | ||
23 | - if ($this->isModified) | ||
24 | - $result["isModified"] = true; | ||
25 | - | ||
26 | - for ($i = 0; $i < count($this->params); $i++) | ||
27 | - { | ||
28 | - $paramObject = array(); | ||
29 | - $index = 'param'.sprintf("%d",$i+2); | ||
30 | - $result[$index] = $this->params[$i]; | ||
31 | - } | ||
32 | - return $result; | ||
33 | - } | ||
34 | - | ||
35 | - // for catalog | ||
36 | - public function setParams($params) | ||
37 | - { | ||
38 | - $this->params = $params; | ||
39 | - } | ||
40 | - | ||
41 | - public function getParams() | ||
42 | - { | ||
43 | - return $this->params; | ||
44 | - } | ||
45 | - | ||
46 | - public function writeBin($handle, $paramsNumber, $paramsSizes, $paramsTypes) | ||
47 | - { | ||
48 | - fwrite($handle,pack('L6',$this->id,$this->index,$this->start,$this->stop,$this->isNew,$this->isModified)); | ||
49 | - for ($i = 0; $i < $paramsNumber; $i++) | ||
50 | - { | ||
51 | - if ($paramsTypes[$i] == '2') // string | ||
52 | - { | ||
53 | - fwrite($handle,pack('d', strlen($this->params[$i]))); | ||
54 | - fwrite($handle, $this->params[$i],strlen($this->params[$i])); | ||
55 | - } | ||
56 | - else | ||
57 | - { | ||
58 | - if ($paramsTypes[$i] == '1') | ||
59 | - $paramString = TimeUtils::iso2stamp($this->params[$i]); | ||
60 | - else | ||
61 | - $paramString = $this->params[$i]; | ||
62 | - | ||
63 | - $paramArray = explode(',',$paramString); | ||
64 | - for ($j = 0; $j < $paramsSizes[$i]; $j++) fwrite($handle,pack('d', $paramArray[$j])); | ||
65 | - } | ||
66 | - } | ||
67 | - } | ||
68 | - | ||
69 | - public function loadBin($handle, $paramsNumber, $paramsSizes, $paramsTypes) | ||
70 | - { | ||
71 | - $array = unpack('L6int',fread($handle,6*4)); | ||
72 | - $this->id = $array['int1']; | ||
73 | - $this->index = $array['int2']; | ||
74 | - $this->start = $array['int3']; | ||
75 | - $this->stop = $array['int4']; | ||
76 | - $this->isNew = $array['int5']; | ||
77 | - $this->isModified = $array['int6']; | ||
78 | - | ||
79 | - for ($i = 0; $i < $paramsNumber; $i++) { | ||
80 | - $this->params[$i] = null; | ||
81 | - | ||
82 | - for ($j = 0; $j < $paramsSizes[$i]; $j++) | ||
83 | - { | ||
84 | - $val = unpack('dval',fread($handle,8)); | ||
85 | - | ||
86 | - if ($paramsTypes[$i] == '2') // string | ||
87 | - { | ||
88 | - $this->params[$i] = fread($handle,$val['val']); | ||
89 | - } | ||
90 | - else | ||
91 | - { | ||
92 | - if ($paramsTypes[$i] == '1') | ||
93 | - $this->params[$i] .= TimeUtils::stamp2iso($val['val']); | ||
94 | - else | ||
95 | - $this->params[$i] .= $val['val']; | ||
96 | - | ||
97 | - if ($j != $paramsSizes[$i] - 1) $this->params[$i] .= ','; | ||
98 | - } | ||
99 | - } | ||
100 | - } | ||
101 | - | ||
102 | - } | ||
103 | - | ||
104 | - public function dump() | ||
105 | - { | ||
106 | - echo " => Interval : id = ".$this->id.", index = ".$this->index.", start = ".$this->start.", stop = ".$this->stop.", isNew = ".$this->isNew.", isModified = ".$this->isModified.PHP_EOL; | ||
107 | - } | ||
108 | -} | ||
109 | - | ||
110 | -class CatalogCacheObject extends TimeTableCacheObject | ||
111 | -{ | ||
112 | - private $paramsNumber; | ||
113 | - private $paramsSizes = array(); | ||
114 | - private $paramsTypes = array(); | ||
115 | - | ||
116 | - public function addInterval($startIso, $stopIso, $params, $isNew = false, $index = -1) | ||
117 | - { | ||
118 | - $interval = new CatIntervalCacheObject($this->lastId, count($this->intervals)); | ||
119 | - ++$this->lastId; | ||
120 | - $interval->setStartFromISO($startIso); | ||
121 | - $interval->setStopFromISO($stopIso); | ||
122 | - // for catalog | ||
123 | - $interval->setParams($params); | ||
124 | - | ||
125 | - $interval->setIsNew($isNew); | ||
126 | - array_push($this->intervals, $interval); | ||
127 | - | ||
128 | - if ($index < 0) | ||
129 | - array_push($this->indexes, count($this->intervals) - 1); | ||
130 | - else | ||
131 | - array_splice($this->indexes, $index, 0, array(count($this->intervals) - 1)); | ||
132 | - | ||
133 | - if ($isNew) | ||
134 | - $this->isModified = true; | ||
135 | - | ||
136 | - return $interval; | ||
137 | - } | ||
138 | - | ||
139 | - public function setParamsNumber($number) | ||
140 | - { | ||
141 | - $this->paramsNumber = $number; | ||
142 | - } | ||
143 | - | ||
144 | - public function setParamsSizes($params) | ||
145 | - { | ||
146 | - for ($i = 0; $i < $this->paramsNumber; $i++) | ||
147 | - $this->paramsSizes[$i] = $params[$i]['size']; | ||
148 | - } | ||
149 | - | ||
150 | - public function setParamsTypes($params) | ||
151 | - { | ||
152 | - for ($i = 0; $i < $this->paramsNumber; $i++) | ||
153 | - $this->paramsTypes[$i] = $params[$i]['type']; | ||
154 | - } | ||
155 | - | ||
156 | - public function writeBin($handle) | ||
157 | - { | ||
158 | - //Magic key ("TTC") | ||
159 | - fwrite($handle,pack('C3',ord('T'),ord('T'),ord('C'))); | ||
160 | - | ||
161 | - //Version | ||
162 | - fwrite($handle,pack('L',TimeTableCacheObject::$format_version)); | ||
163 | - | ||
164 | - //Token | ||
165 | - for ($i = 0; $i < TimeTableCacheObject::$token_len; ++$i) | ||
166 | - fwrite($handle,pack('C',ord($this->token[$i]))); | ||
167 | - | ||
168 | - //Modified | ||
169 | - fwrite($handle,pack('L',$this->isModified)); | ||
170 | - | ||
171 | - //Filter | ||
172 | - $this->filter->writeBin($handle); | ||
173 | - | ||
174 | - //Sort | ||
175 | - $this->sort->writeBin($handle); | ||
176 | - | ||
177 | - //Params Number | ||
178 | - fwrite($handle,pack('L',$this->paramsNumber)); | ||
179 | - | ||
180 | - //Params Sizes | ||
181 | - for ($i = 0; $i < $this->paramsNumber; $i++) | ||
182 | - fwrite($handle,pack('L',$this->paramsSizes[$i])); | ||
183 | - | ||
184 | - //Params Types | ||
185 | - for ($i = 0; $i < $this->paramsNumber; $i++) | ||
186 | - fwrite($handle,pack('L',$this->paramsTypes[$i])); | ||
187 | - | ||
188 | - //Intervals | ||
189 | - fwrite($handle,pack('L2', count($this->intervals), $this->lastId)); | ||
190 | - | ||
191 | - | ||
192 | - foreach($this->intervals as $interval) | ||
193 | - $interval->writeBin($handle,$this->paramsNumber,$this->paramsSizes, $this->paramsTypes); | ||
194 | - | ||
195 | - //Indexes | ||
196 | - fwrite($handle,pack('L',count($this->indexes))); | ||
197 | - foreach($this->indexes as $index) | ||
198 | - fwrite($handle,pack('L',$index)); | ||
199 | - } | ||
200 | - | ||
201 | - public function loadBin($handle) { | ||
202 | - //Magic key ("TTC") | ||
203 | - if (!$res = unpack('C3key',fread($handle,3))) | ||
204 | - return false; | ||
205 | - | ||
206 | - if (($res['key1'] != ord('T')) || ($res['key2'] != ord('T')) || ($res['key3'] != ord('C'))) | ||
207 | - return false; | ||
208 | - | ||
209 | - //Version | ||
210 | - if (!$res = unpack('Lversion',fread($handle,4))) | ||
211 | - return false; | ||
212 | - if (($res['version'] != TimeTableCacheObject::$format_version)) | ||
213 | - return false; | ||
214 | - | ||
215 | - //Token | ||
216 | - $token = ""; | ||
217 | - for ($i = 0; $i < TimeTableCacheObject::$token_len; ++$i) | ||
218 | - { | ||
219 | - if (!$res = unpack('Ctoken',fread($handle,1))) | ||
220 | - return false; | ||
221 | - $token .= chr($res['token']); | ||
222 | - } | ||
223 | - $this->token = $token; | ||
224 | - | ||
225 | - //Modified | ||
226 | - if (!$res = unpack('Lmodified',fread($handle,4))) | ||
227 | - return false; | ||
228 | - $this->isModified = $res['modified']; | ||
229 | - | ||
230 | - //Filter | ||
231 | - $this->filter->loadBin($handle); | ||
232 | - | ||
233 | - //Sort | ||
234 | - $this->sort->loadBin($handle); | ||
235 | - | ||
236 | - //ParamsNumber | ||
237 | - if (!$res = unpack('Lnumber',fread($handle,4))) | ||
238 | - return false; | ||
239 | - $this->paramsNumber = $res['number']; | ||
240 | - | ||
241 | - //ParamsSizes | ||
242 | - for ($i = 0; $i < $this->paramsNumber; $i++) { | ||
243 | - if (!$res = unpack('Lsize',fread($handle,4))) | ||
244 | - return false; | ||
245 | - $this->paramsSizes[$i] = $res['size']; | ||
246 | - } | ||
247 | - //ParamsTypes | ||
248 | - for ($i = 0; $i < $this->paramsNumber; $i++) { | ||
249 | - if (!$res = unpack('Ltype',fread($handle,4))) | ||
250 | - return false; | ||
251 | - $this->paramsTypes[$i] = $res['type']; | ||
252 | - } | ||
253 | - //Intervals | ||
254 | - $res = unpack('L2data',fread($handle,2*4)); | ||
255 | - $nbIntervals = $res['data1']; | ||
256 | - $this->lastId = $res['data2']; | ||
257 | - | ||
258 | - for ($i = 0; $i < $nbIntervals; ++$i) | ||
259 | - { | ||
260 | - $interval = new CatIntervalCacheObject(-1); | ||
261 | - $interval->loadBin($handle, $this->paramsNumber, $this->paramsSizes, $this->paramsTypes); | ||
262 | - array_push($this->intervals, $interval); | ||
263 | - } | ||
264 | - | ||
265 | - //Indexes | ||
266 | - $res = unpack('Ldata',fread($handle,4)); | ||
267 | - $nbIndexes = $res['data']; | ||
268 | - for ($i = 0; $i < $nbIndexes; ++$i) | ||
269 | - { | ||
270 | - $res = unpack('Lindex',fread($handle,4)); | ||
271 | - array_push($this->indexes, $res['index']); | ||
272 | - } | ||
273 | - | ||
274 | - return true; | ||
275 | - } | ||
276 | - | ||
277 | - public function modifyIntervalFromId($obj) { | ||
278 | - | ||
279 | - foreach ($this->intervals as $interval) | ||
280 | - { | ||
281 | - if ($interval->getId() == $obj->cacheId) | ||
282 | - { | ||
283 | - foreach((array)$obj as $key => $val) { | ||
284 | - | ||
285 | - if ($key == 'start') | ||
286 | - $interval->setStartFromISO($val); | ||
287 | - else if ($key == 'stop') | ||
288 | - $interval->setStopFromISO($val); | ||
289 | - else { | ||
290 | - if (strpos($key, 'param') === false) | ||
291 | - continue; | ||
292 | - $params = $interval->getParams(); | ||
293 | - $paramIndex = (int)substr($key,5); | ||
294 | - $params[$paramIndex-2] = $val; | ||
295 | - $interval->setParams($params); | ||
296 | - } | ||
297 | - } | ||
298 | - $interval->setIsModified(true); | ||
299 | - $this->isModified = true; | ||
300 | - return true; | ||
301 | - } | ||
302 | - } | ||
303 | - | ||
304 | - return false; | ||
305 | - } | ||
306 | -} | ||
307 | - | ||
308 | class CatalogCacheMgr extends TimeTableCacheMgr | 7 | class CatalogCacheMgr extends TimeTableCacheMgr |
309 | { | 8 | { |
310 | 9 |
@@ -0,0 +1,201 @@ | @@ -0,0 +1,201 @@ | ||
1 | +<?php | ||
2 | + | ||
3 | +class CatalogCacheObject extends TimeTableCacheObject | ||
4 | +{ | ||
5 | + private $paramsNumber; | ||
6 | + private $paramsSizes = array(); | ||
7 | + private $paramsTypes = array(); | ||
8 | + | ||
9 | + public function addInterval($startIso, $stopIso, $params, $isNew = false, $index = -1) | ||
10 | + { | ||
11 | + $interval = new CatIntervalCacheObject($this->lastId, count($this->intervals)); | ||
12 | + ++$this->lastId; | ||
13 | + $interval->setStartFromISO($startIso); | ||
14 | + $interval->setStopFromISO($stopIso); | ||
15 | + // for catalog | ||
16 | + $interval->setParams($params); | ||
17 | + | ||
18 | + $interval->setIsNew($isNew); | ||
19 | + array_push($this->intervals, $interval); | ||
20 | + | ||
21 | + if ($index < 0) | ||
22 | + array_push($this->indexes, count($this->intervals) - 1); | ||
23 | + else | ||
24 | + array_splice($this->indexes, $index, 0, array(count($this->intervals) - 1)); | ||
25 | + | ||
26 | + if ($isNew) | ||
27 | + $this->isModified = true; | ||
28 | + | ||
29 | + return $interval; | ||
30 | + } | ||
31 | + | ||
32 | + public function setParamsNumber($number) | ||
33 | + { | ||
34 | + $this->paramsNumber = $number; | ||
35 | + } | ||
36 | + | ||
37 | + public function setParamsSizes($params) | ||
38 | + { | ||
39 | + for ($i = 0; $i < $this->paramsNumber; $i++) | ||
40 | + $this->paramsSizes[$i] = $params[$i]['size']; | ||
41 | + } | ||
42 | + | ||
43 | + public function setParamsTypes($params) | ||
44 | + { | ||
45 | + for ($i = 0; $i < $this->paramsNumber; $i++) | ||
46 | + $this->paramsTypes[$i] = $params[$i]['type']; | ||
47 | + } | ||
48 | + | ||
49 | + public function writeBin($handle) | ||
50 | + { | ||
51 | + //Magic key ("TTC") | ||
52 | + fwrite($handle,pack('C3',ord('T'),ord('T'),ord('C'))); | ||
53 | + | ||
54 | + //Version | ||
55 | + fwrite($handle,pack('L',TimeTableCacheObject::$format_version)); | ||
56 | + | ||
57 | + //Token | ||
58 | + for ($i = 0; $i < TimeTableCacheObject::$token_len; ++$i) | ||
59 | + fwrite($handle,pack('C',ord($this->token[$i]))); | ||
60 | + | ||
61 | + //Modified | ||
62 | + fwrite($handle,pack('L',$this->isModified)); | ||
63 | + | ||
64 | + //Filter | ||
65 | + $this->filter->writeBin($handle); | ||
66 | + | ||
67 | + //Sort | ||
68 | + $this->sort->writeBin($handle); | ||
69 | + | ||
70 | + //Params Number | ||
71 | + fwrite($handle,pack('L',$this->paramsNumber)); | ||
72 | + | ||
73 | + //Params Sizes | ||
74 | + for ($i = 0; $i < $this->paramsNumber; $i++) | ||
75 | + fwrite($handle,pack('L',$this->paramsSizes[$i])); | ||
76 | + | ||
77 | + //Params Types | ||
78 | + for ($i = 0; $i < $this->paramsNumber; $i++) | ||
79 | + fwrite($handle,pack('L',$this->paramsTypes[$i])); | ||
80 | + | ||
81 | + //Intervals | ||
82 | + fwrite($handle,pack('L2', count($this->intervals), $this->lastId)); | ||
83 | + | ||
84 | + | ||
85 | + foreach($this->intervals as $interval) | ||
86 | + $interval->writeBin($handle,$this->paramsNumber,$this->paramsSizes, $this->paramsTypes); | ||
87 | + | ||
88 | + //Indexes | ||
89 | + fwrite($handle,pack('L',count($this->indexes))); | ||
90 | + foreach($this->indexes as $index) | ||
91 | + fwrite($handle,pack('L',$index)); | ||
92 | + } | ||
93 | + | ||
94 | + public function loadBin($handle) { | ||
95 | + //Magic key ("TTC") | ||
96 | + if (!$res = unpack('C3key',fread($handle,3))) | ||
97 | + return false; | ||
98 | + | ||
99 | + if (($res['key1'] != ord('T')) || ($res['key2'] != ord('T')) || ($res['key3'] != ord('C'))) | ||
100 | + return false; | ||
101 | + | ||
102 | + //Version | ||
103 | + if (!$res = unpack('Lversion',fread($handle,4))) | ||
104 | + return false; | ||
105 | + if (($res['version'] != TimeTableCacheObject::$format_version)) | ||
106 | + return false; | ||
107 | + | ||
108 | + //Token | ||
109 | + $token = ""; | ||
110 | + for ($i = 0; $i < TimeTableCacheObject::$token_len; ++$i) | ||
111 | + { | ||
112 | + if (!$res = unpack('Ctoken',fread($handle,1))) | ||
113 | + return false; | ||
114 | + $token .= chr($res['token']); | ||
115 | + } | ||
116 | + $this->token = $token; | ||
117 | + | ||
118 | + //Modified | ||
119 | + if (!$res = unpack('Lmodified',fread($handle,4))) | ||
120 | + return false; | ||
121 | + $this->isModified = $res['modified']; | ||
122 | + | ||
123 | + //Filter | ||
124 | + $this->filter->loadBin($handle); | ||
125 | + | ||
126 | + //Sort | ||
127 | + $this->sort->loadBin($handle); | ||
128 | + | ||
129 | + //ParamsNumber | ||
130 | + if (!$res = unpack('Lnumber',fread($handle,4))) | ||
131 | + return false; | ||
132 | + $this->paramsNumber = $res['number']; | ||
133 | + | ||
134 | + //ParamsSizes | ||
135 | + for ($i = 0; $i < $this->paramsNumber; $i++) { | ||
136 | + if (!$res = unpack('Lsize',fread($handle,4))) | ||
137 | + return false; | ||
138 | + $this->paramsSizes[$i] = $res['size']; | ||
139 | + } | ||
140 | + //ParamsTypes | ||
141 | + for ($i = 0; $i < $this->paramsNumber; $i++) { | ||
142 | + if (!$res = unpack('Ltype',fread($handle,4))) | ||
143 | + return false; | ||
144 | + $this->paramsTypes[$i] = $res['type']; | ||
145 | + } | ||
146 | + //Intervals | ||
147 | + $res = unpack('L2data',fread($handle,2*4)); | ||
148 | + $nbIntervals = $res['data1']; | ||
149 | + $this->lastId = $res['data2']; | ||
150 | + | ||
151 | + for ($i = 0; $i < $nbIntervals; ++$i) | ||
152 | + { | ||
153 | + $interval = new CatIntervalCacheObject(-1); | ||
154 | + $interval->loadBin($handle, $this->paramsNumber, $this->paramsSizes, $this->paramsTypes); | ||
155 | + array_push($this->intervals, $interval); | ||
156 | + } | ||
157 | + | ||
158 | + //Indexes | ||
159 | + $res = unpack('Ldata',fread($handle,4)); | ||
160 | + $nbIndexes = $res['data']; | ||
161 | + for ($i = 0; $i < $nbIndexes; ++$i) | ||
162 | + { | ||
163 | + $res = unpack('Lindex',fread($handle,4)); | ||
164 | + array_push($this->indexes, $res['index']); | ||
165 | + } | ||
166 | + | ||
167 | + return true; | ||
168 | + } | ||
169 | + | ||
170 | + public function modifyIntervalFromId($obj) { | ||
171 | + | ||
172 | + foreach ($this->intervals as $interval) | ||
173 | + { | ||
174 | + if ($interval->getId() == $obj->cacheId) | ||
175 | + { | ||
176 | + foreach((array)$obj as $key => $val) { | ||
177 | + | ||
178 | + if ($key == 'start') | ||
179 | + $interval->setStartFromISO($val); | ||
180 | + else if ($key == 'stop') | ||
181 | + $interval->setStopFromISO($val); | ||
182 | + else { | ||
183 | + if (strpos($key, 'param') === false) | ||
184 | + continue; | ||
185 | + $params = $interval->getParams(); | ||
186 | + $paramIndex = (int)substr($key,5); | ||
187 | + $params[$paramIndex-2] = $val; | ||
188 | + $interval->setParams($params); | ||
189 | + } | ||
190 | + } | ||
191 | + $interval->setIsModified(true); | ||
192 | + $this->isModified = true; | ||
193 | + return true; | ||
194 | + } | ||
195 | + } | ||
196 | + | ||
197 | + return false; | ||
198 | + } | ||
199 | +} | ||
200 | + | ||
201 | + ?> |
@@ -0,0 +1,286 @@ | @@ -0,0 +1,286 @@ | ||
1 | +<?php | ||
2 | + | ||
3 | +class FilterPartCacheObject | ||
4 | +{ | ||
5 | + public static $TYPE_UNKNOWN = 0; | ||
6 | + public static $TYPE_START = 1; | ||
7 | + public static $TYPE_STOP = 2; | ||
8 | + public static $TYPE_DURATION_SEC = 3; | ||
9 | + public static $TYPE_DURATION_MIN = 4; | ||
10 | + public static $TYPE_DURATION_HOUR = 5; | ||
11 | + | ||
12 | + public static $OPERATION_UNKNOWN = 0; | ||
13 | + public static $OPERATION_LT = 1; | ||
14 | + public static $OPERATION_GT = 2; | ||
15 | + public static $OPERATION_EQ = 3; | ||
16 | + | ||
17 | + protected $type; | ||
18 | + protected $op; | ||
19 | + protected $value; | ||
20 | + | ||
21 | + function __construct() { | ||
22 | + $this->type = self::$TYPE_UNKNOWN; | ||
23 | + $this->op = self::$OPERATION_UNKNOWN; | ||
24 | + $this->value = 0.; | ||
25 | + } | ||
26 | + | ||
27 | + public function getType() { | ||
28 | + return $this->type; | ||
29 | + } | ||
30 | + | ||
31 | + public function getOp() { | ||
32 | + return $this->op; | ||
33 | + } | ||
34 | + | ||
35 | + public function getValue() { | ||
36 | + return $this->value; | ||
37 | + } | ||
38 | + | ||
39 | + public function isSame($part) { | ||
40 | + return (($this->type == $part->getType()) && ($this->op == $part->getOp()) && ($this->value == $part->getValue())); | ||
41 | + } | ||
42 | + | ||
43 | + public function toFiltered($interval) { | ||
44 | + switch ($this->type) { | ||
45 | + case self::$TYPE_START : | ||
46 | + { | ||
47 | + switch ($this->op) { | ||
48 | + case self::$OPERATION_LT : | ||
49 | + return ($interval->getStartToStamp() < $this->value); | ||
50 | + case self::$OPERATION_GT : | ||
51 | + return ($interval->getStartToStamp() > $this->value); | ||
52 | + case self::$OPERATION_EQ : | ||
53 | + return (!(($interval->getStartToStamp() >= $this->value) && ($interval->getStartToStamp() <= $this->value+86400))); | ||
54 | + default : | ||
55 | + return false; | ||
56 | + } | ||
57 | + } | ||
58 | + break; | ||
59 | + case self::$TYPE_STOP : | ||
60 | + { | ||
61 | + switch ($this->op) { | ||
62 | + case self::$OPERATION_LT : | ||
63 | + return ($interval->getStopToStamp() < $this->value); | ||
64 | + case self::$OPERATION_GT : | ||
65 | + return ($interval->getStopToStamp() > $this->value); | ||
66 | + case self::$OPERATION_EQ : | ||
67 | + return (!(($interval->getStopToStamp() >= $this->value) && ($interval->getStopToStamp() <= $this->value+86400))); | ||
68 | + default : | ||
69 | + return false; | ||
70 | + } | ||
71 | + } | ||
72 | + break; | ||
73 | + case self::$TYPE_DURATION_SEC : | ||
74 | + case self::$TYPE_DURATION_MIN : | ||
75 | + case self::$TYPE_DURATION_HOUR : | ||
76 | + { | ||
77 | + $value = $this->value; | ||
78 | + if ($this->type == self::$TYPE_DURATION_MIN) | ||
79 | + $value *= 60; | ||
80 | + else if ($this->type == self::$TYPE_DURATION_HOUR) | ||
81 | + $value *= 3600; | ||
82 | + switch ($this->op) { | ||
83 | + case self::$OPERATION_LT : | ||
84 | + return ($interval->getDuration() < $value); | ||
85 | + case self::$OPERATION_GT : | ||
86 | + return ($interval->getDuration() > $value); | ||
87 | + case self::$OPERATION_EQ : | ||
88 | + return ($interval->getDuration() != $value); | ||
89 | + default : | ||
90 | + return false; | ||
91 | + } | ||
92 | + } | ||
93 | + break; | ||
94 | + default: | ||
95 | + return false; | ||
96 | + } | ||
97 | + } | ||
98 | + | ||
99 | + public function loadFromObject($part_obj) { | ||
100 | + $this->value = 0.; | ||
101 | + switch ($part_obj->field) | ||
102 | + { | ||
103 | + case 'start' : | ||
104 | + $this->value = TimeUtils::iso2stamp($part_obj->value); | ||
105 | + $this->type = self::$TYPE_START; | ||
106 | + break; | ||
107 | + case 'stop' : | ||
108 | + $this->value = TimeUtils::iso2stamp($part_obj->value); | ||
109 | + $this->type = self::$TYPE_STOP; | ||
110 | + break; | ||
111 | + case 'durationMin' : | ||
112 | + $this->value = $part_obj->value; | ||
113 | + $this->type = self::$TYPE_DURATION_MIN; | ||
114 | + break; | ||
115 | + case 'durationHour' : | ||
116 | + $this->value = $part_obj->value; | ||
117 | + $this->type = self::$TYPE_DURATION_HOUR; | ||
118 | + break; | ||
119 | + case 'durationSec' : | ||
120 | + $this->value = $part_obj->value; | ||
121 | + $this->type = self::$TYPE_DURATION_SEC; | ||
122 | + break; | ||
123 | + default: | ||
124 | + $this->value = 0.; | ||
125 | + $this->type = self::$TYPE_UNKNOWN; | ||
126 | + } | ||
127 | + | ||
128 | + switch ($part_obj->comparison) | ||
129 | + { | ||
130 | + case 'lt' : | ||
131 | + $this->op = self::$OPERATION_LT; | ||
132 | + break; | ||
133 | + case 'gt' : | ||
134 | + $this->op = self::$OPERATION_GT; | ||
135 | + break; | ||
136 | + case 'eq' : | ||
137 | + $this->op = self::$OPERATION_EQ; | ||
138 | + break; | ||
139 | + default: | ||
140 | + $this->op = self::$OPERATION_UNKNOWN; | ||
141 | + } | ||
142 | + } | ||
143 | + | ||
144 | + public function writeBin($handle) { | ||
145 | + fwrite($handle,pack('L2',$this->type,$this->op)); | ||
146 | + fwrite($handle,pack('f',$this->value)); | ||
147 | + } | ||
148 | + | ||
149 | + public function loadBin($handle) { | ||
150 | + $res = unpack('L2data',fread($handle,4*2)); | ||
151 | + $this->type = $res['data1']; | ||
152 | + $this->op = $res['data2']; | ||
153 | + | ||
154 | + $res = unpack('fvalue',fread($handle,4)); | ||
155 | + $this->value = $res['value']; | ||
156 | + } | ||
157 | + | ||
158 | + public function dump() { | ||
159 | + echo " => FilterPartCacheObject : type = "; | ||
160 | + switch ($this->type) | ||
161 | + { | ||
162 | + case self::$TYPE_START : | ||
163 | + echo "start"; | ||
164 | + break; | ||
165 | + case self::$TYPE_STOP : | ||
166 | + echo "stop"; | ||
167 | + break; | ||
168 | + case self::$TYPE_DURATION_SEC : | ||
169 | + echo "duration seconde"; | ||
170 | + break; | ||
171 | + case self::$TYPE_DURATION_MIN : | ||
172 | + echo "duration minute"; | ||
173 | + break; | ||
174 | + case self::$TYPE_DURATION_HOUR : | ||
175 | + echo "duration hour"; | ||
176 | + break; | ||
177 | + default: | ||
178 | + echo "unknown"; | ||
179 | + } | ||
180 | + echo ", operation = "; | ||
181 | + switch ($this->op) | ||
182 | + { | ||
183 | + case self::$OPERATION_LT : | ||
184 | + echo "lt"; | ||
185 | + break; | ||
186 | + case self::$OPERATION_GT : | ||
187 | + echo "gt"; | ||
188 | + break; | ||
189 | + case self::$OPERATION_EQ : | ||
190 | + echo "eq"; | ||
191 | + break; | ||
192 | + default: | ||
193 | + echo "unknown"; | ||
194 | + } | ||
195 | + echo ", value = ".$this->value.PHP_EOL; | ||
196 | + } | ||
197 | +} | ||
198 | + | ||
199 | +class FilterCacheObject | ||
200 | +{ | ||
201 | + protected $parts = array(); | ||
202 | + | ||
203 | + function __construct() { | ||
204 | + | ||
205 | + } | ||
206 | + | ||
207 | + public function getParts() { | ||
208 | + return $this->parts; | ||
209 | + } | ||
210 | + | ||
211 | + public function reset() { | ||
212 | + $this->parts = array(); | ||
213 | + } | ||
214 | + | ||
215 | + public function isEmpty() { | ||
216 | + return (count($this->parts) == 0); | ||
217 | + } | ||
218 | + | ||
219 | + public function loadFromJSON($filter_json) { | ||
220 | + $this->reset(); | ||
221 | + $filter_obj = json_decode($filter_json); | ||
222 | + | ||
223 | + foreach ($filter_obj as $filter_part) | ||
224 | + { | ||
225 | + $part = new FilterPartCacheObject(); | ||
226 | + $part->loadFromObject($filter_part); | ||
227 | + array_push($this->parts, $part); | ||
228 | + } | ||
229 | + } | ||
230 | + | ||
231 | + public function isSame($filter) { | ||
232 | + if (count($this->parts) != count($filter->getParts())) | ||
233 | + return false; | ||
234 | + | ||
235 | + $identique = true; | ||
236 | + for ($i = 0; $i < count($this->parts); ++$i) | ||
237 | + { | ||
238 | + if (!$this->parts[$i]->isSame($filter->getParts()[$i])) | ||
239 | + { | ||
240 | + return false; | ||
241 | + } | ||
242 | + } | ||
243 | + | ||
244 | + return true; | ||
245 | + } | ||
246 | + | ||
247 | + public function isSameFromJSON($filter_json) { | ||
248 | + $filter = new FilterCacheObject(); | ||
249 | + $filter->loadFromJSON($filter_json); | ||
250 | + return $this->isSame($filter); | ||
251 | + } | ||
252 | + | ||
253 | + public function toFiltered($interval) { | ||
254 | + foreach ($this->parts as $part) | ||
255 | + { | ||
256 | + if ($part->toFiltered($interval)) | ||
257 | + return true; | ||
258 | + } | ||
259 | + return false; | ||
260 | + } | ||
261 | + | ||
262 | + public function writeBin($handle) { | ||
263 | + fwrite($handle,pack('L',count($this->parts))); | ||
264 | + foreach ($this->parts as $part) | ||
265 | + $part->writeBin($handle); | ||
266 | + } | ||
267 | + | ||
268 | + public function loadBin($handle) { | ||
269 | + $this->reset(); | ||
270 | + $res = unpack('Lcount',fread($handle,4)); | ||
271 | + for ($i = 0; $i < $res['count']; ++$i) | ||
272 | + { | ||
273 | + $part = new FilterPartCacheObject(); | ||
274 | + $part->loadBin($handle); | ||
275 | + array_push($this->parts, $part); | ||
276 | + } | ||
277 | + } | ||
278 | + | ||
279 | + public function dump() { | ||
280 | + echo " => FilterCacheObject : number of parts = ".count($this->parts).PHP_EOL; | ||
281 | + foreach ($this->parts as $part) | ||
282 | + $part->dump(); | ||
283 | + } | ||
284 | +} | ||
285 | + | ||
286 | + ?> |
@@ -0,0 +1,261 @@ | @@ -0,0 +1,261 @@ | ||
1 | +<?php | ||
2 | + | ||
3 | +class SortPartCacheObject | ||
4 | +{ | ||
5 | + public static $TYPE_UNKNOWN = 0; | ||
6 | + public static $TYPE_START = 1; | ||
7 | + public static $TYPE_STOP = 2; | ||
8 | + public static $TYPE_DURATION_SEC = 3; | ||
9 | + public static $TYPE_DURATION_MIN = 4; | ||
10 | + public static $TYPE_DURATION_HOUR = 5; | ||
11 | + | ||
12 | + public static $DIRECTION_UNKNOWN = 0; | ||
13 | + public static $DIRECTION_ASC = 1; | ||
14 | + public static $DIRECTION_DES = 2; | ||
15 | + | ||
16 | + protected $type; | ||
17 | + protected $dir; | ||
18 | + | ||
19 | + function __construct() { | ||
20 | + $this->type = self::$TYPE_UNKNOWN; | ||
21 | + $this->dir = self::$DIRECTION_UNKNOWN; | ||
22 | + } | ||
23 | + | ||
24 | + public function getType() { | ||
25 | + return $this->type; | ||
26 | + } | ||
27 | + | ||
28 | + public function getDir() { | ||
29 | + return $this->dir; | ||
30 | + } | ||
31 | + | ||
32 | + public function isSame($part) { | ||
33 | + return (($this->type == $part->getType()) && ($this->dir == $part->getDir())); | ||
34 | + } | ||
35 | + | ||
36 | + public function compare($interval_a, $interval_b) { | ||
37 | + switch ($this->type) { | ||
38 | + case self::$TYPE_START : | ||
39 | + { | ||
40 | + switch ($this->dir) { | ||
41 | + case self::$DIRECTION_ASC : | ||
42 | + return ($interval_b->getStartToStamp() - $interval_a->getStartToStamp()); | ||
43 | + default : | ||
44 | + return ($interval_a->getStartToStamp() - $interval_b->getStartToStamp()); | ||
45 | + } | ||
46 | + } | ||
47 | + break; | ||
48 | + case self::$TYPE_STOP : | ||
49 | + { | ||
50 | + switch ($this->dir) { | ||
51 | + case self::$DIRECTION_ASC : | ||
52 | + return ($interval_b->getStopToStamp() - $interval_a->getStopToStamp()); | ||
53 | + default : | ||
54 | + return ($interval_a->getStopToStamp() - $interval_b->getStopToStamp()); | ||
55 | + } | ||
56 | + } | ||
57 | + break; | ||
58 | + case self::$TYPE_DURATION_SEC : | ||
59 | + case self::$TYPE_DURATION_MIN : | ||
60 | + case self::$TYPE_DURATION_HOUR : | ||
61 | + { | ||
62 | + switch ($this->dir) { | ||
63 | + case self::$DIRECTION_ASC : | ||
64 | + return ($interval_b->getDuration() - $interval_a->getDuration()); | ||
65 | + default : | ||
66 | + return ($interval_a->getDuration() - $interval_b->getDuration()); | ||
67 | + } | ||
68 | + } | ||
69 | + break; | ||
70 | + default : | ||
71 | + return 0; | ||
72 | + } | ||
73 | + return 0; | ||
74 | + } | ||
75 | + | ||
76 | + public function loadFromObject($part_obj) { | ||
77 | + switch ($part_obj->property) | ||
78 | + { | ||
79 | + case 'start' : | ||
80 | + $this->type = self::$TYPE_START; | ||
81 | + break; | ||
82 | + case 'stop' : | ||
83 | + $this->type = self::$TYPE_STOP; | ||
84 | + break; | ||
85 | + case 'durationMin' : | ||
86 | + $this->type = self::$TYPE_DURATION_MIN; | ||
87 | + break; | ||
88 | + case 'durationHour' : | ||
89 | + $this->type = self::$TYPE_DURATION_HOUR; | ||
90 | + break; | ||
91 | + case 'durationSec' : | ||
92 | + $this->type = self::$TYPE_DURATION_SEC; | ||
93 | + break; | ||
94 | + default: | ||
95 | + $this->type = self::$TYPE_UNKNOWN; | ||
96 | + } | ||
97 | + | ||
98 | + switch ($part_obj->direction) | ||
99 | + { | ||
100 | + case 'ASC' : | ||
101 | + $this->dir = self::$DIRECTION_ASC; | ||
102 | + break; | ||
103 | + case 'DESC' : | ||
104 | + $this->dir = self::$DIRECTION_DES; | ||
105 | + break; | ||
106 | + default: | ||
107 | + $this->dir = self::$DIRECTION_UNKNOWN; | ||
108 | + } | ||
109 | + } | ||
110 | + | ||
111 | + public function writeBin($handle) { | ||
112 | + fwrite($handle,pack('L2',$this->type,$this->dir)); | ||
113 | + } | ||
114 | + | ||
115 | + public function loadBin($handle) { | ||
116 | + $res = unpack('L2data',fread($handle,4*2)); | ||
117 | + $this->type = $res['data1']; | ||
118 | + $this->dir = $res['data2']; | ||
119 | + } | ||
120 | + | ||
121 | + public function dump() { | ||
122 | + echo " => SortPartCacheObject : type = "; | ||
123 | + switch ($this->type) | ||
124 | + { | ||
125 | + case self::$TYPE_START : | ||
126 | + echo "start"; | ||
127 | + break; | ||
128 | + case self::$TYPE_STOP : | ||
129 | + echo "stop"; | ||
130 | + break; | ||
131 | + case self::$TYPE_DURATION_SEC : | ||
132 | + echo "duration seconde"; | ||
133 | + break; | ||
134 | + case self::$TYPE_DURATION_MIN : | ||
135 | + echo "duration minute"; | ||
136 | + break; | ||
137 | + case self::$TYPE_DURATION_HOUR : | ||
138 | + echo "duration hour"; | ||
139 | + break; | ||
140 | + default: | ||
141 | + echo "unknown"; | ||
142 | + } | ||
143 | + echo ", direction = "; | ||
144 | + switch ($this->dir) | ||
145 | + { | ||
146 | + case self::$DIRECTION_ASC : | ||
147 | + echo "ASC"; | ||
148 | + break; | ||
149 | + case self::$DIRECTION_DES : | ||
150 | + echo "DESC"; | ||
151 | + break; | ||
152 | + default: | ||
153 | + echo "unknown"; | ||
154 | + } | ||
155 | + echo PHP_EOL; | ||
156 | + } | ||
157 | +} | ||
158 | + | ||
159 | +class SortCacheObject | ||
160 | +{ | ||
161 | + protected $parts = array(); | ||
162 | + | ||
163 | + function __construct() { | ||
164 | + } | ||
165 | + | ||
166 | + public function getParts() { | ||
167 | + return $this->parts; | ||
168 | + } | ||
169 | + | ||
170 | + public function reset() { | ||
171 | + $this->parts = array(); | ||
172 | + } | ||
173 | + | ||
174 | + public function isEmpty() { | ||
175 | + return (count($this->parts) == 0); | ||
176 | + } | ||
177 | + | ||
178 | + public function loadFromObject($sort_obj) { | ||
179 | + $this->reset(); | ||
180 | + foreach ($sort_obj as $sort_part) | ||
181 | + { | ||
182 | + $part = new SortPartCacheObject(); | ||
183 | + $part->loadFromObject($sort_part); | ||
184 | + array_push($this->parts, $part); | ||
185 | + } | ||
186 | + } | ||
187 | + | ||
188 | + public function isSameFromObject($sort_obj) { | ||
189 | + $sort = new SortCacheObject(); | ||
190 | + $sort->loadFromObject($sort_obj); | ||
191 | + return $this->isSame($sort); | ||
192 | + } | ||
193 | + | ||
194 | + public function isSame($sort) { | ||
195 | + if (count($this->parts) != count($sort->getParts())) | ||
196 | + return false; | ||
197 | + | ||
198 | + $identique = true; | ||
199 | + for ($i = 0; $i < count($this->parts); ++$i) | ||
200 | + { | ||
201 | + if (!$this->parts[$i]->isSame($sort->getParts()[$i])) | ||
202 | + { | ||
203 | + return false; | ||
204 | + } | ||
205 | + } | ||
206 | + | ||
207 | + return true; | ||
208 | + } | ||
209 | + | ||
210 | + public function apply($intervals) { | ||
211 | + $sorted_indexes = array(); | ||
212 | + | ||
213 | + global $global_parts, $global_intervals; | ||
214 | + $global_parts = $this->parts; | ||
215 | + $global_intervals = $intervals; | ||
216 | + | ||
217 | + foreach ($intervals as $interval) | ||
218 | + array_push($sorted_indexes, $interval->getIndex()); | ||
219 | + | ||
220 | + if (count($global_parts) == 0) | ||
221 | + return $sorted_indexes; | ||
222 | + | ||
223 | + usort($sorted_indexes, function ($index_a, $index_b) { | ||
224 | + global $global_parts, $global_intervals; | ||
225 | + foreach ($global_parts as $part) | ||
226 | + { | ||
227 | + $res = $part->compare($global_intervals[$index_a], $global_intervals[$index_b]); | ||
228 | + if ($res != 0) | ||
229 | + return $res; | ||
230 | + } | ||
231 | + return $index_a-$index_b; | ||
232 | + }); | ||
233 | + | ||
234 | + return $sorted_indexes; | ||
235 | + } | ||
236 | + | ||
237 | + public function writeBin($handle) { | ||
238 | + fwrite($handle,pack('L',count($this->parts))); | ||
239 | + foreach ($this->parts as $part) | ||
240 | + $part->writeBin($handle); | ||
241 | + } | ||
242 | + | ||
243 | + public function loadBin($handle) { | ||
244 | + $this->reset(); | ||
245 | + $res = unpack('Lcount',fread($handle,4)); | ||
246 | + for ($i = 0; $i < $res['count']; ++$i) | ||
247 | + { | ||
248 | + $part = new SortPartCacheObject(); | ||
249 | + $part->loadBin($handle); | ||
250 | + array_push($this->parts, $part); | ||
251 | + } | ||
252 | + } | ||
253 | + | ||
254 | + public function dump() { | ||
255 | + echo " => SortCacheObject : number of parts = ".count($this->parts).PHP_EOL; | ||
256 | + foreach ($this->parts as $part) | ||
257 | + $part->dump(); | ||
258 | + } | ||
259 | +} | ||
260 | + | ||
261 | + ?> |
php/classes/TimeTableCacheMgr.php
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | -class SortPartCacheObject | ||
4 | -{ | ||
5 | - public static $TYPE_UNKNOWN = 0; | ||
6 | - public static $TYPE_START = 1; | ||
7 | - public static $TYPE_STOP = 2; | ||
8 | - public static $TYPE_DURATION_SEC = 3; | ||
9 | - public static $TYPE_DURATION_MIN = 4; | ||
10 | - public static $TYPE_DURATION_HOUR = 5; | ||
11 | - | ||
12 | - public static $DIRECTION_UNKNOWN = 0; | ||
13 | - public static $DIRECTION_ASC = 1; | ||
14 | - public static $DIRECTION_DES = 2; | ||
15 | - | ||
16 | - protected $type; | ||
17 | - protected $dir; | ||
18 | - | ||
19 | - function __construct() { | ||
20 | - $this->type = self::$TYPE_UNKNOWN; | ||
21 | - $this->dir = self::$DIRECTION_UNKNOWN; | ||
22 | - } | ||
23 | - | ||
24 | - public function getType() { | ||
25 | - return $this->type; | ||
26 | - } | ||
27 | - | ||
28 | - public function getDir() { | ||
29 | - return $this->dir; | ||
30 | - } | ||
31 | - | ||
32 | - public function isSame($part) { | ||
33 | - return (($this->type == $part->getType()) && ($this->dir == $part->getDir())); | ||
34 | - } | ||
35 | - | ||
36 | - public function compare($interval_a, $interval_b) { | ||
37 | - switch ($this->type) { | ||
38 | - case self::$TYPE_START : | ||
39 | - { | ||
40 | - switch ($this->dir) { | ||
41 | - case self::$DIRECTION_ASC : | ||
42 | - return ($interval_b->getStartToStamp() - $interval_a->getStartToStamp()); | ||
43 | - default : | ||
44 | - return ($interval_a->getStartToStamp() - $interval_b->getStartToStamp()); | ||
45 | - } | ||
46 | - } | ||
47 | - break; | ||
48 | - case self::$TYPE_STOP : | ||
49 | - { | ||
50 | - switch ($this->dir) { | ||
51 | - case self::$DIRECTION_ASC : | ||
52 | - return ($interval_b->getStopToStamp() - $interval_a->getStopToStamp()); | ||
53 | - default : | ||
54 | - return ($interval_a->getStopToStamp() - $interval_b->getStopToStamp()); | ||
55 | - } | ||
56 | - } | ||
57 | - break; | ||
58 | - case self::$TYPE_DURATION_SEC : | ||
59 | - case self::$TYPE_DURATION_MIN : | ||
60 | - case self::$TYPE_DURATION_HOUR : | ||
61 | - { | ||
62 | - switch ($this->dir) { | ||
63 | - case self::$DIRECTION_ASC : | ||
64 | - return ($interval_b->getDuration() - $interval_a->getDuration()); | ||
65 | - default : | ||
66 | - return ($interval_a->getDuration() - $interval_b->getDuration()); | ||
67 | - } | ||
68 | - } | ||
69 | - break; | ||
70 | - default : | ||
71 | - return 0; | ||
72 | - } | ||
73 | - return 0; | ||
74 | - } | ||
75 | - | ||
76 | - public function loadFromObject($part_obj) { | ||
77 | - switch ($part_obj->property) | ||
78 | - { | ||
79 | - case 'start' : | ||
80 | - $this->type = self::$TYPE_START; | ||
81 | - break; | ||
82 | - case 'stop' : | ||
83 | - $this->type = self::$TYPE_STOP; | ||
84 | - break; | ||
85 | - case 'durationMin' : | ||
86 | - $this->type = self::$TYPE_DURATION_MIN; | ||
87 | - break; | ||
88 | - case 'durationHour' : | ||
89 | - $this->type = self::$TYPE_DURATION_HOUR; | ||
90 | - break; | ||
91 | - case 'durationSec' : | ||
92 | - $this->type = self::$TYPE_DURATION_SEC; | ||
93 | - break; | ||
94 | - default: | ||
95 | - $this->type = self::$TYPE_UNKNOWN; | ||
96 | - } | ||
97 | - | ||
98 | - switch ($part_obj->direction) | ||
99 | - { | ||
100 | - case 'ASC' : | ||
101 | - $this->dir = self::$DIRECTION_ASC; | ||
102 | - break; | ||
103 | - case 'DESC' : | ||
104 | - $this->dir = self::$DIRECTION_DES; | ||
105 | - break; | ||
106 | - default: | ||
107 | - $this->dir = self::$DIRECTION_UNKNOWN; | ||
108 | - } | ||
109 | - } | ||
110 | - | ||
111 | - public function writeBin($handle) { | ||
112 | - fwrite($handle,pack('L2',$this->type,$this->dir)); | ||
113 | - } | ||
114 | - | ||
115 | - public function loadBin($handle) { | ||
116 | - $res = unpack('L2data',fread($handle,4*2)); | ||
117 | - $this->type = $res['data1']; | ||
118 | - $this->dir = $res['data2']; | ||
119 | - } | ||
120 | - | ||
121 | - public function dump() { | ||
122 | - echo " => SortPartCacheObject : type = "; | ||
123 | - switch ($this->type) | ||
124 | - { | ||
125 | - case self::$TYPE_START : | ||
126 | - echo "start"; | ||
127 | - break; | ||
128 | - case self::$TYPE_STOP : | ||
129 | - echo "stop"; | ||
130 | - break; | ||
131 | - case self::$TYPE_DURATION_SEC : | ||
132 | - echo "duration seconde"; | ||
133 | - break; | ||
134 | - case self::$TYPE_DURATION_MIN : | ||
135 | - echo "duration minute"; | ||
136 | - break; | ||
137 | - case self::$TYPE_DURATION_HOUR : | ||
138 | - echo "duration hour"; | ||
139 | - break; | ||
140 | - default: | ||
141 | - echo "unknown"; | ||
142 | - } | ||
143 | - echo ", direction = "; | ||
144 | - switch ($this->dir) | ||
145 | - { | ||
146 | - case self::$DIRECTION_ASC : | ||
147 | - echo "ASC"; | ||
148 | - break; | ||
149 | - case self::$DIRECTION_DES : | ||
150 | - echo "DESC"; | ||
151 | - break; | ||
152 | - default: | ||
153 | - echo "unknown"; | ||
154 | - } | ||
155 | - echo PHP_EOL; | ||
156 | - } | ||
157 | -} | ||
158 | - | ||
159 | -class SortCacheObject | ||
160 | -{ | ||
161 | - protected $parts = array(); | ||
162 | - | ||
163 | - function __construct() { | ||
164 | - } | ||
165 | - | ||
166 | - public function getParts() { | ||
167 | - return $this->parts; | ||
168 | - } | ||
169 | - | ||
170 | - public function reset() { | ||
171 | - $this->parts = array(); | ||
172 | - } | ||
173 | - | ||
174 | - public function isEmpty() { | ||
175 | - return (count($this->parts) == 0); | ||
176 | - } | ||
177 | - | ||
178 | - public function loadFromObject($sort_obj) { | ||
179 | - $this->reset(); | ||
180 | - foreach ($sort_obj as $sort_part) | ||
181 | - { | ||
182 | - $part = new SortPartCacheObject(); | ||
183 | - $part->loadFromObject($sort_part); | ||
184 | - array_push($this->parts, $part); | ||
185 | - } | ||
186 | - } | ||
187 | - | ||
188 | - public function isSameFromObject($sort_obj) { | ||
189 | - $sort = new SortCacheObject(); | ||
190 | - $sort->loadFromObject($sort_obj); | ||
191 | - return $this->isSame($sort); | ||
192 | - } | ||
193 | - | ||
194 | - public function isSame($sort) { | ||
195 | - if (count($this->parts) != count($sort->getParts())) | ||
196 | - return false; | ||
197 | - | ||
198 | - $identique = true; | ||
199 | - for ($i = 0; $i < count($this->parts); ++$i) | ||
200 | - { | ||
201 | - if (!$this->parts[$i]->isSame($sort->getParts()[$i])) | ||
202 | - { | ||
203 | - return false; | ||
204 | - } | ||
205 | - } | ||
206 | - | ||
207 | - return true; | ||
208 | - } | ||
209 | - | ||
210 | - public function apply($intervals) { | ||
211 | - $sorted_indexes = array(); | ||
212 | - | ||
213 | - global $global_parts, $global_intervals; | ||
214 | - $global_parts = $this->parts; | ||
215 | - $global_intervals = $intervals; | ||
216 | - | ||
217 | - foreach ($intervals as $interval) | ||
218 | - array_push($sorted_indexes, $interval->getIndex()); | ||
219 | - | ||
220 | - if (count($global_parts) == 0) | ||
221 | - return $sorted_indexes; | ||
222 | - | ||
223 | - usort($sorted_indexes, function ($index_a, $index_b) { | ||
224 | - global $global_parts, $global_intervals; | ||
225 | - foreach ($global_parts as $part) | ||
226 | - { | ||
227 | - $res = $part->compare($global_intervals[$index_a], $global_intervals[$index_b]); | ||
228 | - if ($res != 0) | ||
229 | - return $res; | ||
230 | - } | ||
231 | - return $index_a-$index_b; | ||
232 | - }); | ||
233 | - | ||
234 | - return $sorted_indexes; | ||
235 | - } | ||
236 | - | ||
237 | - public function writeBin($handle) { | ||
238 | - fwrite($handle,pack('L',count($this->parts))); | ||
239 | - foreach ($this->parts as $part) | ||
240 | - $part->writeBin($handle); | ||
241 | - } | ||
242 | - | ||
243 | - public function loadBin($handle) { | ||
244 | - $this->reset(); | ||
245 | - $res = unpack('Lcount',fread($handle,4)); | ||
246 | - for ($i = 0; $i < $res['count']; ++$i) | ||
247 | - { | ||
248 | - $part = new SortPartCacheObject(); | ||
249 | - $part->loadBin($handle); | ||
250 | - array_push($this->parts, $part); | ||
251 | - } | ||
252 | - } | ||
253 | - | ||
254 | - public function dump() { | ||
255 | - echo " => SortCacheObject : number of parts = ".count($this->parts).PHP_EOL; | ||
256 | - foreach ($this->parts as $part) | ||
257 | - $part->dump(); | ||
258 | - } | ||
259 | -} | ||
260 | - | ||
261 | -class FilterPartCacheObject | ||
262 | -{ | ||
263 | - public static $TYPE_UNKNOWN = 0; | ||
264 | - public static $TYPE_START = 1; | ||
265 | - public static $TYPE_STOP = 2; | ||
266 | - public static $TYPE_DURATION_SEC = 3; | ||
267 | - public static $TYPE_DURATION_MIN = 4; | ||
268 | - public static $TYPE_DURATION_HOUR = 5; | ||
269 | - | ||
270 | - public static $OPERATION_UNKNOWN = 0; | ||
271 | - public static $OPERATION_LT = 1; | ||
272 | - public static $OPERATION_GT = 2; | ||
273 | - public static $OPERATION_EQ = 3; | ||
274 | - | ||
275 | - protected $type; | ||
276 | - protected $op; | ||
277 | - protected $value; | ||
278 | - | ||
279 | - function __construct() { | ||
280 | - $this->type = self::$TYPE_UNKNOWN; | ||
281 | - $this->op = self::$OPERATION_UNKNOWN; | ||
282 | - $this->value = 0.; | ||
283 | - } | ||
284 | - | ||
285 | - public function getType() { | ||
286 | - return $this->type; | ||
287 | - } | ||
288 | - | ||
289 | - public function getOp() { | ||
290 | - return $this->op; | ||
291 | - } | ||
292 | - | ||
293 | - public function getValue() { | ||
294 | - return $this->value; | ||
295 | - } | ||
296 | - | ||
297 | - public function isSame($part) { | ||
298 | - return (($this->type == $part->getType()) && ($this->op == $part->getOp()) && ($this->value == $part->getValue())); | ||
299 | - } | ||
300 | - | ||
301 | - public function toFiltered($interval) { | ||
302 | - switch ($this->type) { | ||
303 | - case self::$TYPE_START : | ||
304 | - { | ||
305 | - switch ($this->op) { | ||
306 | - case self::$OPERATION_LT : | ||
307 | - return ($interval->getStartToStamp() < $this->value); | ||
308 | - case self::$OPERATION_GT : | ||
309 | - return ($interval->getStartToStamp() > $this->value); | ||
310 | - case self::$OPERATION_EQ : | ||
311 | - return (!(($interval->getStartToStamp() >= $this->value) && ($interval->getStartToStamp() <= $this->value+86400))); | ||
312 | - default : | ||
313 | - return false; | ||
314 | - } | ||
315 | - } | ||
316 | - break; | ||
317 | - case self::$TYPE_STOP : | ||
318 | - { | ||
319 | - switch ($this->op) { | ||
320 | - case self::$OPERATION_LT : | ||
321 | - return ($interval->getStopToStamp() < $this->value); | ||
322 | - case self::$OPERATION_GT : | ||
323 | - return ($interval->getStopToStamp() > $this->value); | ||
324 | - case self::$OPERATION_EQ : | ||
325 | - return (!(($interval->getStopToStamp() >= $this->value) && ($interval->getStopToStamp() <= $this->value+86400))); | ||
326 | - default : | ||
327 | - return false; | ||
328 | - } | ||
329 | - } | ||
330 | - break; | ||
331 | - case self::$TYPE_DURATION_SEC : | ||
332 | - case self::$TYPE_DURATION_MIN : | ||
333 | - case self::$TYPE_DURATION_HOUR : | ||
334 | - { | ||
335 | - $value = $this->value; | ||
336 | - if ($this->type == self::$TYPE_DURATION_MIN) | ||
337 | - $value *= 60; | ||
338 | - else if ($this->type == self::$TYPE_DURATION_HOUR) | ||
339 | - $value *= 3600; | ||
340 | - switch ($this->op) { | ||
341 | - case self::$OPERATION_LT : | ||
342 | - return ($interval->getDuration() < $value); | ||
343 | - case self::$OPERATION_GT : | ||
344 | - return ($interval->getDuration() > $value); | ||
345 | - case self::$OPERATION_EQ : | ||
346 | - return ($interval->getDuration() != $value); | ||
347 | - default : | ||
348 | - return false; | ||
349 | - } | ||
350 | - } | ||
351 | - break; | ||
352 | - default: | ||
353 | - return false; | ||
354 | - } | ||
355 | - } | ||
356 | - | ||
357 | - public function loadFromObject($part_obj) { | ||
358 | - $this->value = 0.; | ||
359 | - switch ($part_obj->field) | ||
360 | - { | ||
361 | - case 'start' : | ||
362 | - $this->value = TimeUtils::iso2stamp($part_obj->value); | ||
363 | - $this->type = self::$TYPE_START; | ||
364 | - break; | ||
365 | - case 'stop' : | ||
366 | - $this->value = TimeUtils::iso2stamp($part_obj->value); | ||
367 | - $this->type = self::$TYPE_STOP; | ||
368 | - break; | ||
369 | - case 'durationMin' : | ||
370 | - $this->value = $part_obj->value; | ||
371 | - $this->type = self::$TYPE_DURATION_MIN; | ||
372 | - break; | ||
373 | - case 'durationHour' : | ||
374 | - $this->value = $part_obj->value; | ||
375 | - $this->type = self::$TYPE_DURATION_HOUR; | ||
376 | - break; | ||
377 | - case 'durationSec' : | ||
378 | - $this->value = $part_obj->value; | ||
379 | - $this->type = self::$TYPE_DURATION_SEC; | ||
380 | - break; | ||
381 | - default: | ||
382 | - $this->value = 0.; | ||
383 | - $this->type = self::$TYPE_UNKNOWN; | ||
384 | - } | ||
385 | - | ||
386 | - switch ($part_obj->comparison) | ||
387 | - { | ||
388 | - case 'lt' : | ||
389 | - $this->op = self::$OPERATION_LT; | ||
390 | - break; | ||
391 | - case 'gt' : | ||
392 | - $this->op = self::$OPERATION_GT; | ||
393 | - break; | ||
394 | - case 'eq' : | ||
395 | - $this->op = self::$OPERATION_EQ; | ||
396 | - break; | ||
397 | - default: | ||
398 | - $this->op = self::$OPERATION_UNKNOWN; | ||
399 | - } | ||
400 | - } | ||
401 | - | ||
402 | - public function writeBin($handle) { | ||
403 | - fwrite($handle,pack('L2',$this->type,$this->op)); | ||
404 | - fwrite($handle,pack('f',$this->value)); | ||
405 | - } | ||
406 | - | ||
407 | - public function loadBin($handle) { | ||
408 | - $res = unpack('L2data',fread($handle,4*2)); | ||
409 | - $this->type = $res['data1']; | ||
410 | - $this->op = $res['data2']; | ||
411 | - | ||
412 | - $res = unpack('fvalue',fread($handle,4)); | ||
413 | - $this->value = $res['value']; | ||
414 | - } | ||
415 | - | ||
416 | - public function dump() { | ||
417 | - echo " => FilterPartCacheObject : type = "; | ||
418 | - switch ($this->type) | ||
419 | - { | ||
420 | - case self::$TYPE_START : | ||
421 | - echo "start"; | ||
422 | - break; | ||
423 | - case self::$TYPE_STOP : | ||
424 | - echo "stop"; | ||
425 | - break; | ||
426 | - case self::$TYPE_DURATION_SEC : | ||
427 | - echo "duration seconde"; | ||
428 | - break; | ||
429 | - case self::$TYPE_DURATION_MIN : | ||
430 | - echo "duration minute"; | ||
431 | - break; | ||
432 | - case self::$TYPE_DURATION_HOUR : | ||
433 | - echo "duration hour"; | ||
434 | - break; | ||
435 | - default: | ||
436 | - echo "unknown"; | ||
437 | - } | ||
438 | - echo ", operation = "; | ||
439 | - switch ($this->op) | ||
440 | - { | ||
441 | - case self::$OPERATION_LT : | ||
442 | - echo "lt"; | ||
443 | - break; | ||
444 | - case self::$OPERATION_GT : | ||
445 | - echo "gt"; | ||
446 | - break; | ||
447 | - case self::$OPERATION_EQ : | ||
448 | - echo "eq"; | ||
449 | - break; | ||
450 | - default: | ||
451 | - echo "unknown"; | ||
452 | - } | ||
453 | - echo ", value = ".$this->value.PHP_EOL; | ||
454 | - } | ||
455 | -} | ||
456 | - | ||
457 | -class FilterCacheObject | ||
458 | -{ | ||
459 | - protected $parts = array(); | ||
460 | - | ||
461 | - function __construct() { | ||
462 | - | ||
463 | - } | ||
464 | - | ||
465 | - public function getParts() { | ||
466 | - return $this->parts; | ||
467 | - } | ||
468 | - | ||
469 | - public function reset() { | ||
470 | - $this->parts = array(); | ||
471 | - } | ||
472 | - | ||
473 | - public function isEmpty() { | ||
474 | - return (count($this->parts) == 0); | ||
475 | - } | ||
476 | - | ||
477 | - public function loadFromJSON($filter_json) { | ||
478 | - $this->reset(); | ||
479 | - $filter_obj = json_decode($filter_json); | ||
480 | - | ||
481 | - foreach ($filter_obj as $filter_part) | ||
482 | - { | ||
483 | - $part = new FilterPartCacheObject(); | ||
484 | - $part->loadFromObject($filter_part); | ||
485 | - array_push($this->parts, $part); | ||
486 | - } | ||
487 | - } | ||
488 | - | ||
489 | - public function isSame($filter) { | ||
490 | - if (count($this->parts) != count($filter->getParts())) | ||
491 | - return false; | ||
492 | - | ||
493 | - $identique = true; | ||
494 | - for ($i = 0; $i < count($this->parts); ++$i) | ||
495 | - { | ||
496 | - if (!$this->parts[$i]->isSame($filter->getParts()[$i])) | ||
497 | - { | ||
498 | - return false; | ||
499 | - } | ||
500 | - } | ||
501 | - | ||
502 | - return true; | ||
503 | - } | ||
504 | - | ||
505 | - public function isSameFromJSON($filter_json) { | ||
506 | - $filter = new FilterCacheObject(); | ||
507 | - $filter->loadFromJSON($filter_json); | ||
508 | - return $this->isSame($filter); | ||
509 | - } | ||
510 | - | ||
511 | - public function toFiltered($interval) { | ||
512 | - foreach ($this->parts as $part) | ||
513 | - { | ||
514 | - if ($part->toFiltered($interval)) | ||
515 | - return true; | ||
516 | - } | ||
517 | - return false; | ||
518 | - } | ||
519 | - | ||
520 | - public function writeBin($handle) { | ||
521 | - fwrite($handle,pack('L',count($this->parts))); | ||
522 | - foreach ($this->parts as $part) | ||
523 | - $part->writeBin($handle); | ||
524 | - } | ||
525 | - | ||
526 | - public function loadBin($handle) { | ||
527 | - $this->reset(); | ||
528 | - $res = unpack('Lcount',fread($handle,4)); | ||
529 | - for ($i = 0; $i < $res['count']; ++$i) | ||
530 | - { | ||
531 | - $part = new FilterPartCacheObject(); | ||
532 | - $part->loadBin($handle); | ||
533 | - array_push($this->parts, $part); | ||
534 | - } | ||
535 | - } | ||
536 | - | ||
537 | - public function dump() { | ||
538 | - echo " => FilterCacheObject : number of parts = ".count($this->parts).PHP_EOL; | ||
539 | - foreach ($this->parts as $part) | ||
540 | - $part->dump(); | ||
541 | - } | ||
542 | -} | ||
543 | - | ||
544 | class TimeTableCacheMgr | 3 | class TimeTableCacheMgr |
545 | { | 4 | { |
546 | protected static $cache_file = "cacheTT"; | 5 | protected static $cache_file = "cacheTT"; |