Blame view

php/classes/TimeTableCacheObject.php 13.1 KB
d18b535d   elena   catalog draft + c...
1
2
3
4
5
6
<?php

class TimeTableCacheObject
{
	protected static $format_version = 1;
	protected static $token_len = 8;
2f1cd444   Benjamin Renard   Apply convention ...
7

d18b535d   elena   catalog draft + c...
8
	protected $token  = "";
2f1cd444   Benjamin Renard   Apply convention ...
9

d18b535d   elena   catalog draft + c...
10
	protected $lastId = 0;
2f1cd444   Benjamin Renard   Apply convention ...
11

d18b535d   elena   catalog draft + c...
12
13
	protected $intervals = array();
	protected $indexes   = array();
2f1cd444   Benjamin Renard   Apply convention ...
14

d18b535d   elena   catalog draft + c...
15
	protected $isModified = false;
2f1cd444   Benjamin Renard   Apply convention ...
16

d18b535d   elena   catalog draft + c...
17
	protected $filter = null;
2f1cd444   Benjamin Renard   Apply convention ...
18

d18b535d   elena   catalog draft + c...
19
20
21
22
	protected $sort = null;

	function __construct() {
		$this->token  = $this->getRandomToken();
ba9b1b7d   Benjamin Renard   Rework of TT and ...
23
		$this->reset();
d18b535d   elena   catalog draft + c...
24
25
26
27
28
29
30
31
	}

	public function reset() {
		$this->lastId = 0;
		$this->isModified = false;
		$this->intervals = array();
		$this->indexes   = array();
		unset($this->filter);
e022e5b5   Benjamin Renard   Filter parameter ...
32
		$this->filter = new TimeTableCacheFilterObject($this);
d18b535d   elena   catalog draft + c...
33
		unset($this->sort);
ab7c3c63   Benjamin Renard   Sort parameter co...
34
		$this->sort = new TimeTableCacheSortObject($this);
d18b535d   elena   catalog draft + c...
35
	}
2f1cd444   Benjamin Renard   Apply convention ...
36

d18b535d   elena   catalog draft + c...
37
38
39
	public function setIsModified($isModified) {
		$this->isModified = $isModified;
	}
2f1cd444   Benjamin Renard   Apply convention ...
40

ba9b1b7d   Benjamin Renard   Rework of TT and ...
41
42
43
44
	protected function createNewIntervalObject($id, $index = -1) {
		return new TimeTableCacheIntervalObject($this, $id, $index);
	}

342b20ca   Benjamin Renard   Fix inheritence b...
45
	public function addInterval($interval, $isNew = false, $index = -1) {
ba9b1b7d   Benjamin Renard   Rework of TT and ...
46
		$intervalObj = $this->createNewIntervalObject($this->lastId, count($this->intervals));
d18b535d   elena   catalog draft + c...
47
		++$this->lastId;
342b20ca   Benjamin Renard   Fix inheritence b...
48
49
50
51
		$intervalObj->setStartFromISO($interval['start']);
		$intervalObj->setStopFromISO($interval['stop']);
		$intervalObj->setIsNew($isNew);
		array_push($this->intervals, $intervalObj);
d18b535d   elena   catalog draft + c...
52
53
54
55
56
57
		if ($index < 0)
			array_push($this->indexes, count($this->intervals) - 1);
		else
			array_splice($this->indexes, $index, 0, array(count($this->intervals) - 1));
		if ($isNew)
			$this->isModified = true;
342b20ca   Benjamin Renard   Fix inheritence b...
58
		return $intervalObj;
d18b535d   elena   catalog draft + c...
59
	}
2f1cd444   Benjamin Renard   Apply convention ...
60

d18b535d   elena   catalog draft + c...
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
	public function removeIntervalFromId($id) {
		for ($i = 0; $i < count($this->intervals); ++$i)
		{
			if ($this->intervals[$i]->getId() == $id)
			{
				//Remove interval
				array_splice($this->intervals, $i, 1);
				//Remove interval index if exist in indexes list
				for ($j = 0; $j < count($this->indexes); ++$j)
				{
					if ($this->indexes[$j] == $i)
					{
						array_splice($this->indexes, $j, 1);
						break;
					}
				}
				//Update indexes list
				for ($j = 0; $j < count($this->indexes); ++$j)
				{
					if ($this->indexes[$j] >=  $i)
						$this->indexes[$j]--;
				}
				$this->isModified = true;
				return true;
			}
		}
2f1cd444   Benjamin Renard   Apply convention ...
87

d18b535d   elena   catalog draft + c...
88
89
		return false;
	}
2f1cd444   Benjamin Renard   Apply convention ...
90

342b20ca   Benjamin Renard   Fix inheritence b...
91
	public function modifyIntervalFromId($cacheId, $data) {
d18b535d   elena   catalog draft + c...
92
93
		foreach ($this->intervals as $interval)
		{
342b20ca   Benjamin Renard   Fix inheritence b...
94
			if ($interval->getId() == $cacheId)
d18b535d   elena   catalog draft + c...
95
			{
42e2e019   Benjamin Renard   Next step for cac...
96
				$this->isModified = $interval->modifyInterval($data);
342b20ca   Benjamin Renard   Fix inheritence b...
97
				return 	$this->isModified;
d18b535d   elena   catalog draft + c...
98
99
			}
		}
2f1cd444   Benjamin Renard   Apply convention ...
100

d18b535d   elena   catalog draft + c...
101
102
		return false;
	}
2f1cd444   Benjamin Renard   Apply convention ...
103

d18b535d   elena   catalog draft + c...
104
105
106
107
	public function operationIntervals($extendTime, $shiftTime) {
		if (($extendTime == 0) && ($shiftTime == 0))
			//Nothing to do
			return true;
2f1cd444   Benjamin Renard   Apply convention ...
108

d18b535d   elena   catalog draft + c...
109
110
111
112
113
		for ($i = 0; $i < count($this->indexes); ++$i) {
			$start = $this->intervals[$this->indexes[$i]]->getStartToStamp();
			$start -= $extendTime;
			$start += $shiftTime;
			$this->intervals[$this->indexes[$i]]->setStartFromStamp($start);
2f1cd444   Benjamin Renard   Apply convention ...
114

d18b535d   elena   catalog draft + c...
115
116
117
118
			$stop = $this->intervals[$this->indexes[$i]]->getStopToStamp();
			$stop += $extendTime;
			$stop += $shiftTime;
			$this->intervals[$this->indexes[$i]]->setStopFromStamp($stop);
2f1cd444   Benjamin Renard   Apply convention ...
119

d18b535d   elena   catalog draft + c...
120
121
122
			$this->intervals[$this->indexes[$i]]->setIsModified(true);
			$this->isModified = true;
		}
2f1cd444   Benjamin Renard   Apply convention ...
123

d18b535d   elena   catalog draft + c...
124
125
		return true;
	}
2f1cd444   Benjamin Renard   Apply convention ...
126

d18b535d   elena   catalog draft + c...
127
128
	public function mergeIntervals() {
		$this->sort->reset();
2f1cd444   Benjamin Renard   Apply convention ...
129

d18b535d   elena   catalog draft + c...
130
131
132
		$this->sort->loadFromObject(
			array(
				(object)array("property" => "start", "direction" => "DESC")
2f1cd444   Benjamin Renard   Apply convention ...
133
			)
d18b535d   elena   catalog draft + c...
134
		);
2f1cd444   Benjamin Renard   Apply convention ...
135

d18b535d   elena   catalog draft + c...
136
		$this->updateIndexes();
2f1cd444   Benjamin Renard   Apply convention ...
137

d18b535d   elena   catalog draft + c...
138
		$merged_intervals = array();
2f1cd444   Benjamin Renard   Apply convention ...
139

d18b535d   elena   catalog draft + c...
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
		for ($i = 0; $i < count($this->indexes); ++$i) {
			if (count($merged_intervals) == 0)
			{
				array_push($merged_intervals,array(
					"start" => $this->intervals[$this->indexes[$i]]->getStartToStamp(),
					"stop"  => $this->intervals[$this->indexes[$i]]->getStopToStamp(),
					"mod"   => FALSE)
				);
				continue;
			}
			if (($merged_intervals[count($merged_intervals)-1]["stop"] >= $this->intervals[$this->indexes[$i]]->getStartToStamp()) &&
				($merged_intervals[count($merged_intervals)-1]["stop"] < $this->intervals[$this->indexes[$i]]->getStopToStamp()))
			{
				$merged_intervals[count($merged_intervals)-1]["stop"] = $this->intervals[$this->indexes[$i]]->getStopToStamp();
				$merged_intervals[count($merged_intervals)-1]["mod"] = TRUE;
			}
			else
				array_push($merged_intervals,array(
					"start" => $this->intervals[$this->indexes[$i]]->getStartToStamp(),
					"stop"  => $this->intervals[$this->indexes[$i]]->getStopToStamp(),
					"mod"   => FALSE)
				);
		}
2f1cd444   Benjamin Renard   Apply convention ...
163

d18b535d   elena   catalog draft + c...
164
		$this->reset();
2f1cd444   Benjamin Renard   Apply convention ...
165

d18b535d   elena   catalog draft + c...
166
		foreach ($merged_intervals as $merged_interval) {
ba9b1b7d   Benjamin Renard   Rework of TT and ...
167
			$interval = $this->createNewIntervalObject($this->lastId, count($this->intervals));
d18b535d   elena   catalog draft + c...
168
169
170
171
172
173
174
175
176
			++$this->lastId;
			$interval->setStartFromStamp($merged_interval["start"]);
			$interval->setStopFromStamp($merged_interval["stop"]);
			$interval->setIsNew($merged_interval["mod"]);
			if ($merged_interval["mod"])
				$this->isModified = true;
			array_push($this->intervals, $interval);
			array_push($this->indexes, count($this->intervals) - 1);
		}
2f1cd444   Benjamin Renard   Apply convention ...
177

d18b535d   elena   catalog draft + c...
178
179
		return true;
	}
2f1cd444   Benjamin Renard   Apply convention ...
180

d18b535d   elena   catalog draft + c...
181
182
183
184
185
186
187
	public function getStatistics() {
		$minTime  = NULL;
		$maxTime  = NULL;
		$minDuration  = NULL;
		$maxDuration  = NULL;
		$indexMinDuration = -1;
		$indexMaxDuration = -1;
2f1cd444   Benjamin Renard   Apply convention ...
188

d18b535d   elena   catalog draft + c...
189
190
		$nbValid = 0;
		$durationTotal = 0;
2f1cd444   Benjamin Renard   Apply convention ...
191

d18b535d   elena   catalog draft + c...
192
193
		//Min & Max
		for ($i = 0; $i < count($this->indexes); ++$i) {
80404514   Hacene SI HADJ MOHAND   #7152 Ok
194
			if ($this->intervals[$this->indexes[$i]]->getDuration() < 0)
d18b535d   elena   catalog draft + c...
195
196
				//Invalid interval
				continue;
2f1cd444   Benjamin Renard   Apply convention ...
197

d18b535d   elena   catalog draft + c...
198
199
			++$nbValid;
			$durationTotal += $this->intervals[$this->indexes[$i]]->getDuration();
2f1cd444   Benjamin Renard   Apply convention ...
200

d18b535d   elena   catalog draft + c...
201
202
			if (!isset($minTime) || ($minTime > $this->intervals[$this->indexes[$i]]->getStartToStamp()))
				$minTime = $this->intervals[$this->indexes[$i]]->getStartToStamp();
2f1cd444   Benjamin Renard   Apply convention ...
203

d18b535d   elena   catalog draft + c...
204
205
			if (!isset($maxTime) || ($maxTime < $this->intervals[$this->indexes[$i]]->getStopToStamp()))
				$maxTime = $this->intervals[$this->indexes[$i]]->getStopToStamp();
2f1cd444   Benjamin Renard   Apply convention ...
206

d18b535d   elena   catalog draft + c...
207
208
209
210
211
			if (!isset($minDuration) || ($minDuration > $this->intervals[$this->indexes[$i]]->getDuration()))
			{
				$minDuration      = $this->intervals[$this->indexes[$i]]->getDuration();
				$indexMinDuration = $i;
			}
2f1cd444   Benjamin Renard   Apply convention ...
212

d18b535d   elena   catalog draft + c...
213
214
215
216
217
218
			if (!isset($maxDuration) || ($maxDuration < $this->intervals[$this->indexes[$i]]->getDuration()))
			{
				$maxDuration      = $this->intervals[$this->indexes[$i]]->getDuration();
				$indexMaxDuration = $i;
			}
		}
2f1cd444   Benjamin Renard   Apply convention ...
219

d18b535d   elena   catalog draft + c...
220
221
222
223
224
225
226
227
		if (!isset($minTime))
			$minTime = 0;
		if (!isset($maxTime))
			$maxTime = 0;
		if (!isset($minDuration))
			$minDuration = 0;
		if (!isset($maxDuration))
			$maxDuration = 0;
2f1cd444   Benjamin Renard   Apply convention ...
228
229


d18b535d   elena   catalog draft + c...
230
231
232
233
234
		//Mean
		if ($nbValid > 0)
			$mean = $durationTotal / $nbValid;
		else
			$mean = 0;
2f1cd444   Benjamin Renard   Apply convention ...
235

d18b535d   elena   catalog draft + c...
236
237
238
		//Standard deviation
		$pow = 0;
		for ($i = 0; $i < count($this->indexes); ++$i) {
80404514   Hacene SI HADJ MOHAND   #7152 Ok
239
			if ($this->intervals[$this->indexes[$i]]->getDuration() < 0)
d18b535d   elena   catalog draft + c...
240
241
				//Invalid interval
				continue;
2f1cd444   Benjamin Renard   Apply convention ...
242

d18b535d   elena   catalog draft + c...
243
244
245
246
247
248
249
			$pow += pow($this->intervals[$this->indexes[$i]]->getDuration()-$mean,2);
		}
		if ($nbValid > 0)
			$variance = $pow/$nbValid;
		else
			$variance = 0;
		$stdev = sqrt($variance);
2f1cd444   Benjamin Renard   Apply convention ...
250

d18b535d   elena   catalog draft + c...
251
252
		//Sort by duration to get median
		$this->sort->reset();
2f1cd444   Benjamin Renard   Apply convention ...
253

d18b535d   elena   catalog draft + c...
254
255
256
257
258
		$this->sort->loadFromObject(
				array(
						(object)array("property" => "durationSec", "direction" => "DESC")
				)
		);
2f1cd444   Benjamin Renard   Apply convention ...
259

d18b535d   elena   catalog draft + c...
260
		$this->updateIndexes();
2f1cd444   Benjamin Renard   Apply convention ...
261

d18b535d   elena   catalog draft + c...
262
263
		$durations = array();
		for ($i = 0; $i < count($this->indexes); ++$i) {
80404514   Hacene SI HADJ MOHAND   #7152 Ok
264
			if ($this->intervals[$this->indexes[$i]]->getDuration() < 0)
d18b535d   elena   catalog draft + c...
265
266
				//Invalid interval
				continue;
2f1cd444   Benjamin Renard   Apply convention ...
267

d18b535d   elena   catalog draft + c...
268
269
			array_push($durations, $this->intervals[$this->indexes[$i]]->getDuration());
		}
2f1cd444   Benjamin Renard   Apply convention ...
270

d18b535d   elena   catalog draft + c...
271
272
273
274
275
276
277
278
279
280
		if (count($durations) > 0)
		{
			if (count($durations)%2 > 0) {
				$median = $durations[count($durations)/2-0.5];
			} else { // else the number of intervals is an even number
				$median = ($durations[count($durations)/2-1] + $durations[count($durations)/2])/2;
			}
		}
		else
			$median = 0;
2f1cd444   Benjamin Renard   Apply convention ...
281

d18b535d   elena   catalog draft + c...
282
283
		//Merge intervals to get density
		$this->mergeIntervals();
2f1cd444   Benjamin Renard   Apply convention ...
284

d18b535d   elena   catalog draft + c...
285
286
		$durationMergedTotal = 0;
		for ($i = 0; $i < count($this->indexes); ++$i) {
80404514   Hacene SI HADJ MOHAND   #7152 Ok
287
			if ($this->intervals[$this->indexes[$i]]->getDuration() < 0)
d18b535d   elena   catalog draft + c...
288
289
				//Invalid interval
				continue;
2f1cd444   Benjamin Renard   Apply convention ...
290

d18b535d   elena   catalog draft + c...
291
292
			$durationMergedTotal += $this->intervals[$this->indexes[$i]]->getDuration();
		}
2f1cd444   Benjamin Renard   Apply convention ...
293

d18b535d   elena   catalog draft + c...
294
295
296
297
		if (($maxTime-$minTime) > 0)
			$density = (($durationMergedTotal/($maxTime-$minTime)));
		else
			$density = 0;
2f1cd444   Benjamin Renard   Apply convention ...
298

d18b535d   elena   catalog draft + c...
299
300
301
302
303
304
305
306
307
308
		return array(
			"minDuration"     => $minDuration,
			"minDurationIndex"=> $indexMinDuration,
			"maxDuration"     => $maxDuration,
			"maxDurationIndex"=> $indexMaxDuration,
			"mean"    => $mean,
			"stdev"   => $stdev,
			"median"  => $median,
			"density" => $density);
	}
2f1cd444   Benjamin Renard   Apply convention ...
309

d18b535d   elena   catalog draft + c...
310
311
	public function getStatus() {
		$nbFiltered = count($this->intervals) - count($this->indexes);
2f1cd444   Benjamin Renard   Apply convention ...
312

d18b535d   elena   catalog draft + c...
313
314
315
316
317
		$nbModified = 0;
		$nbNew      = 0;
		$nbInvalid  = 0;
		$nbValid    = 0;
		for ($i = 0; $i < count($this->indexes); ++$i) {
80404514   Hacene SI HADJ MOHAND   #7152 Ok
318
			if ($this->intervals[$this->indexes[$i]]->getDuration() < 0)
d18b535d   elena   catalog draft + c...
319
320
321
322
323
324
325
326
				++$nbInvalid;
			else
				++$nbValid;
			if ($this->intervals[$this->indexes[$i]]->isModified())
				++$nbModified;
			if ($this->intervals[$this->indexes[$i]]->isNew())
				++$nbNew;
		}
2f1cd444   Benjamin Renard   Apply convention ...
327

d18b535d   elena   catalog draft + c...
328
329
330
331
332
333
334
335
336
		return array(
			"nbFiltered" => $nbFiltered,
			"nbModified" => $nbModified,
			"nbNew"      => $nbNew,
			"nbInvalid"  => $nbInvalid,
			"nbValid"    => $nbValid,
			"isModified" => $this->isModified
		);
	}
2f1cd444   Benjamin Renard   Apply convention ...
337

d18b535d   elena   catalog draft + c...
338
339
	public function getIntervalsArray($startIndex, $limit,$skipInvalid = false) {
		$intervals = array();
2f1cd444   Benjamin Renard   Apply convention ...
340

d18b535d   elena   catalog draft + c...
341
342
		if (!isset($startIndex))
			$startIndex = 0;
2f1cd444   Benjamin Renard   Apply convention ...
343

d18b535d   elena   catalog draft + c...
344
345
		if (!isset($limit))
			$limit = count($this->indexes);
2f1cd444   Benjamin Renard   Apply convention ...
346

d18b535d   elena   catalog draft + c...
347
348
349
		for ($i = 0; $i < $limit; ++$i) {
			if ($startIndex+$i >= count($this->indexes))
				break;
80404514   Hacene SI HADJ MOHAND   #7152 Ok
350
			if ($skipInvalid && ($this->intervals[$this->indexes[$startIndex+$i]]->getDuration() < 0))
d18b535d   elena   catalog draft + c...
351
352
353
354
355
				continue;
			array_push($intervals, $this->intervals[$this->indexes[$startIndex+$i]]->toArray());
		}
		return $intervals;
	}
2f1cd444   Benjamin Renard   Apply convention ...
356

d18b535d   elena   catalog draft + c...
357
358
359
	public function getLength() {
		return count($this->indexes);
	}
2f1cd444   Benjamin Renard   Apply convention ...
360

d18b535d   elena   catalog draft + c...
361
362
363
	public function getToken() {
		return $this->token;
	}
2f1cd444   Benjamin Renard   Apply convention ...
364

d18b535d   elena   catalog draft + c...
365
366
367
	public function getFilter() {
		return $this->filter;
	}
2f1cd444   Benjamin Renard   Apply convention ...
368

d18b535d   elena   catalog draft + c...
369
370
371
	public function getSort() {
		return $this->sort;
	}
2f1cd444   Benjamin Renard   Apply convention ...
372

d18b535d   elena   catalog draft + c...
373
374
	public function updateIndexes() {
		$this->indexes = array();
2f1cd444   Benjamin Renard   Apply convention ...
375

d18b535d   elena   catalog draft + c...
376
377
		for ($i = 0; $i < count($this->intervals); ++$i)
			$this->intervals[$i]->setIndex($i);
2f1cd444   Benjamin Renard   Apply convention ...
378

d18b535d   elena   catalog draft + c...
379
380
		//Apply sort
		$sort_result = $this->sort->apply($this->intervals);
2f1cd444   Benjamin Renard   Apply convention ...
381

d18b535d   elena   catalog draft + c...
382
383
384
385
386
387
388
		//Apply filter
		for ($i = 0; $i < count($sort_result); ++$i)
		{
			if (!$this->filter->toFiltered($this->intervals[$sort_result[$i]]))
				array_push($this->indexes,$this->intervals[$sort_result[$i]]->getIndex());
		}
	}
2f1cd444   Benjamin Renard   Apply convention ...
389

d18b535d   elena   catalog draft + c...
390
391
392
	public function writeBin($handle) {
		//Magic key ("TTC")
		fwrite($handle,pack('C3',ord('T'),ord('T'),ord('C')));
2f1cd444   Benjamin Renard   Apply convention ...
393

d18b535d   elena   catalog draft + c...
394
395
		//Version
		fwrite($handle,pack('L',TimeTableCacheObject::$format_version));
2f1cd444   Benjamin Renard   Apply convention ...
396

d18b535d   elena   catalog draft + c...
397
398
399
		//Token
		for ($i = 0; $i < TimeTableCacheObject::$token_len; ++$i)
			fwrite($handle,pack('C',ord($this->token[$i])));
2f1cd444   Benjamin Renard   Apply convention ...
400

d18b535d   elena   catalog draft + c...
401
402
		//Modified
		fwrite($handle,pack('L',$this->isModified));
2f1cd444   Benjamin Renard   Apply convention ...
403

e022e5b5   Benjamin Renard   Filter parameter ...
404
405
406
		//Additional info
		$this->writeAdditionalHeaderBin($handle);

d18b535d   elena   catalog draft + c...
407
408
		//Filter
		$this->filter->writeBin($handle);
2f1cd444   Benjamin Renard   Apply convention ...
409

d18b535d   elena   catalog draft + c...
410
411
412
		//Sort
		$this->sort->writeBin($handle);

d18b535d   elena   catalog draft + c...
413
414
		//Intervals
		fwrite($handle,pack('L2',count($this->intervals), $this->lastId));
ba9b1b7d   Benjamin Renard   Rework of TT and ...
415
		foreach($this->intervals as $interval) {
d18b535d   elena   catalog draft + c...
416
			$interval->writeBin($handle);
ba9b1b7d   Benjamin Renard   Rework of TT and ...
417
		}
2f1cd444   Benjamin Renard   Apply convention ...
418

d18b535d   elena   catalog draft + c...
419
420
421
422
423
		//Indexes
		fwrite($handle,pack('L',count($this->indexes)));
		foreach($this->indexes as $index)
			fwrite($handle,pack('L',$index));
	}
2f1cd444   Benjamin Renard   Apply convention ...
424

d18b535d   elena   catalog draft + c...
425
426
427
428
	public function loadBin($handle) {
		//Magic key ("TTC")
		if (!$res = unpack('C3key',fread($handle,3)))
			return false;
2f1cd444   Benjamin Renard   Apply convention ...
429

d18b535d   elena   catalog draft + c...
430
431
		if (($res['key1'] != ord('T')) || ($res['key2'] != ord('T')) || ($res['key3'] != ord('C')))
			return false;
2f1cd444   Benjamin Renard   Apply convention ...
432

d18b535d   elena   catalog draft + c...
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
		//Version
		if (!$res = unpack('Lversion',fread($handle,4)))
			return false;
		if (($res['version'] != TimeTableCacheObject::$format_version))
			return false;

		//Token
		$token = "";
		for ($i = 0; $i < TimeTableCacheObject::$token_len; ++$i)
		{
			if (!$res = unpack('Ctoken',fread($handle,1)))
				return false;
			$token .= chr($res['token']);
		}
		$this->token = $token;
2f1cd444   Benjamin Renard   Apply convention ...
448

d18b535d   elena   catalog draft + c...
449
450
451
452
		//Modified
		if (!$res = unpack('Lmodified',fread($handle,4)))
			return false;
		$this->isModified = $res['modified'];
2f1cd444   Benjamin Renard   Apply convention ...
453

e022e5b5   Benjamin Renard   Filter parameter ...
454
455
456
		//Additional info
		$this->loadAdditionalHeaderBin($handle);

d18b535d   elena   catalog draft + c...
457
458
		//Filter
		$this->filter->loadBin($handle);
2f1cd444   Benjamin Renard   Apply convention ...
459

d18b535d   elena   catalog draft + c...
460
461
		//Sort
		$this->sort->loadBin($handle);
2f1cd444   Benjamin Renard   Apply convention ...
462

d18b535d   elena   catalog draft + c...
463
464
465
466
467
468
		//Intervals
		$res = unpack('L2data',fread($handle,2*4));
		$nbIntervals  = $res['data1'];
		$this->lastId = $res['data2'];
		for ($i = 0; $i < $nbIntervals; ++$i)
		{
ba9b1b7d   Benjamin Renard   Rework of TT and ...
469
			$interval = $this->createNewIntervalObject(-1);
d18b535d   elena   catalog draft + c...
470
471
472
			$interval->loadBin($handle);
			array_push($this->intervals, $interval);
		}
2f1cd444   Benjamin Renard   Apply convention ...
473

d18b535d   elena   catalog draft + c...
474
475
476
477
478
479
480
481
		//Indexes
		$res = unpack('Ldata',fread($handle,4));
		$nbIndexes  = $res['data'];
		for ($i = 0; $i < $nbIndexes; ++$i)
		{
			$res = unpack('Lindex',fread($handle,4));
			array_push($this->indexes, $res['index']);
		}
2f1cd444   Benjamin Renard   Apply convention ...
482

d18b535d   elena   catalog draft + c...
483
484
		return true;
	}
2f1cd444   Benjamin Renard   Apply convention ...
485

ba9b1b7d   Benjamin Renard   Rework of TT and ...
486
487
488
489
490
491
492
493
	protected function loadAdditionalHeaderBin($handle) {
		// Nothing to do for a TT
	}

	protected function writeAdditionalHeaderBin($handle) {
		// Nothing to do for a TT
	}

d18b535d   elena   catalog draft + c...
494
495
496
497
	protected function getRandomToken() {
		$letters = 'abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
		return substr(str_shuffle($letters), 0, TimeTableCacheObject::$token_len);
	}
2f1cd444   Benjamin Renard   Apply convention ...
498

d18b535d   elena   catalog draft + c...
499
	public function dump() {
ab7c3c63   Benjamin Renard   Sort parameter co...
500
		echo " => ".get_class($this)." : token = ".$this->token.", nb intervals = ".count($this->intervals).", last id = ".$this->lastId.", nb indexes = ".count($this->indexes).PHP_EOL;
d18b535d   elena   catalog draft + c...
501
		echo PHP_EOL;
2f1cd444   Benjamin Renard   Apply convention ...
502

d18b535d   elena   catalog draft + c...
503
504
		$this->filter->dump();
		echo PHP_EOL;
2f1cd444   Benjamin Renard   Apply convention ...
505

d18b535d   elena   catalog draft + c...
506
507
		$this->sort->dump();
		echo PHP_EOL;
2f1cd444   Benjamin Renard   Apply convention ...
508

d18b535d   elena   catalog draft + c...
509
510
511
		foreach ($this->intervals as $interval)
			$interval->dump();
		echo PHP_EOL;
2f1cd444   Benjamin Renard   Apply convention ...
512

d18b535d   elena   catalog draft + c...
513
514
515
516
517
518
519
520
521
		echo " => Indexes list : ";
		foreach ($this->indexes as $index)
		{
			echo $index.", ";
		}
		echo PHP_EOL;
	}
}

2f1cd444   Benjamin Renard   Apply convention ...
522
?>